Processing
04 Function 功能
Functions 功能
void setup(){ size(500,500); smooth(); }
void draw(){ background(0); }
We want to make our own function 我們要有自己的功能
void rectCircle(){ rectMode(CENTER); rect(width/2,height/2,50,50); ellipse(width/2,height/2,25,25); }
void rectCircle(){ rectMode(CENTER); rect( x, y, rR, rR); ellipse(x, y, cR, cR); }
void rectCircle(float x, float y, float rR, float cR){ rectMode(CENTER); rect( x, y, rR, rR); ellipse(x, y, cR, cR); }
Now, we have our function, but how to use it? 再來 我們要怎麼使用呢?
void setup(){ size(500,500); smooth(); } void draw(){ background(0); rectCircle(width/2, height/2, 50, 30); }
void rectCircle(float x, float y, float rR, float cR){ rectMode(CENTER); rect( x, y, rR, rR); ellipse(x, y, cR, cR); }
void setup(){ size(800,800); smooth(); } void draw(){ background(0); rectCircle(250,250,50,25); rectCircle(125,125,100,50); rectCircle(375,375,30,15); } void rectCircle(float x, float y, float rR, float cR){ rectMode(CENTER); rect( x, y, rR, rR); ellipse(x, y, cR, cR); }
Add some colors
為人生 加點顏色吧
void setup(){ size(500,500); smooth(); } void draw(){ background(0); rectCircle(250,250,50,25,200,100,250,100); rectCircle(125,125,100,50,70,250,60,80); rectCircle(375,375,30,15,20,20,200,200); } void rectCircle(float x, float y, float rR, float cR, float R, float G, float B, float T){ fill(R,G,B,T); rectMode(CENTER); rect(x,y,rR,rR); ellipse(x,y,cR,cR); }
Put it Into For_Loop? 放入迴圈中?
void setup(){ size(500,500); smooth(); } void draw(){ background(0); for(int i =0; i<= width; i+=50){ rectCircle( i, 250, 50, 25, 0, 250, 0, 200); } } void rectCircle(float x, float y, float rR, float cR, float R, float G, float B, float T){ fill(R,G,B,T); rectMode(CENTER); rect(x,y,rR,rR); ellipse(x,y,cR,cR); }
void setup(){ size(500,500); smooth(); } void draw(){ background(0); for(int i =0; i<= width; i+=50){ rectCircle( i, 250, 50, 25, 0, 250, 0, 200); } } void rectCircle(float x, float y, float rR, float cR, float R, float G, float B, float T){ fill(R,G,B,T); rectMode(CENTER); rect(x,y,rR,rR); ellipse(x,y,cR,cR); }
void setup(){ size(500,500); smooth(); } void draw(){ background(0); for(int i =0; i<= width; i+=50){ for(int j=0; j<=height; j+=50){ rectCircle(i, j, 50, 25, 0, 250, 0, 200); } } } void rectCircle(float x, float y, float rR, float cR, float R, float G, float B, float T){ fill(R,G,B,T); rectMode(CENTER); rect(x,y,rR,rR); ellipse(x,y,cR,cR); }
void setup(){ size(500,500); smooth(); } void draw(){ background(0); noStroke(); for(int i =0; i<= width; i+=50){ for(int j=0; j<=height; j+=50){ rectCircle(i, j, i/10, j/10, i, i*j/500, j, 200); } } } void rectCircle(float x, float y, float rR, float cR, float R, float G, float B, float T){ fill(R,G,B,T); rectMode(CENTER); rect(x,y,rR,rR); ellipse(x,y,cR,cR); }
void setup(){ size(1200,900); background(0); smooth(); } void draw(){
noStroke(); rectCircle(mouseX, mouseY, 50, 30, random(0,255), random(0,255), random(0,255), 200); } void rectCircle(float x, float y, float rR, float cR, float R, float G, float B, float T){ fill(R,G,B,T); rectMode(CENTER); rect(x,y,rR,rR); ellipse(x,y,cR,cR); }
void setup(){ size(1200,900); background(0); smooth(); } void draw(){ noStroke(); rectCircle(mouseX, mouseY, random(10,80), random(10,200), random(0,255), random(0,255), random(0,255), 200);
} void rectCircle(float x, float y, float rR, float cR, float R, float G, float B, float T){ fill(R,G,B,T); rectMode(CENTER); rect(x,y,rR,rR); ellipse(x,y,cR,cR); }
A bit more mousePressed(); mouseButton(); 再多一點點 mousePressed(); mouseButton();
void setup(){ size(1200,900); background(0); smooth(); } void draw(){ noStroke(); rectCircle(mouseX, mouseY, random(10,80), random(10,200), random(0,255), random(0,255), random(0,255), 200); } void rectCircle(float x, float y, float rR, float cR, float R, float G, float B, float T) { if(mousePressed == true && mouseButton ==LEFT){ fill(c1,c2,c3); noStroke(); fill(R,G,B,T); You press your rectMode(CENTER); mouse and with the rect(x,y,rR,rR); ellipse(x,y,cR,cR); left button, then draw } }