10=transform=20130607

40
Processing 1 0 Transform 幾幾幾幾

Upload: gene-kao

Post on 02-May-2017

215 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: 10=Transform=20130607

Processing

10

Transform幾何變換

Page 2: 10=Transform=20130607

Transform 1 & 2

Page 3: 10=Transform=20130607

translate(x,y);

rotate(angle);PI=3.14161598=180o

scale(size);scale(xsize, ysize);

pushMatrix();popMatrix();

Page 4: 10=Transform=20130607

Stack 堆疊 FILOQueue 排隊 FIFO

Page 5: 10=Transform=20130607

size(400,400);rect(100,100,100,50); // the first rectangletranslate(200,200);rect(0,0,100,100); // the second rectangle

1

2

Page 6: 10=Transform=20130607

size(400,400);translate(200,200);rect(100,100,100,50); // the first rectanglerect(0,0,100,100); // the second rectangle

1

2

Page 7: 10=Transform=20130607

size(400,400);pushMatrix();translate(200,200);rect(100,100,100,50); // the first rectanglepopMatrix();rect(0,0,100,100); // the second rectangle

1

2

Page 8: 10=Transform=20130607

size(200,200);rectMode(CENTER);noFill();smooth();translate(100,100);rect(0,0,10,10);

size(200,200);rectMode(CENTER);noFill();smooth();translate(100,100);rect(0,0,10,10);rotate(PI/4);rect(0,0,20,20);rect(0,0,30,30);rect(0,0,40,40);

Page 9: 10=Transform=20130607

size(200,200);rectMode(CENTER);noFill();smooth();translate(100,100);rect(0,0,10,10);rotate(PI/4);scale(1.5);rect(0,0,20,20);rect(0,0,30,30);rect(0,0,40,40);

size(200,200);rectMode(CENTER);noFill();smooth();translate(100,100);rect(0,0,10,10);pushMatrix();rotate(PI/4);scale(1.5);rect(0,0,20,20);popMatrix();rect(0,0,30,30);rect(0,0,40,40);

Page 10: 10=Transform=20130607

for (int i = 200; i > 0; i -= 20) {ellipse(0, 0, i, i);

}

Page 11: 10=Transform=20130607

size(200,200);smooth();noFill();

translate(100,100);for (int i = 200; i > 0; i -= 20) {

ellipse(0, 0, i, i);}

Page 12: 10=Transform=20130607

size(200,200);smooth();noFill();

translate(150,50);for (int i = 200; i > 0; i -= 20) {

ellipse(0, 0, i, i);}

Page 13: 10=Transform=20130607

void setup() { size(200, 200); noFill(); smooth();}

void draw() { BullEyes(100,0); BullEyes(0,100); BullEyes(0,100); BullEyes(100,-100); BullEyes(-200,0);}

void BullEyes(int x, int y) { translate(x,y); for (int i = 200; i > 0; i -= 20) { ellipse(0, 0, i, i);}} 這樣寫,不用

pushMatrix() 與 popMatrix() 雖然程式較短,但是得對座標,太累了。

Page 14: 10=Transform=20130607

void setup() { size(400, 400); smooth(); strokeWeight(1); noFill(); smooth();}

void draw() { BullEyes(width/2,0); BullEyes(0,height/2); BullEyes(0,height/2); BullEyes(width/2,0-height/2); BullEyes(0-width,0);}

void BullEyes(int x, int y) { translate(x,y); for (int i = width; i > 0; i -= 20) { ellipse(0, 0, i, i);}}

這樣寫,不用pushMatrix() 與 popMatrix() 雖然程式較短,但是得對座標,太累了。

Page 15: 10=Transform=20130607

void setup() { size(400, 400); noFill(); strokeWeight(5); smooth();}

void draw() { BullEyes(200,0); BullEyes(400,200); BullEyes(200,400); BullEyes(0,200); BullEyes(200,200);}

void BullEyes(int x, int y) { pushMatrix(); translate(x,y); for (int i = 400; i > 0; i -= 40) { ellipse(0, 0, i, i); } popMatrix();}

這樣寫,用pushMatrix() 與 popMatrix() 雖然程式較長,但是易懂。

Page 16: 10=Transform=20130607

void setup() { size(100, 100); noFill(); strokeWeight(1); smooth();}

void draw() { BullEyes(width/2,0); BullEyes(width,height/2); BullEyes(width/2,height); BullEyes(0,height/2); BullEyes(width/2,height/2);}

void BullEyes(int x, int y) { pushMatrix(); translate(x,y); for (int i = width; i > 0; i -= width / 10) { ellipse(0, 0, i, i); } popMatrix();}

Page 17: 10=Transform=20130607

void setup() { size(400, 400); smooth(); noStroke(); noLoop();}

void draw () { BullEyes(,);}

void BullEyes(int x, int y) { translate(x,y); for (int i = 280; i > 0; i -= 20) { if ((i % 40) == 0) {fill(0);} else {fill(255);} ellipse(0, 0, i, i); } }

Page 18: 10=Transform=20130607

void setup() { size(400, 400); smooth(); noStroke(); noLoop();}

