All pastes #498488 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-05-20 13:52 UTC
rendered paste body

#define YP 1024

bool *tussi::rajaaympyra(int sade) //Wikipediasta apua \o/
{
	static bool alue[YP*YP]; //Toivotaan ettei kukaan halua isompaa ympyrää...
	memset(alue, false, (YP*sade*2+YP)/8); //taitaa olla 8-bittinen yksi blokki oletuksena...
	int f = 1 - sade;
	int ddF_x = 0;
	int ddF_y = -2 * sade;
	int x = 0;
	int y = sade;
	int x0, y0;
	x0=y0=sade;
	alue[x0+(y0 + sade)*YP]=true;
	alue[x0+(y0 - sade)*YP]=true;
	alue[(x0+sade)+y0*YP]=true;
	alue[(x0-sade)+y0*YP]=true;
	while(x < y)
	{
		if(f >= 0)
		{
			y--;
			ddF_y += 2;
			f += ddF_y;
		}
		x++;
		ddF_x += 2;
		f += ddF_x + 1;
		alue[(x0 + x)+(y0 + y)*YP]=true;
		alue[(x0 - x)+(y0 + y)*YP]=true;
		alue[(x0 + x)+(y0 - y)*YP]=true;
		alue[(x0 - x)+(y0 - y)*YP]=true;
		alue[(x0 + y)+(y0 + x)*YP]=true;
		alue[(x0 - y)+(y0 + x)*YP]=true;
		alue[(x0 + y)+(y0 - x)*YP]=true;
		alue[(x0 - y)+(y0 - x)*YP]=true;
	}
	return alue;
}

void tussi::piirraympyra(int x, int y, int sade, SDL_Color vari, bool taytetty)
{
	bool *alue=rajaaympyra(sade);
	if(taytetty)
	{
		for(int i=0; i<(YP*sade*2)+YP; i++)
		{
			if(alue[i]==true)
			{
				int tayta=0;
				for(int j=i+1;alue[j]!=true && j%YP!=YP-1;j++)
					tayta++;
				if(tayta>sade*2)
					tayta=0;
				for(int j=i;j<i+tayta+1;j++)
				{
					alue[j]=true;
				}
			}
		}
	}
	for(int i=0; i<YP*sade*2+YP; i++)
	{
		if(alue[i]==true)
			varitapikseli(x+i%(YP), y+i/(YP), vari);
	}
}