绘制奥林匹克五环旗。

最终效果: 

 

//绘制奥林匹克五环旗。
#include"../实践/GUI/Simple_window.h"
#include"GUI/Graph.h"
//建立圆弧类。
struct arc_circle :Shape {
    arc_circle(Point p, int rr, int ba, int ea);
    void draw_lines() const;

private:
    int r;
    int begin_angle;
    int end_angle;
};

arc_circle::arc_circle(Point p, int rr, int ba, int ea)
    :r(rr), begin_angle(ba), end_angle(ea)
{
    add(Point(p.x - r, p.y - r));
}

void arc_circle::draw_lines() const
{
    if (fill_color().visibility()) {	// fill
        fl_color(fill_color().as_int());
        fl_pie(point(0).x, point(0).y, r + r - 1, r + r - 1, begin_angle, end_angle);
        fl_color(color().as_int());	// reset color
    }

    if (color().visibility()) {
        fl_color(color().as_int());
        fl_arc(point(0).x, point(0).y, r + r, r + r, begin_angle, end_angle);
    }
}
//-------------------------------------------------------------------------------------------
int main()
try
{
    using namespace Graph_lib;
    //建立窗口。
    Simple_window win(Point(0,0), 600,400 , "My Window");
    Simple_window win2(Point(800,0), 600, 600, "Color_display");
    //---------------------------------------------------------------------------------------
    // 建立调色版。
    Vector_ref<Graph_lib::Rectangle>vr;
    Vector_ref<Text>tt;

    for(int i=0;i<16;i++)
        for (int j = 0; j < 16; j++)
        {
            ostringstream oss;
            oss << i*16+j;
            vr.push_back(new Graph_lib::Rectangle(Point(i * 35, j * 35), 35, 35));
            tt.push_back(new Text(Point(i * 35, (j+1) * 35-10), oss.str()));
            vr[vr.size() - 1].set_fill_color(i * 16 + j);
            tt[tt.size() - 1].set_color(Color::white);
            win2.attach(vr[vr.size() - 1]);
            win2.attach(tt[tt.size() - 1]);
        }
    // --------------------------------------------------------------------------------------
    //绘制旗面。
    Graph_lib::Rectangle flat(Point(0, 0), 600, 350);
    flat.set_color(Color::white);
    flat.set_fill_color(Color::white);
    win.attach(flat);
    //--------------------------------------------------------------------------------------
    //绘制蓝环。
    arc_circle arc_blue(Point(100,115), 90, 0, 360);
    arc_blue.set_color(4);
    arc_blue.set_style(Line_style(Line_style::solid, 10));
    win.attach(arc_blue);
    //----------------------------------------------------------------------------------------
    //绘制黄环。
    arc_circle arc_yellow(Point(200, 205), 90, 100,94);
    arc_yellow.set_color(3);
    arc_yellow.set_style(Line_style(Line_style::solid, 10));
    win.attach(arc_yellow);
    //----------------------------------------------------------------------------------------
    //绘制黑环。
    arc_circle arc_black(Point(300, 115), 90, 184, 178);
    arc_black.set_color(Color::black);
    arc_black.set_style(Line_style(Line_style::solid, 10));
    win.attach(arc_black);
    //---------------------------------------------------------------------------------------
    //绘制绿环。
    arc_circle arc_green(Point(400, 205), 90, 100, 94);
    arc_green.set_color(99);
    arc_green.set_style(Line_style(Line_style::solid, 10));
    win.attach(arc_green);
    //----------------------------------------------------------------------------------------
    //绘制红环。
    arc_circle arc_red(Point(500,115), 90, -176, 178);
    arc_red.set_color(1);
    arc_red.set_style(Line_style(Line_style::solid, 10));
    win.attach(arc_red);
    //----------------------------------------------------------------------------------------
    //将控制权交给显示引擎,使GUI系统在屏幕上显示一个对象,并等待用户按下窗口中的“Next”,以便执行下面的程序。
    win.wait_for_button();
    win2.wait_for_button();
    //----------------------------------------------------------------------------------------
}
catch (exception& e) {
    cerr << "error: " << e.what() << '\n';
    return 1;
}
catch (...) {
    cerr << "Oops: unknown exception!\n";
    return 2;
};
//---------------------------------------------------------------------------------------------

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值