void draw() { BullEyes(200,200);}

void BullEyes(int x, int y) { translate(x,y); for (int i = 280; i > 0; i -= 20) { if ((i % 40) == 0) {fill(0);} else {fill(255);} ellipse(0, 0, i, i); } }

Page 19: 10=Transform=20130607

void setup() { size(400, 400); smooth(); noStroke(); noLoop();}

void draw() { BullEyes(200,200); BullEyes(,); BullEyes(,); BullEyes(,); BullEyes(,);}

void BullEyes(int x, int y) { pushMatrix(); translate(x,y); for (int i = 280; i > 0; i -= 20) { if ((i % 40) == 0) {fill(0);} else {fill(255);} ellipse(0, 0, i, i); } popMatrix();}

Page 20: 10=Transform=20130607

void BullEyes(int x, int y) { pushMatrix(); translate(x,y); for (int i = 280; i > 0; i -= 20) { if ((i % 40) == 0) {fill(0);} else {fill(255);} ellipse(0, 0, i, i); } popMatrix();}

Page 21: 10=Transform=20130607

void setup() { size(400, 400); smooth(); noStroke(); noLoop();}

void draw() { BullEyes(200,200); BullEyes(200,0); BullEyes(400,200); BullEyes(200,400); BullEyes(0,200);}

void BullEyes(int x, int y) { pushMatrix(); translate(x,y); for (int i = 280; i > 0; i -= 20) { if ((i % 40) == 0) {fill(0);} else {fill(255);} ellipse(0, 0, i, i); } popMatrix();}

Page 22: 10=Transform=20130607

void setup() { size(400, 400); smooth(); noStroke(); noLoop();}

void draw() { BullEyes(200,200,0,0,0); BullEyes(200,0,255,0,0); BullEyes(400,200,0,255,0); BullEyes(200,400,0,0,255); BullEyes(0,200,255,255,0);}

void BullEyes(int x, int y, int c1 , int c2, int c3) { pushMatrix(); translate(x,y); for (int i = 280; i > 0; i -= 20) { if ((i % 40) == 0) {fill(c1,c2,c3);} else {fill(255);} ellipse(0, 0, i, i); } popMatrix();}

Page 23: 10=Transform=20130607

void setup() { size(400, 400); smooth(); rectMode(CENTER); noStroke(); noLoop();}

void draw() { for (int i = 0; i <= 400; i += 200) { for (int j = 0; j <= 400; j +=200) { BullEyes(i,j); }}}

void BullEyes(int x, int y) { pushMatrix(); translate(x,y); for (int i = 280; i > 0; i -= 20) { if ((i % 40) == 0) {fill(0);} else {fill(255);} ellipse(0, 0, i, i); } popMatrix();}

Page 24: 10=Transform=20130607

void setup() { size(400, 400); smooth(); rectMode(CENTER); noStroke(); noLoop();}void draw() { for (int i = 0; i <= 400; i += 200) { for (int j = 0; j <= 400; j +=200) { BullEyes(i,j);}} BullEyes(200,0); BullEyes(400,200); BullEyes(200,400); BullEyes(0,200);}void BullEyes(int x, int y) { pushMatrix(); translate(x,y); for (int i = 280; i > 0; i -= 20) { if ((i % 40) == 0) {fill(0);} else {fill(255);} ellipse(0, 0, i, i); } popMatrix();}

Page 25: 10=Transform=20130607

void setup() { size(400, 400); smooth(); rectMode(CENTER);}

void draw() { BullEyes(200,0); BullEyes(400,200); BullEyes(200,400); BullEyes(0,200);}

void BullEyes(int x, int y) { pushMatrix(); translate(x,y); for (int i = 200; i > 0; i -= 20) { if ((i % 40) == 0) {fill(255);} else {fill(0);} rect(0, 0, i, i); } popMatrix();}

Page 26: 10=Transform=20130607

void setup() { size(400, 400); smooth(); rectMode(CENTER);}

void draw() { for (int i = 0; i <= 400; i += 200) { for (int j = 0; j <= 400; j +=200) { BullEyes(i,j); }}}

void BullEyes(int x, int y) { pushMatrix(); translate(x,y); for (int i = 200; i > 0; i -= 20) { if ((i % 40) == 0) {fill(255);} else {fill(0);} rect(0, 0, i, i); } popMatrix();}

Page 27: 10=Transform=20130607

void setup() { size(400, 400); smooth(); rectMode(CENTER); noLoop(); }

void draw() { for (int i = 0; i <= 400; i += 200) { for (int j = 0; j <= 400; j +=200) { BullEyes(i,j);}}}

void BullEyes(int x, int y) { println(200%400); pushMatrix(); translate(x,y); for (int i = 200; i > 0; i -= 20) { if (((x + y) % 400) != 0) { if ((i % 40) == 0) {fill(0);} else {fill(255);}} if (((x + y) % 400) == 0) { if ((i % 40) == 0) {fill(255);} else {fill(0);}} rect(0, 0, i, i); } popMatrix();}

Page 28: 10=Transform=20130607

