⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bouncefollow.cpp

📁 C++&datastructure书籍源码,以前外教提供现在与大家共享
💻 CPP
字号:
#include <iostream>
#include "canvas.h"
#include "auxil.h"
#include <string>

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<AnimatedCanvas&>(c).getClick();
        if (p.x != -1)
        {
            //double slope = static_cast<double>(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;
    
    
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -