-
Notifications
You must be signed in to change notification settings - Fork 0
/
mouseevents.pde
127 lines (112 loc) · 2.64 KB
/
mouseevents.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// MAGIC SERPENT - THAT TOY CONSISTENT ON SMALL PRISMS JOINED BY THEIR SQUARE FACES-
// A very simple GUI to emulate kay events if
// keys are not available e.g. android.
class Circle {
public float rad;
public color col;
public float x,y;
public int code;
public Circle(float xc, float yc, float r, color c, int cod){
this.rad=r;
this.x=xc;
this.y=yc;
this.col=c;
this.code=cod;
}
public Circle(float xc, float yc, color c, int cod){
this.rad=width/10;
this.x=xc;
this.y=yc;
this.col=c;
this.code=cod;
}
public Circle(float xc, float yc, float r, int cod){
this.rad=r;
this.x=xc;
this.y=yc;
this.col=color(96,96,96);
this.code=cod;
}
public Circle(float xc, float yc, int cod){
this.rad=width/10;
this.x=xc;
this.y=yc;
this.col=color(96,96,96);
this.code=cod;
}
public boolean insideCircle(float xx,float yy){
return (dist(xx,yy,this.x,this.y)<this.rad);
}
public void draw(){
float a,b,c;
fill(this.col);
noStroke();
ellipse (this.x, this.y, this.rad, this.rad);
fill(255,255,255);
stroke(255,255,255);
switch (this.code){
case UP:
a=-1.5;
break;
case DOWN:
a=1.5;
break;
case LEFT:
a=1;
break;
case RIGHT:
a=2;
break;
default:
a=99;
}
if (a!=99){
b=a+2;
c=a+4;
triangle(
this.x+this.rad*cos(a*PI/3)/2,this.y+this.rad*sin(a*PI/3)/2,
this.x+this.rad*cos(b*PI/3)/2,this.y+this.rad*sin(b*PI/3)/2,
this.x+this.rad*cos(c*PI/3)/2,this.y+this.rad*sin(c*PI/3)/2
);
}
}
}
Circle [] circles={};
void guiSetup(){
float cr;
cr=min(width,height)/10;
circles= (Circle[]) append(circles, new Circle(width/2-(cr*1.5),height*0.9-cr,cr,LEFT));
circles= (Circle[]) append(circles, new Circle(width/2+(cr*1.5),height*0.9-cr,cr,RIGHT));
circles= (Circle[]) append(circles,new Circle(width/2, height*0.9-cr,cr,UP));
}
void guiDraw(){
int i;
for ( i=0; i<circles.length; i++){
circles[i].draw();
}
}
void mousePressed(){
int code=-1;
for (int i=0; i<circles.length; i++){
if (circles[i].insideCircle(mouseX,mouseY)){
code=circles[i].code;
}
}
if (demo ){
demo=false;
}
switch(code){
case LEFT:
iprisma--;
if (iprisma<0) iprisma=anguloprisma.length-1;
break;
case RIGHT:
iprisma++;
if (iprisma>=anguloprisma.length) iprisma=anguloprisma.length-1;
break;
case UP:
anguloprisma[iprisma]++;
if (anguloprisma[iprisma]>=4){ anguloprisma[iprisma]=0; }
break;
}
}