• C语言经典100例题(56-60)--画圆;画方;画线


    目录

    【程序56】题目:画图,学用circle画圆形

    【程序57】题目:画图,学用line画直线。

    【程序58】题目:画图,学用rectangle画方形。

    【程序59】题目:画图,综合例子。

    【程序60】题目:画图,综合例子。   


    【程序56】
    题目:画图,学用circle画圆形

    1. #include "graphics.h"
    2. #include<conio.h>
    3. int main()
    4. {
    5.     int  i;
    6.     float j = 1, k = 1;
    7.     initgraph(640, 480);
    8.     setbkcolor(YELLOW);
    9.     cleardevice();
    10.     for (i = 0;i <= 25;i++)
    11.     {
    12.         setlinestyle(PS_SOLID, 4);
    13.         setlinecolor(BLUE);
    14.         circle(310, 250, k);
    15.         k = k + j;
    16.         j = j + 0.3;
    17.     }
    18.     _getch();
    19.     closegraph();//关闭窗口
    20. }

     

    【程序57】
    题目:画图,学用line画直线。

    1. #include "graphics.h"
    2. #include<conio.h>
    3. int main()
    4. {
    5.     int i;
    6.     float x0, y0, y1, x1;
    7.     float j = 12, k;
    8.     initgraph(640, 480);
    9.     setbkcolor(GREEN);
    10.     cleardevice();
    11.     x0 = 263;y0 = 263;y1 = 275;x1 = 275;
    12.     for (i = 0;i <= 18;i++)
    13.     {
    14.         setlinestyle(PS_SOLID, 4);
    15.         setlinecolor(BLUE);
    16.         line(x0, y0, x0, y1);
    17.         x0 = x0 - 5;
    18.         y0 = y0 - 5;
    19.         x1 = x1 + 5;
    20.         y1 = y1 + 5;
    21.         j = j + 10;
    22.     }
    23.     x0 = 263;y1 = 275;y0 = 263;
    24.     for (i = 0;i <= 20;i++)
    25.     {
    26.         setlinestyle(PS_SOLID, 4);
    27.         setlinecolor(BLUE);
    28.         line(x0, y0, x0, y1);
    29.         x0 = x0 + 5;
    30.         y0 = y0 + 5;
    31.         y1 = y1 - 5;
    32.     }
    33.     _getch();
    34.     closegraph();//关闭窗口
    35. }

     

    【程序58】
    题目:画图,学用rectangle画方形。

      
    程序分析:利用for循环控制100 - 999个数,每个数分解出个位,十位,百位。

    1. #include <graphics.h>
    2. #include<conio.h>
    3. int main()
    4. {
    5.     int x0, y0, y1, x1, i;
    6.     initgraph(640, 480);
    7.     setbkcolor(YELLOW);
    8.     cleardevice();
    9.     x0 = 263;y0 = 263;y1 = 275;x1 = 275;
    10.     for (i = 0;i <= 18;i++)
    11.     {
    12.         setlinestyle(PS_SOLID, 4);
    13.         setlinecolor(BLUE);
    14.         rectangle(x0, y0, x1, y1);
    15.         x0 = x0 - 5;
    16.         y0 = y0 - 5;
    17.         x1 = x1 + 5;
    18.         y1 = y1 + 5;
    19.     }
    20.     setcolor(2);
    21.     circle(269, 269, 137);
    22.     _getch();
    23.     closegraph();//关闭窗口
    24. }

     

    【程序59】
    题目:画图,综合例子。

    1. # define PAI 3.1415926
    2. # define B 0.809
    3. # include "graphics.h"
    4. #include "math.h"
    5. #include<conio.h>
    6. int main()
    7. {
    8.     int i, j, k, x0, y0, x, y;
    9.     float a;
    10.     initgraph(640, 480);
    11.     setlinestyle(PS_SOLID, 3);
    12.     setlinecolor(BLUE);
    13.     setbkcolor(GREEN);
    14.     cleardevice();
    15.     x0 = 150;y0 = 100;
    16.     circle(x0, y0, 10);
    17.     circle(x0, y0, 20);
    18.     circle(x0, y0, 50);
    19.     for (i = 0;i < 16;i++)
    20.     {
    21.         a = (2 * PAI / 16) * i;
    22.         x = ceil(x0 + 48 * cos(a));
    23.         y = ceil(y0 + 48 * sin(a) * B);
    24.         setlinestyle(PS_SOLID, 3);
    25.         setlinecolor(BLUE);
    26.         line(x0, y0, x, y);
    27.     }
    28.     setcolor(3);circle(x0, y0, 60);
    29.     /* Make 0 time normal size letters */
    30.     _getch();
    31.     setfillstyle(10, YELLOW);
    32.     floodfill(202, 100, WHITE);
    33.     _getch();
    34.     for (k = 0;k <= 500;k++)
    35.     {
    36.         setlinestyle(PS_SOLID, 4);
    37.         setlinecolor(BLUE);
    38.         for (i = 0;i <= 16;i++)
    39.         {
    40.             a = (2 * PAI / 16) * i + (2 * PAI / 180) * k;
    41.             x = ceil(x0 + 48 * cos(a));
    42.             y = ceil(y0 + 48 + sin(a) * B);
    43.             setlinestyle(PS_SOLID, 3);
    44.             setlinecolor(BLUE);
    45.             line(x0, y0, x, y);
    46.         }
    47.         for (j = 1;j <= 50;j++)
    48.         {
    49.             a = (2 * PAI / 16) * i + (2 * PAI / 180) * k - 1;
    50.             x = ceil(x0 + 48 * cos(a));
    51.             y = ceil(y0 + 48 * sin(a) * B);
    52.             line(x0, y0, x, y);
    53.         }
    54.     }
    55.     restorecrtmode();
    56.     _getch();
    57.     closegraph();//关闭窗口
    58. }

     

    【程序60】
    题目:画图,综合例子。
       

    1. #include "graphics.h"
    2. #include<conio.h>
    3. #define LEFT 0
    4. #define TOP 0
    5. #define RIGHT 639
    6. #define BOTTOM 479
    7. #define LINES 400
    8. #define MAXCOLOR 15
    9. int main()
    10. {
    11.     int error=0;
    12.     int x1, y1;
    13.     int x2, y2;
    14.     int dx1, dy1, dx2, dy2, i = 1;
    15.     int count = 0;
    16.     int color = 0;
    17.     initgraph(640, 480);
    18.     x1 = x2 = y1 = y2 = 10;
    19.     dx1 = dy1 = 2;
    20.     dx2 = dy2 = 3;
    21.     while (!_kbhit())
    22.     {
    23.         line(x1, y1, x2, y2);
    24.         x1 += dx1;y1 += dy1;
    25.         x2 += dx2;y2 + dy2;
    26.         if (x1 <= LEFT || x1 >= RIGHT)
    27.             dx1 = -dx1;
    28.         if (y1 <= TOP || y1 >= BOTTOM)
    29.             dy1 = -dy1;
    30.         if (x2 <= LEFT || x2 >= RIGHT)
    31.             dx2 = -dx2;
    32.         if (y2 <= TOP || y2 >= BOTTOM)
    33.             dy2 = -dy2;
    34.         if (++count > LINES)
    35.         {
    36.             setlinestyle(PS_SOLID, 0);
    37.             setlinecolor(BLUE);
    38.             color = (color >= MAXCOLOR) ? 0 : ++color;
    39.         }
    40.     }
    41.     closegraph();
    42.     _getch();
    43.     closegraph();//关闭窗口
    44. }

  • 相关阅读:
    单应用架构设计和实现(springboot或者springcloud方式)
    C++ 输入输出及txt文件输入示例
    Visual Studio Code---介绍
    【Unity | Editor强化工具】资产快速访问工具
    Python究竟属不属于嵌入式语言?
    vue3+ts打开echarts的正确方式
    Navicat连接mysql8.0:提示无法加载身份验证插件“caching_sha2_password”
    [数据可视化] 柱状图
    力扣(leetcode)第485题最大连续1的个数(Python)
    Python 文件读写操作区别案例(r、r+、rb、w、w+、wb、a、a+、ab)
  • 原文地址:https://blog.csdn.net/qq_52442214/article/details/132916303