Date post: | 22-Mar-2016 |
Category: |
Documents |
Upload: | gary-chang |
View: | 212 times |
Download: | 0 times |
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;
}
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!!!
我們會用很多
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 (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)
邏輯等式
if your mouse is on the right side of the screen,
The background will be “RED”
如果滑鼠移到螢幕右邊 背景為紅
else
The background will be “GREEN”
其餘的話 背景為綠
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;
}
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;
}
}
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 || x< 0){
speed = -speed;
}
}