42
Processing For_Loop 03 迴圈

Processing=003=for loop

Embed Size (px)

DESCRIPTION

A_Little_Bit_Processing_Tutorial

Citation preview

Page 1: Processing=003=for loop

Processing

For_Loop

03迴圈

Page 2: Processing=003=for loop

For_Loop迴圈

Page 3: Processing=003=for loop

Moving

Page 4: Processing=003=for loop

int x=250;

int y=250;

int speed=2;

void setup(){

size(500,500);

smooth();

}

void draw(){

background(0);

noStroke();

ellipse(x,y,40,40);

x=x+speed;

}What we

gonna use

A LOT!!!

Void

draw()

is a

FOR

LOOP

Page 5: Processing=003=for loop

If you are in the condition, you are in the loop如果你在條件中你就在輪迴中

Page 6: Processing=003=for loop

INCEPTION

Page 7: Processing=003=for loop
Page 8: Processing=003=for loop
Page 9: Processing=003=for loop

For_Loop迴圈

Page 10: Processing=003=for loop

for (start;costrain;step){Do the thing;}

open

close

condition

Page 11: Processing=003=for loop

It is easier to code than to talk this time寫的比說的簡單

Page 12: Processing=003=for loop

void setup(){

size(500,500);

smooth();

}

void draw(){

background(0);

noStroke();

for (int i =0; i<500; i=i+25){

stroke(255);

strokeWeight(20);

point( i, 250);

}}

i starts from “0” point(0,250);

Next time “0 + 25” point(25,250);

Next time “0+25+25” point(50,250);

Next time “0+25+25+25” point(75,250);

Page 13: Processing=003=for loop
Page 14: Processing=003=for loop

void setup(){

size(500,500);

smooth();

}

void draw(){

background(0);

noStroke();

for (int i =0; i<500; i=i+25){

stroke(255);

strokeWeight(20);

point( i, i);

}}

i starts from “0” point(0,0);

Next time “0 + 25” point(25,25);

Next time “0+25+25” point(50,50);

Next time “0+25+25+25” point(75,75);

Page 15: Processing=003=for loop
Page 16: Processing=003=for loop

void setup(){

size(500,500);

smooth();

}

void draw(){

background(0);

stroke(255);

strokeWeight(2);

for (int i =0; i<500; i=i+25){

line( i, 0, i, 500);

}}

Let’s draw lines

line(x1,y1,x2,y2);

畫線八

Page 17: Processing=003=for loop
Page 18: Processing=003=for loop

How to do this?

Use For_Loop Twice

如何用兩次迴圈來完成

Page 19: Processing=003=for loop

void setup(){

size(500,500);

smooth();

}

void draw(){

background(0);

stroke(255);

for (int i =0; i<500; i=i+25){

strokeWeight(i/50);

line( i, 0, i, 500);

}

for (int i =0; i<500; i=i+25){

strokeWeight(i/50);

line( 0, i, 500, i);

}}

How about control the

strokeWeight with i

用 i 改變筆寬何如?

Page 20: Processing=003=for loop
Page 21: Processing=003=for loop

Nested For_Loop很髒的迴圈中的迴圈

Page 22: Processing=003=for loop

For loopInsideFor loop

Page 23: Processing=003=for loop

void setup(){

size(500,500);

background(0);

smooth();

}

void draw(){

for(int i =0; i<=500; i=i+20){

ellipse( i , 10 ,20,20);

}

}

Page 24: Processing=003=for loop

Imagine there is a

TYPEWRITER

想像有台打字機

Page 25: Processing=003=for loop

OK,

PLOTTER

抱歉列印機

Page 26: Processing=003=for loop

i starts from “0” ellipse(0,10,20,20);

Next time “0 + 20” ellipse (20,10,20,20);

Next time “0+20+20” ellipse(40,10,20,20);

Next time “0+20+20+20” ellipse(60,10,20,20);

…. …. ….

Next time “0+20+20…+20” ellipse(500,10,20,20);

Page 27: Processing=003=for loop

void setup(){

size(500,500);

smooth();

}

void draw(){

background(0);

for(int i =0; i<500; i=i+20){

for (int j=0; j<500; j=j+20){

ellipse( i , j ,20,20);

}

}

}

Page 28: Processing=003=for loop
Page 29: Processing=003=for loop

i starts from “0”

j starts from “0” ellipse(0, 0, 20,20);

“0 + 20” ellipse (0, 20, 20,20);

“0+20+20” ellipse(0, 40, 20,20);

“0+20+20+20” ellipse(0, 60, 20,20);

…… …..

“0+20+20+20” ellipse(0, 480, 20,20);

Next time “i+20=20”

j starts from “0” ellipse(20, 0, 20,20);

“0 + 20” ellipse (20, 20, 20,20);

“0+20+20” ellipse(20, 40, 20,20);

…… …..

“0+20+20+20” ellipse(20, 480, 20,20);

……………………………….. ………………………..

Next time “i+20+….20=480”

j starts from “0” ellipse(480, 0, 20,20);

“0 + 20” ellipse (480, 20, 20,20);

…… …..

“0+20+20+20” ellipse(480, 480, 20,20);

Page 30: Processing=003=for loop

void setup(){

size(500,500);

smooth();

}

void draw(){

background(0);

for(int i =0; i<500; i=i+20){

for (int j=0; j<500; j=j+20){

ellipse( i+10 , j+10 ,20,20);

}

}

}

Page 31: Processing=003=for loop

rect( locX, locY,w,h);

Page 32: Processing=003=for loop

void setup(){

size(500,500);

smooth();

}

void draw(){

background(0);

strokeWeight(5);

for(int i =0; i<500; i=i+20){

for (int j=0; j<500; j=j+20){

rect( i , j ,20,20);

}

}

}

Page 33: Processing=003=for loop

void setup(){

size(500,500);

smooth();

}

void draw(){

background(0);

strokeWeight(5);

for(int i =0; i<500; i=i+20){

for (int j=0; j<500; j=j+20){

fill( i , j , i+j /10);

rect( i , j ,20,20);

}

}

}

Page 34: Processing=003=for loop

void setup(){

size(500,500);

smooth();

}

void draw(){

background(0);

strokeWeight(5);

for(int i =0; i<500; i=i+20){

for (int j=0; j<500; j=j+20){

fill(mouseX,mouseY,(i+j)/10);

rect( i , j ,20,20);

}

}

}

Page 35: Processing=003=for loop
Page 36: Processing=003=for loop

5 / 3 = 1 ….2

5 % 3 = 2

Page 37: Processing=003=for loop

void setup(){

size(500,500);

smooth();

}

void draw(){

background(0);

strokeWeight(5);

for(int i =0; i<500; i=i+20){

for (int j=0; j<500; j=j+20){

fill( i , j , i+j /10);

if( (i+j) % 3 ==1){

rect( i , j ,20,20);

}

else{

ellipse ( i +10, j+10 ,20,20);

}

}

}

}

Page 38: Processing=003=for loop

Random!!!亂數

Page 39: Processing=003=for loop

random(min,max)

Page 40: Processing=003=for loop

void setup(){

size(500,500);

smooth();

noLoop();//stop looping the code

}

void draw(){

background(0);

strokeWeight(5);

for(int i =0; i<500; i=i+20){

for (int j=0; j<500; j=j+20){

fill(random(0,255) ,0 ,0);

rect( i , j ,20,20);

}

}

}

Page 41: Processing=003=for loop

void setup(){

size(500,500);

smooth();

}

void draw(){

background(0);

for(int i =0; i<500; i=i+50){

for (int j=0; j<500; j=j+50){

stroke(255);

line(random(0,width),0,random(0,width),height);

}

}

}

Page 42: Processing=003=for loop