소스코드
int rectWidth;
void setup() {
size(400 , 300);
noStroke();
background(139,144,104);
rectWidth = width/5;
}
void draw() {
// keep draw() here to continue looping while waiting for keys
}
void keyPressed() {
int keyIndex = -1;
char m = 0;
if (key >= '1' && key <= '9') {
keyIndex = key - '1';
} else if (key >= '1' && key <= '9'|| key == 'm') {
keyIndex = key - '1';
}
if (keyIndex == -1) {
// If it's not a letter key, clear the screen
background(217,174,104);
} else {
// It's a letter key, fill a rectangle
fill(millis() % random(255),random(255),random(255));
float x = map(keyIndex, 0, 10, 2, width - rectWidth);
rect(0, x, 400, rectWidth);
}
if (key == 'm') saveFrame("line-##.png");
}






댓글
댓글 쓰기