0% found this document useful (0 votes)
2K views40 pages

Processing: Transform

The document discusses transformations in processing including translate, rotate, scale, pushMatrix, and popMatrix. It provides examples of using these functions to draw shapes and nested transformations. It also discusses using for loops to draw concentric circles and spiral patterns. The key concepts covered are 2D geometric transformations, matrix stacks, and programmatically drawing shapes.

Uploaded by

Gene Kao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views40 pages

Processing: Transform

The document discusses transformations in processing including translate, rotate, scale, pushMatrix, and popMatrix. It provides examples of using these functions to draw shapes and nested transformations. It also discusses using for loops to draw concentric circles and spiral patterns. The key concepts covered are 2D geometric transformations, matrix stacks, and programmatically drawing shapes.

Uploaded by

Gene Kao
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 40

Processing

Transform

10

Transform 1 & 2

translate(x,y);
rotate(angle);
PI=3.14161598=180o
scale(size);
scale(xsize, ysize);
pushMatrix();
popMatrix();

Stack FILO
Queue FIFO

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

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

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

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

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

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


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

size(200,200);
smooth();
noFill();
translate(100,100);
for (int i = 200; i > 0; i -= 20) {
ellipse(0, 0, i, i);
}

size(200,200);
smooth();
noFill();
translate(150,50);
for (int i = 200; i > 0; i -= 20) {
ellipse(0, 0, i, i);
}

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()

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()

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()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Ch. 16 - 17
06/07/2013

You might also like