- Recitation 7: This recitation provided us a chance to practice the function in processing which integrates keyboard input into the picture processing draws. It was challenging at first, however, after I made clear of how the function works, it’s not that diffcult.
- The code of my exercise is:
int i = 30;
void setup() { |
|
size(500, 500); | |
frameRate(4); | |
background(0); | |
rect(30, 20, 55, 55, 7); | |
fill(255, 50, 60); | |
} | |
void draw() { | |
background(0); | |
rect(i, i, 50, 50, 7); | |
fill(i, i, 50); | |
} | |
void keyPressed() { | |
if (key == CODED) { | |
if (keyCode == DOWN) { | |
i++; | |
} | |
} | |
} |
- Homework:
int r = 80;
int i = 1;
int l = 0;
int m = 300;
int n = 300;
void setup(){
size(600,600);
frameRate(60);
colorMode(HSB);
}
void draw(){
background(255);
strokeWeight(10);
stroke(l,255,255);
if(l < 255){
l ++;
}
ellipse(m,n,r,r);
r += i;
if(r >= 300){
i = -i;
r += i;
}
if(r <= 80){
i = 1;
r += i;
}
}
void keyPressed(){
if(key == CODED){
if(keyCode == UP){
n -= 20;
}if(keyCode == DOWN){
n += 20;
}if(keyCode == LEFT){
m -= 20;
}if(keyCode == RIGHT){
m += 20;
}
}
}