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

📄 bouncefish.cpp

📁 C++&datastructure书籍源码,以前外教提供现在与大家共享
💻 CPP
字号:
#include <iostream>
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;
    
    
}

⌨️ 快捷键说明

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