add key_action
This commit is contained in:
parent
f933a9f7fe
commit
ee50fc0348
26
Lektion 2/Key_action/arrow_key_move/arrow_key_move.pde
Normal file
26
Lektion 2/Key_action/arrow_key_move/arrow_key_move.pde
Normal file
@ -0,0 +1,26 @@
|
||||
int x = 0;//Position x
|
||||
int y = 0;//Positon y
|
||||
|
||||
void setup () {
|
||||
size(300, 300);
|
||||
//Startposition Mitte
|
||||
x = width /2;
|
||||
y = height /2;
|
||||
}
|
||||
|
||||
void draw () {
|
||||
background(255);
|
||||
ellipse(x, y, 40, 40);
|
||||
}
|
||||
|
||||
void keyPressed() {
|
||||
if (keyCode == RIGHT) {
|
||||
x +=10; // Kreis nach rechts
|
||||
} else if (keyCode == LEFT) {
|
||||
x -= 10; // Kreis nach links
|
||||
} else if (keyCode == DOWN) {
|
||||
y +=10; // Kreis nach unten
|
||||
} else if (keyCode == UP) {
|
||||
y -= 10; // Kreis nach oben
|
||||
}
|
||||
}
|
||||
15
Lektion 2/Key_action/black_white_1/black_white_1.pde
Normal file
15
Lektion 2/Key_action/black_white_1/black_white_1.pde
Normal file
@ -0,0 +1,15 @@
|
||||
int bg = 200;//bg = background
|
||||
|
||||
void draw() {
|
||||
background(bg);
|
||||
rectMode(CENTER);
|
||||
rect(50, 50, 40, 40);
|
||||
}
|
||||
|
||||
void keyPressed() {
|
||||
bg = 0;
|
||||
}
|
||||
|
||||
void mousePressed() {
|
||||
bg = 255;
|
||||
}
|
||||
21
Lektion 2/Key_action/black_white_2/black_white_2.pde
Normal file
21
Lektion 2/Key_action/black_white_2/black_white_2.pde
Normal file
@ -0,0 +1,21 @@
|
||||
boolean bg_is_white = true;
|
||||
|
||||
void draw() {
|
||||
if(bg_is_white) {
|
||||
background(255);
|
||||
fill(0);
|
||||
} else {
|
||||
background(0);
|
||||
fill(255);
|
||||
}
|
||||
ellipseMode(CENTER);
|
||||
ellipse(50, 50, 50, 50);
|
||||
}
|
||||
|
||||
void keyPressed() {
|
||||
bg_is_white = false;
|
||||
}
|
||||
|
||||
void mousePressed() {
|
||||
bg_is_white = true;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user