09=Functions=20130531

35
Processing 0 9 Functions 函函 ( 函函函 )

Transcript of 09=Functions=20130531

Page 1: 09=Functions=20130531

Processing

09

Functions函數 (副程式 )

Page 2: 09=Functions=20130531

Structure 3: Functions

Page 3: 09=Functions=20130531

Function 機能 (建築 )Function 函數 (數學 )Function 函式、副程式 (程式 )

Page 4: 09=Functions=20130531

void Processingdefun LISPprocedure PASCALsubroutine FORTRANsub BASIC

function

Page 5: 09=Functions=20130531

1. 分工 ( 段 )2. 模矩化3. 邏輯化4. 重複使用 ( 程式內部、之後 )

Page 6: 09=Functions=20130531

void setup() { size(400,400); background(255); rectMode(CENTER); ellipseMode(CENTER); smooth(); frameRate(10);}

Page 7: 09=Functions=20130531

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);}

Page 8: 09=Functions=20130531

void rect_circle (float x, float y) { fill(0); rect(x,y,100,100); fill(255); ellipse(x,y,100,100);}

Page 9: 09=Functions=20130531

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);}

Page 10: 09=Functions=20130531

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);}

Page 11: 09=Functions=20130531

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);}

Page 12: 09=Functions=20130531

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);}

Page 13: 09=Functions=20130531

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);}

Page 14: 09=Functions=20130531

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);}

Page 15: 09=Functions=20130531
Page 16: 09=Functions=20130531

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);}

Page 17: 09=Functions=20130531

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); }

Page 18: 09=Functions=20130531

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); }

Page 19: 09=Functions=20130531

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); }}

Page 20: 09=Functions=20130531

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); }}

Page 21: 09=Functions=20130531

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); }}

Page 22: 09=Functions=20130531

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); }}

Page 23: 09=Functions=20130531

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); }}

Page 24: 09=Functions=20130531

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); }}

Page 25: 09=Functions=20130531

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); }}

Page 26: 09=Functions=20130531

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); }}

Page 27: 09=Functions=20130531

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); }}

Page 28: 09=Functions=20130531

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); }}

Page 29: 09=Functions=20130531

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); }}

Page 30: 09=Functions=20130531

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); }}

Page 31: 09=Functions=20130531

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); }}

Page 32: 09=Functions=20130531

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); }}

Page 33: 09=Functions=20130531

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); }}

Page 34: 09=Functions=20130531

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); }}

Page 35: 09=Functions=20130531

Ch. 2105/31/2013