#include using namespace std; #include "canvas.h" #include "randgen.h" #include "prompt.h" #include "mathutils.h" int main() { const int WIDTH= 300; const int HEIGHT= 200; AnimatedCanvas display(WIDTH,HEIGHT,20,20); RandGen rgen; display.SetTitle("fish bouncer demo"); EllipseShape body (Point(10,10), Point(50,30), CanvasColor::YELLOW); EllipseShape bodyb(Point(9,9), Point(51,31), CanvasColor::BLACK); CircleShape eye (Point(40,15), 5, CanvasColor::RED); TriangleShape fin (Point(30,5), Point(30,11), Point(35,11), CanvasColor::BLUE); TriangleShape tail (Point(0,10), Point(0,30), Point(15,20), CanvasColor::GREEN); CompositeShape fish; fish.add(fin); fish.add(tail); fish.add(bodyb); fish.add(body); fish.add(eye); // fish should start on grid, not bouncing const int MAX_FISH_X = WIDTH - fish.bbox().width(); const int MAX_FISH_Y = HEIGHT - fish.bbox().height(); int numFish = PromptRange("how many fish: ",1,100); int k; for(k=0; k < numFish; k++) { fish.setLocation(Point(rgen.RandInt(0,MAX_FISH_X), rgen.RandInt(0,MAX_FISH_Y))); Bouncer fishb(fish, deg2rad(rgen.RandInt(0,360)), rgen.RandInt(2,7)); display.addShape(fishb); } display.runUntilEscape(10); return 0; }