懵圈小白 2021-06-16 14:14 采纳率: 0%
浏览 15

请给出代码,和运行结果图,感谢

用中点法实现圆的绘制。圆的半径取200~800之间的一个随机数

用Qt运行

  • 写回答

2条回答 默认 最新

  • CSDN专家-sinJack 2021-06-16 14:24
    关注
    #include <graphics.h>
    #include <conio.h>
    #include<stdio.h>
    #include <cstdlib> 
    // 中点画圆法
    void Circle_Midpoint(int x, int y, int r, int color)
    {
    	int tx = 0, ty = r, d = 1 - r;
     
    	while(tx <= ty)
    	{
    		// 利用圆的八分对称性画点
    		putpixel(x + tx, y + ty, color);
    		putpixel(x + tx, y - ty, color);
    		putpixel(x - tx, y + ty, color);
    		putpixel(x - tx, y - ty, color);
    		putpixel(x + ty, y + tx, color);
    		putpixel(x + ty, y - tx, color);
    		putpixel(x - ty, y + tx, color);
    		putpixel(x - ty, y - tx, color);
     
    		if(d < 0)
    			d += 2 * tx + 3;
    		else
    			d += 2 * (tx - ty) + 5, ty--;
     
    		tx++;
    	}
    }
     
     
    // 主函数
    void main()
    {
     
    	int x=200,y=400,r;
    	r=rand()%600+200;
    	initgraph(640, 480);
    	
    	// 测试画圆
    	Circle_Midpoint((x,y,r, RED);
    	
    	// 按任意键退出
    	getch();
    	closegraph();
    }

    如有帮助望采纳。点击我回答右上角【采纳】按钮。

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题