-
Notifications
You must be signed in to change notification settings - Fork 0
/
Optical_illusion_Processing.pde
86 lines (70 loc) · 1.25 KB
/
Optical_illusion_Processing.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
color yellow = color(255, 204, 0);
color black = color(0);
int value = 0;
int x = 160;
int y = 160;
int x2 = 340;
int y2 = 340;
int x3 = 340;
int y3 = 160;
int x4 = 160;
int y4 = 340;
int swi = 0;
void setup() {
size(500, 500);
smooth();
noStroke();
rectMode(CENTER);
}
void draw() {
background(255);
textSize(16);
text("Press any key for illusion", 10, 30);
switchDirection();
movingRect(x, y, 45);
movingRect(x2, y2, 45);
movingRect(x3, y3, 135);
movingRect(x4, y4, 135);
if (value == 0) {
drawRectangle(70, 250);
drawRectangle(430, 250);
drawRectangle(260, 70);
drawRectangle(260, 430);
}
}
void movingRect(int x, int y, int angle) {
pushMatrix();
fill(black);
translate(x, y);
rotate(radians(angle));
rect(0, 0, 6, 185);
popMatrix();
}
void drawRectangle(int x, int y) {
pushMatrix();
fill(yellow);
translate(x, y);
rotate(radians(45));
rect(0, 0, 100, 100);
popMatrix();
}
void switchDirection() {
if (x == 190) {
swi = 1;
}
if (x == 140) {
swi = 0;
}
if (swi==0) {
x++; y++; x2++; y2++; x3++; y3--; x4++; y4--;
} else {
x--; y--; x2--; y2--; x3--; y3++; x4--; y4++;
}
}
void keyPressed() {
if (value == 0) {
value = 1;
} else {
value = 0;
}
}