void setup() { size(400, 400); smooth(); rectMode(CORNER); noLoop(); }

void draw() { for (int i = 0; i < 400; i += 200) { for (int j = 0; j < 400; j +=200) { BullEyes(i,j);}}}

void BullEyes(int x, int y) { println(200%400); pushMatrix(); translate(x,y); for (int i = 200; i > 0; i -= 20) { if (((x + y) % 400) != 0) { if ((i % 40) == 0) {fill(0);} else {fill(255);}} if (((x + y) % 400) == 0) { if ((i % 40) == 0) {fill(255);} else {fill(0);}} rect(0, 0, i, i); } popMatrix();}

Page 29: 10=Transform=20130607

void setup() { size(400, 400); smooth(); rectMode(CENTER); noStroke(); noLoop();}

void draw() { BullEyes(200,0); BullEyes(400,200); BullEyes(200,400); BullEyes(0,200);}

void BullEyes(int x, int y) { pushMatrix(); translate(x,y); rotate(PI/4); for (int i = 280; i > 0; i -= 20) { if ((i % 40) == 0) {fill(0);} else {fill(255);} rect(0, 0, i, i); } popMatrix();}

Page 30: 10=Transform=20130607

size(400,400);background(0);stroke(255,100);translate(300,100);smooth();

for (int i = 0; i < 18; i ++) { strokeWeight(i); rotate(PI/18); line(0,0,60*i,0);}

Page 31: 10=Transform=20130607

size(400,400);background(0);stroke(200,100);translate(300,100);smooth();

for (int i = 0; i < 24; i ++) { strokeWeight(i*4); rotate(PI/12); line(0,0,200*i,0);}

Page 32: 10=Transform=20130607

void setup() { size(400,400); background(255); smooth();}

void draw() { int i; frameRate(1); circles(random(width),random(height), int(random(1,10)),int(random(100,200)));}

void circles (float x, float y, int step, int d) { pushMatrix(); translate(x,y); for (int i = 0; i < 24; i ++) { rotate(PI/12); line(0,0,60,0); } popMatrix(); }

Page 33: 10=Transform=20130607

void setup() { size(400,400); background(255); smooth();}

void draw() { int i; frameRate(1); circles(random(width),random(height), int(random(1,10)),int(random(100,200)));}

void circles (float x, float y, int step, int d) { pushMatrix(); translate(x,y); for (int i = 0; i < 24; i ++) { rotate(PI/12); line(0,0,i*3,0); } popMatrix(); }

Page 34: 10=Transform=20130607

void setup() { size(400,400); background(255); smooth();}

void draw() { int i; frameRate(1); circles(random(width),random(height), int(random(1,10)),int(random(100,200)));}

void circles (float x, float y, int step, int d) { pushMatrix(); translate(x,y); for (int i = 0; i < 24; i ++) { rotate(PI/12); line(0,0,random(30,120),0); } popMatrix(); }

Page 35: 10=Transform=20130607

void setup() { size(400,400); background(255); smooth();}

void draw() { int i; frameRate(1); circles(random(width),random(height), int(random(1,10)),int(random(100,200)));}

void circles (float x, float y, int step, int d) {stroke(random(255), random(255), random(255)); pushMatrix(); translate(x,y); scale(random(0.25,1.25)); for (int i = 0; i < 24; i ++) { rotate(PI/12); line(0,0,60,0); } popMatrix(); }

Page 36: 10=Transform=20130607

void setup() { size(400,400); background(255); smooth();}

void draw() { int i; frameRate(2); circles(random(width),random(height), int(random(1,10)),int(random(100,200)));}

void circles (float x, float y, int step, int d) { translate(x,y); for (int i = 0; i < 18; i ++) { rotate(PI/18); line(0,0,60*i,0);}}

Page 37: 10=Transform=20130607

void setup() { size(400,400); background(255); smooth(); noStroke(); fill(0,255,0,125);}

void draw() { int i; frameRate(3); circles(random(width),random(height), int(random(1,10)),int(random(100,200)));}

void circles (float x, float y, int step, int d) { pushMatrix(); translate(x,y); for (int i = 0; i < 6; i ++) { rotate(PI/6); ellipse(0,0,60,5);} popMatrix(); }

Page 38: 10=Transform=20130607

void setup() { size(400,400); background(255); smooth(); noStroke();}

void draw() { int i; frameRate(3); circles(random(width),random(height), int(random(1,10)),int(random(100,200)));}

void circles (float x, float y, int step, int d) { fill(random(255),random(255),random(255),125); pushMatrix(); translate(x,y); for (int i = 0; i < 6; i ++) { rotate(PI/6); ellipse(0,0,60,5);} popMatrix(); }

Page 39: 10=Transform=20130607

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) { fill(random(255),random(255),random(255),125); pushMatrix(); translate(x,y); float a = random(30); float b = random(20); for (int i = 0; i < 6; i ++) { rotate(PI/6); ellipse(0,0,60+a,20+b);} popMatrix(); }

Page 40: 10=Transform=20130607

Ch. 16 - 1706/07/2013