示例#1
0
void octant0(SDL_Surface* surface, Uint32 x0, Uint32 y0, Uint32 deltax, Uint32 deltay,
             int xdirection, const PG_Color& color, Uint8 width, int pixelflag)
{
	int deltay2;
	int error;
	int deltay2deltax2;	/* delta y2 - deltax2 */

	/* setup intial error used in drawing loop */
	deltay2 = deltay << 1;
	deltay2deltax2 = deltay2 - (int)(deltax << 1);
	error = deltay2 - (int)deltax;

	/* draw the line */
	plotpixel(surface, x0, y0, color, width, &pixelflag);	/* draw first pixel */
	while(deltax--) {
		/* test to advance the y coordinate */
		if (error >= 0) {
			/* advance y coordinate and adjust the error term */
			y0++;
			error += deltay2deltax2;
		} /* end of the if */
		else {
			/* add to the error term */
			error += deltay2;
		} /* end of if else */

		x0 += xdirection; 		/* advance the x coordinate */
		plotpixel(surface, x0, y0, color, width, &pixelflag);
	} /* end of the while */

} /* end of the function */
示例#2
0
void main()
{
int driver,mode;
int errorcode;
int p0,p;
driver=DETECT;
initgraph(&driver,&mode,"c:\\tc\\bin");
errorcode=graphresult();
if(errorcode!=grOk)
{
cout<<"\nerror opening the graphics mode :";
cout<<"\npress any key to halt :";
getch();
exit(1);
}
cout<<"\nenter the 'x' coordinate of center :";
cin>>xc;
cout<<"\nenter the 'y' coordinate of center :";
cin>>yc;
cout<<"\nenter the radius of circle :";
cin>>r;
cleardevice();
xcc=getmaxx()/2;
ycc=getmaxy()/2;
x=0;
y=r;
p0=1-r;
p=p0;
line(0,getmaxy()/2,getmaxx(),getmaxy()/2);
line(getmaxx()/2,0,getmaxx()/2,getmaxy());
outtextxy(10,10,"By Mid-point circle algorithm");
line(10,20,250,20);
outtextxy(xcc+xc-20,ycc-yc+10,"(xc,yc)");
while(x<y)
{
if(p<0)
{
x=x+1;
delay(50);
plotpixel();
p=p+(2*x)+1;
}
else
{
x=x+1;
y=y-1;
delay(50);
plotpixel();
p=p+(2*x)+1-(2*y);
}}
getch();
closegraph();
}
示例#3
0
void		burningship(t_env *env, int x, int y)
{
	size_t	i;
	t_cplx	 z;
	t_cplx	 c;
	t_cplx	 a;

	
	c.r = env->ptx + ((x - (SCREEN_W / 2)) / env->zoom);
	c.i = env->pty + ((y - (SCREEN_H / 2)) / env->zoom);
	z = cplx(0.0, 0.0);
	a = cplx(c.r, c.i);
	i = -1;
	while (++i < env->max_i && mod(z) < 2)
	{
		z = cplx(fabs(z.r), fabs(z.i));
		z = cplx_add(cplx_mult(z, z), c);
	}
	plotpixel(env, x, y, get_color(env, z, a, i));
}