关于polyline函数的一个提问

1

polyline函数在绘制连续的线段时,当出现不在画布上的坐标,也就是画布之外的点,会导致polyline函数不执行吗?在如下代码中,编译没有问题,但是结果没有出现图形,求解答。

#include <graphics.h>   // 引用图形库头文件
#include<math.h>
#include<stdio.h>
#include<stdlib.h>

struct Point{
		double x;
		double y;
	};
 

void Phan()//绘制函数
{
	double x,y;
	double tempx,tempy;
	int n=0,i=0;
	struct Point *point;
	for(x = -8; x <= 8; x=x+0.001){
		n++;}
	point = (struct Point *)malloc(n * sizeof(struct Point));
	for(x = -8; x <= 8; x=x+0.001) {
		y=pow(x,2);
		tempx = x;
		tempy = y;
		if (tempx >= 0){
			tempx = x*50+500;
		}else if(tempx<0){
			tempx = 500+x*50;
		}
		point[i].x = tempx;
		if (tempy >= 0){
			tempy = 300 - y * 50;
		}else if(tempy<0){
			tempy = 300 - y * 50;
		}
		point[i].y = tempy;
		i++;
	}
	polyline((POINT *)point, n);
	free(point);
	
}
 
 
int main()
{
	initgraph(1000, 600);// 初始化绘图窗口
	setbkcolor(WHITE);
	cleardevice();
	Phan();
 

	system("PAUSE");
	return 0;
}

ava
Abner

2023-2-26

0

polyline 函数 的 x,y,坐标点不支持高精度浮点数,polyline 只支持整形数据。

ava
随波逐流

2023-2-27

而且 easyx 默认绘制线条颜色是白色的,你把画图的背景设为白色,所以以默认白色线条的绘图函数的绘图程序自然就看不到了,你要把背景改成黑色或者,把线条颜色改成其他的就可以了。 -  随波逐流  2023-2-27
技术讨论社区