Back Then Schematic >>> Now Faster to Prototype! >>> Real World!
Was there IoT in 2009??
Conditional Statements
How does computer language make different decision? So far we learned setup() : something happens at the start, draw(): something same event happens over and over. Also we learned event function like : mousepressed.
Something changes over time.
Today we want to learn something that happens different from previous event. For example, the color of the ellipse changes after one draw, the position of the rectangle change over based on the position of the user's mouse.
if (100 < mouseX AND mouseX < 200){ }
if (100 < mouseX && mouseX <200){ }
100 < mouseX AND mouseX < 200
var x,y;
function setup() {
createCanvas(400, 400);
}
function draw() {
background(255,255,255);
stroke(50);
noFill();
if(100 < mouseX && mouseX < 200 ){
fill(255,0,210);
ellipse(200, 200, 50, 50);
}
}
OR
if (100 < mouseX OR mouseX < 200){ }
if (100 < mouseX || mouseX <200){ }
x < 0 OR x > height
var x = 0;
var y = 0;
var speed = 3;
function setup() {
createCanvas(400, 400); }
function draw() {
background(255,255,255);
stroke(50); noFill();
fill(255,0,210);
ellipse(200, y, 50, 50);
if(y < 0 || y > height ){
speed = speed * -1
}
y = y + speed; }
if(something is ture){
Do this code
}
// Happened ONCE and Move On!!
While ...하는 동안
while(something is true){
Do this code
}
//Continue this code over, over, onv and over...
Ellipses one by one....
function setup() {
createCanvas(400, 400);
}
function draw() {
background(220);
var x = 0; //local variable
ellipse(x,50,25,25);
x = x + 50;
ellipse(x,50,25,25);
x = x + 50;
ellipse(x,50,25,25);
x = x + 50;
ellipse(x,50,25,25);
x = x + 50;
}