Created
April 21, 2016 07:25
-
-
Save gn-spawn/653e1560c04b0610989457c080936253 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void setup() { | |
size(512,512); | |
background(0); | |
noStroke(); | |
} | |
int mojim[][][] = { | |
{{50, 450}, {50, 50}}, | |
{{50, 50}, {250, 200}}, | |
{{250, 200}, {450, 50}}, | |
{{450, 50}, {450, 450}} | |
}; | |
void draw(){ | |
//int x[] = {400, 320, 180, 100, 100, 180, 320, 400}; | |
//int y[] = {320, 400, 400, 320, 180, 100, 100, 180}; | |
//int i; | |
//for(i=0;i<8;i++){ | |
// Bresen(250, 250, x[i], y[i]); | |
//} | |
//Bresen(10,250, 510, 350); | |
//Bresen(10,250, 510, 150); | |
//Bresen(510,250, 10, 450); | |
//Bresen(510,250, 10, 50); | |
polygonmode(mojim, 4); | |
} | |
void polygonmode(int p[][][], int num){ | |
for(int i =0;i<num;i++){ | |
Bresen(p[i][0][0], p[i][0][1], p[i][1][0], p[i][1][1]); | |
} | |
} | |
void Bresen(int xs,int ys, int xe, int ye) | |
{ | |
int w, er, x, y; | |
if(abs(xe - xs) > abs(ye - ys)) { | |
if(xs>xe) { | |
w=xs;xs=xe;xe=w; | |
w=ys;ys=ye;ye=w; | |
} | |
y=ys; er=(xe-xs); | |
for( x=xs ; x<=xe ; x++) { | |
v_pixel(1,x,y,255,255,255); | |
er=er+abs(ye-ys)*2; | |
if( er >=(xe-xs)*2) { | |
if(ys < ye) { | |
y = y+1; | |
}else { | |
y = y-1; | |
} | |
er = er-(xe-xs)*2; | |
} | |
} | |
}else{ | |
if(ys>ye) { | |
w=ys;ys=ye;ye=w; | |
w=xs;xs=xe;xe=w; | |
} | |
y=ys; er=(ye-ys); | |
x = xs; er = 0; | |
for(y=ys;y<=ye;y++){ | |
v_pixel(1,x,y,255,255,255); | |
er=er+abs(xe-xs)*2; | |
if( er >=(ye-ys)*2) { | |
if(xs < xe) { | |
x = x+1; | |
}else { | |
x = x-1; | |
} | |
er = er-(ye-ys)*2; | |
} | |
} | |
} | |
} | |
// Do not Delete folowing function | |
void keyPressed(){ | |
if( key== 's' ) { | |
saveFrame("Result.jpg"); // Save File Name | |
} | |
} | |
// | |
// Don't rewrite following function v_pixel !! | |
// | |
void v_pixel(int n, int x, int y, int r,int g, int b) | |
{ | |
if(n==1) | |
{stroke(color(r,g,b)); | |
point(x,y);} | |
else | |
{fill(r,g,b); | |
rect(x*n,y*n,n,n);} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment