+ All Categories
Home > Documents > Processing=002=condition

Processing=002=condition

Date post: 22-Mar-2016
Category:
Upload: gary-chang
View: 212 times
Download: 0 times
Share this document with a friend
Description:
A_Little_Bit_Processing_Tutorial
Popular Tags:
34
Processing Condition 02 條件式
Transcript

Processing

Condition

02條件式

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

}

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;

}

Moving

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;

}

Void

draw()

is a

FOR

LOOPWhat we

gonna use

A LOT!!!

我們會用很多

Save the File 先存檔八

CONDITION條件式

Are you good at MATH?!你數學老師有常常請假嗎?

IF_Else

NAME EXAMPLE

While

Case

If the sun is coming out,(I will play tennis)Else(I will do my design)

While I am in STUDIO(I am always doing my design)

Case 1(I am sleeping)Case 2(I am eating)Case 3(I am DESIGNING)

IF_Else如果…其餘

if (it’s sunny){I will go swimming;}

else{I will stay at home;}

open

close

Logiccondition

open

close

If ( it’s sunny, ){I will play tennis}

else If (it’s cloudy,){I will read}

else if (it’s raining,){I will do my lundry}

else{I will do my design}{I will be killed}

All the

conditions

rest

Logic

> (greater than)< (less than)>= (greater than or equal to) <= (less than or equal to)== (equality)!= (inequality)

|| (logical OR)&& (logical AND)! (logical NOT)

邏輯等式

That’s Enough!!!夠了!!!

x < width / 2 x > width / 2

0 500

500

if your mouse is on the right side of the screen,

The background will be “RED”

如果滑鼠移到螢幕右邊 背景為紅

else

The background will be “GREEN”

其餘的話 背景為綠

How about 4 colors四色呢?

x < width / 2

y < height / 2

x > width / 2

y < height / 2

0 500

500

x < width / 2

y > height / 2

x > width / 2

y > height / 2

void setup(){

size(500,500);

smooth();

}

void draw(){

if(mouseX<(width/2) && mouseY <(height/2)){

background(255,0,0);

}

if(mouseX<(width/2) && mouseY >(height/2)){

background(0,255,0);

}

if(mouseX>(width/2) && mouseY <(height/2)){

background(0,0,255);

}

if(mouseX>(width/2) && mouseY >(height/2)){

background(255,255,255);

}

}

Now you should

understand it

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;

}

Moving

跑掉了!

Go all the way out!

How about Bouncing如何反彈

if(x > width){

speed = -speed;

}

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;

if( x > width ){

speed = -speed;

}

}

if(x < 0){

speed = -speed;

}

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;

if( x > width ){

speed = -speed;

}

if(x < 0){

speed = -speed;

}

}

if(x > width || x< 0){

speed = -speed;

}

|| (shift+\ = |)

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;

if(x > width || x< 0){

speed = -speed;

}

}


Recommended