09=Functions=20130531
Transcript of 09=Functions=20130531
Processing
09
Functions函數 (副程式 )
Structure 3: Functions
Function 機能 (建築 )Function 函數 (數學 )Function 函式、副程式 (程式 )
void Processingdefun LISPprocedure PASCALsubroutine FORTRANsub BASIC
function
1. 分工 ( 段 )2. 模矩化3. 邏輯化4. 重複使用 ( 程式內部、之後 )
void setup() { size(400,400); background(255); rectMode(CENTER); ellipseMode(CENTER); smooth(); frameRate(10);}
void draw() { rect_circle(random(width),random(height));}
void rect_circle (float x, float y) { fill(0); rect(x,y,100,100); fill(255); ellipse(x,y,100,100);}
void rect_circle (float x, float y) { fill(0); rect(x,y,100,100); fill(255); ellipse(x,y,100,100);}
void setup() { size(400,400); background(255); rectMode(CENTER); ellipseMode(CENTER); smooth(); frameRate(5);}
void draw() { rect_circle(random(width),random(height));}
void rect_circle (float x, float y) { fill(0); rect(x,y,100,100); fill(255); ellipse(x,y,100,100);}
void rect_circle (float x, float y) { float w = random(60); fill(0); rect(x,y,w,w); fill(255); ellipse(x,y,w,w);}
void setup() { size(400,400); background(255); rectMode(CENTER); ellipseMode(CENTER); smooth(); frameRate(5);}
void draw() { rect_circle(random(width),random(height));}
void rect_circle (float x, float y) { float w = random(60); fill(0); rect(x,y,w,w); fill(255); ellipse(x,y,w,w);}
void rect_circle (float x, float y) { float w = random(60); fill(random(255),random(255),random(255)); rect(x,y,w,w); fill(255); ellipse(x,y,w,w);}
void setup() { size(400,400); background(255); rectMode(CENTER); ellipseMode(CENTER); smooth(); frameRate(5);}
void draw() { rect_circle(random(width),random(height));}
void rect_circle (float x, float y) { float w = random(60); fill(random(255),random(255),random(255)); rect(x,y,w,w); fill(255); ellipse(x,y,w,w);}
void setup() { size(400,400); background(255); rectMode(CENTER); ellipseMode(CENTER); smooth(); frameRate(20);}
void draw() { rect_circle(random(width),random(height));}
void rect_circle (float x, float y) { float w = random(20,60); fill(random(255),random(255),random(255)); rect(x,y,w,w); fill(255); ellipse(x,y,w,w);}
void setup() { size(400,400); background(255); rectMode(CENTER); ellipseMode(CENTER); smooth(); frameRate(5);}
void draw() { rect_circle(random(2));}
void rect_circle (float z) { if (z > 1) {rect_circle_1(random(width), random(height));} else {rect_circle_2(random(width), random(height));}}
void rect_circle_1 (float x, float y) { float w = random(60); fill(random(255),random(255),random(255)); rect(x,y,w,w); fill(255); ellipse(x,y,w,w);}
void rect_circle_2 (float x, float y) { float w = random(60); fill(255); rect(x,y,w,w); fill(random(255),random(255),random(255)); ellipse(x,y,w,w);}
void setup() { size(400,400); background(255); }
void draw() { fill(0); rect(50,50,100,100); fill(255); rect(50,50,80,80); fill(0); rect(50,50,60,60); fill(255); rect(50,50,40,40); fill(0); rect(50,50,20,20); }
void setup() { size(400,400); background(255); rectMode(CENTER);}
void draw() { fill(0); rect(50,50,100,100); fill(255); rect(50,50,80,80); fill(0); rect(50,50,60,60); fill(255); rect(50,50,40,40); fill(0); rect(50,50,20,20); }
void setup() { size(400,400); background(255); rectMode(CENTER);}
void draw() { five_rects();}
void five_rects() { fill(0); rect(50,50,100,100); fill(255); rect(50,50,80,80); fill(0); rect(50,50,60,60); fill(255); rect(50,50,40,40); fill(0); rect(50,50,20,20); }
void setup() { size(400,400); background(255); rectMode(CENTER);}
void draw() { five_rects();}
void five_rects() { for (int i = 0; i < 5; i += 1) { if ((i % 2) == 1) {fill(255);} else {fill(0);} rect(50,50,100-20*i,100-20*i); }}
void draw() { five_rects(random(width),random(height));}
void five_rects (float x, float y) { for (int i = 0; i < 5; i += 1) { if ((i % 2) == 1) {fill(255);} else {fill(0);} rect(x,y,100-20*i,100-20*i); }}
void setup() { size(400,400); background(255); rectMode(CENTER);}
void draw() { five_rects(random(width),random(height));}
void five_rects (float x, float y) { for (int i = 0; i < 5; i += 1) { if ((i % 2) == 1) {fill(255);} else {fill(0);} rect(x,y,100-20*i,100-20*i); }}
void setup() { size(400,400); background(255); //rectMode(CENTER);}
void draw() { five_rects(random(width),random(height));}
void five_rects (float x, float y) { for (int i = 0; i < 5; i += 1) { if ((i % 2) == 1) {fill(255);} else {fill(0);} rect(x,y,100-20*i,100-20*i); }}
void setup() { size(400,400); background(255); //rectMode(CENTER); frameRate(6);}
void draw() { five_rects(random(width),random(height));}
void five_rects (float x, float y) { if (random(1 ,3) >= 2) {rectMode(CENTER);} else {rectMode(CORNER);} for (int i = 0; i < 5; i += 1) { if ((i % 2) == 1) {fill(255);} else {fill(0);} rect(x,y,100-20*i,100-20*i); }}
void setup() { size(400,400); background(255); smooth(); frameRate(5);}
void draw() { circles(random(width),random(height));}
void circles (float x, float y) { for (int i = 0; i < 5; i += 1) { if ((i % 2) == 1) {fill(255);} else {fill(0);} ellipse(x,y,100-20*i,100-20*i); }}
void setup() { size(400,400); background(255); smooth(); frameRate(5);}
void draw() { circles(random(width),random(height));}
void circles (float x, float y) { for (int i = 0; i < 5; i += 1) { fill(random(255),random(255),random(255)); ellipse(x,y,100-20*i,100-20*i); }}
void draw() { int i; circles(random(width),random(height),int(random(1,5)));}
void circles (float x, float y, int step) { for (int i = 0; i < step; i += 1) { fill(random(255),random(255),random(255)); ellipse(x,y,100-20*i,100-20*i); }}
void setup() { size(400,400); background(255); smooth(); frameRate(5);}
void draw() { int i; circles(random(width),random(height), int(random(1,5)));}
void circles (float x, float y, int step) { for (int i = 0; i < step; i += 1) { fill(random(255),random(255),random(255)); ellipse(x,y,100-20*i,100-20*i); }}
void draw() { int i; circles(random(width),random(height), int(random(1,10)),int(random(100,200)));}
void circles (float x, float y, int step, int d) { for (int i = 0; i < step; i += 1) { fill(random(255),random(255),random(255)); ellipse(x,y,d-20*i,d-20*i); }}
void setup() { size(400,400); background(255); smooth(); frameRate(5);}
void draw() { int i; circles(random(width),random(height), int(random(1,10)),int(random(100,200)));}
void circles (float x, float y, int step, int d) { for (int i = 0; i < step; i += 1) { fill(random(255),random(255),random(255)); ellipse(x,y,d-20*i,d-20*i); }}
void setup() { size(400,400); background(255); smooth(); frameRate(5);}
void draw() { int i; circles(random(width),random(height), int(random(1,10)),int(random(100,200)));}
void circles (float x, float y, int step, int d) { for (int i = 0; i < step; i += 1) { fill(random(255),random(255),random(255),125); ellipse(x,y,d-20*i,d-20*i); }}
void setup() { size(400,400); background(255); smooth(); noStroke();}
void draw() { int i; frameRate(5); circles(random(width),random(height), int(random(1,10)),int(random(100,200)));}
void circles (float x, float y, int step, int d) { for (int i = 0; i < step; i += 1) { fill(random(255),random(255),random(255),150); ellipse(x,y,d-20*i,d-20*i); }}
void setup() { size(400,400); background(255); smooth(); noStroke(); frameRate(5);}
void draw() { int i; many_rects(random(width),random(height), int(random(1,10)),int(random(100,200)));}
void many_rects (float x, float y, int step, int d) { for (int i = 0; i < step; i += 1) { fill(random(255),random(255),random(255),255); rect(x,y,d-20*i,d-20*i); }}
void setup() { size(400,400); background(255); smooth(); noStroke(); rectMode(CENTER); frameRate(5);}
void draw() { int i; many_rects(random(width),random(height), int(random(1,10)),int(random(100,200)));}
void many_rects (float x, float y, int step, int d) { for (int i = 0; i < step; i += 1) { fill(random(255),random(255),random(255),255); rect(x,y,d-20*i,d-20*i); }}
void setup() { size(400,400); background(255); smooth(); noStroke(); rectMode(CENTER); frameRate(5);}
void draw() { int i; many_rects(random(width),random(height), int(random(1,10)),int(random(100,200)));}
void many_rects (float x, float y, int step, int d) { for (int i = 0; i < step; i += 1) { fill(random(255),random(255),random(255), random(255)); rect(x,y,d-20*i,d-20*i); }}
Ch. 2105/31/2013