Curhat, tutorial, tugas kuliah, dll..

Konsep lingkaran

Sebelum tahap implementasi sebaiknya temen2 baca dulu konsep dari algoritma lingkaran itu sendiri, silakan temen2 download pdf dibawah ini untuk paham lebih jauh mengenai konsep dari algoritma pembuatan lingkaran..

Implementasi dengan processing


// STANDAR TEMPLATE TUBES GRAFCIT @IT TELKOM | 2011
//--------------------------------- inisialisasi, ga perlu dirubah
static int canvasW = 600;
static int canvasH = 600;
void setup() {
	size(canvasW, canvasH);
	background(255);
}

//--------------------------------- variable global ditulis disini

//--------------------------------- disini mulai codingnya
void draw() {
	drawHelpLines();
	midpoint(0,0,100);
}

//--------------------------------- procedure/fungsi bikinan sendiri
//--------------------------------- silahkan ditulis dibawah sini

void midpoint(int x0, int y0, int r) {
	int P=1-r;
	int x=0;
	int y=r;

	plot(x0,y0,x,y);
	for (int xa=x; x<y;) {

		if (P<0)
		{
			x=x+1;
			P=P+2*x+1;
			plot(x0,y0,x,y);
		}
		else
		{
			x=x+1;
			y=y-1;
			P=P+(2*x)-(2*y)+1;
			plot(x0,y0,x,y);
		}
	}
}

void plot(int x0, int y0, int x, int y) {
	stdPoint(x+x0, y+y0);
	stdPoint(x+x0, -y+y0);
	stdPoint(-x+x0, -y+y0);
	stdPoint(-x+x0, y+y0);
	stdPoint(y+x0, x+y0);
	stdPoint(y+x0, -x+y0);
	stdPoint(-y+x0, x+y0);
	stdPoint(-y+x0, -x+y0);
}

// -------------------------------- normalisasi, ga perlu dirubah
void stdPoint(int xxx, int yyy)
{
	//stroke(warna);
	point(xxx+(canvasW/2), (yyy*-1)+(canvasH/2));
}

void drawHelpLines()
{
	stroke(0, 0, 255);
	for (int z=0; z<canvasW; z=z+1) {
		point((canvasW/2), z);
		point(z, (canvasH/2));
	}
	stroke(0, 0, 0);
}
Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

%d bloggers like this: