#include #include "canvas.h" #include "auxil.h" #include using namespace std; class Follower : public Mouseable, public Bouncer { public: Follower(Shape& s, double angle, double v) : Bouncer(s,angle,v) { } Follower(const Follower& f) : Bouncer(f) { } Shape * clone() { return new Follower(*this); } void draw(AnimatedCanvas& c) { Bouncer::draw(c); } Box bbox() const { return Bouncer::bbox(); } void processClick(const Point& p, AnimatedCanvas & c) { Point current = getLocation(); myAngle = atan2(p.y-current.y,p.x-current.x); return; #ifdef foo Point p = dynamic_cast(c).getClick(); if (p.x != -1) { //double slope = static_cast(myDy)/myDx; //myDx = p.x - myPoint.x; //myDy = p.y - myPoint.y; myAngle = atan2(p.y-myPoint.y,p.x-myPoint.x); } Bouncer::update(c); #endif } }; int main() { int width=400; int height=400; AnimatedCanvas display(width,height,20,20); const double PI=3.1415926535; int limit = 2; int k; for(k=0; k < limit; k++) { CircleShape c1(Point(k*20+100,k*10+15),8,RED); CircleShape c2(Point(20*(k+4)+150,15*k+15),8,BLUE); CircleShape c4(Point(20*(k+4),15*k+100),8,ORANGE); CircleShape c3(Point(10*(k+3)+10,10*k+20),8,GREEN); Follower f(c3,PI/4, 2); display.addShape(f.clone()); Bouncer b1(c1,PI/4,2*k+1); Bouncer b3(c4,PI/4,2); display.addShape(b3.clone()); Bouncer b4(c4,PI*3/4,2); display.addShape(b4.clone()); display.addShape(b1.clone()); Bouncer b2(c2,PI/4,4*k+1); display.addShape(b2.clone()); } display.run(10000,5); //display.repaint(); char ch; cin.get(ch); return 0; }