-
Notifications
You must be signed in to change notification settings - Fork 0
/
palindrome_rev1.pde
233 lines (176 loc) · 4.61 KB
/
palindrome_rev1.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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
/*
The End is Where We Start From: Week 3
*/
/*
TO DO
- replace type on drawing and erase labels to be icons
- implement eraser tool
- store the motions, then redraw them after a pause
FIXME
- make the program accept regular colors in 0,0,0 format, not just a single integer
*/
boolean DEBUG = true ;
PFont font ;
String line1 = "palindrome interface";
String line2 = "version 0.2";
boolean first_run = true ;
int canvas_size_x = 700 ;
int canvas_size_y = canvas_size_x ;
int background_color = 255 ;
int brush_diameter = 4 ;
int eraser_diameter = 16 ;
float start_time ;
float end_time ;
TextButton clear_button ;
TextButton save_button ;
DrawingButton brush_button ;
DrawingButton erase_button ;
String default_mode = "drawing" ;
String current_mode ;
ArrayList saved_coordinates = new ArrayList ( ) ;
void setup( )
{
size (canvas_size_x, canvas_size_y+50);
background(background_color);
smooth ( ) ;
font = loadFont("HelveticaNeue-18.vlw");
current_mode = default_mode ;
draw_heading ( ) ;
// clear_button = new Button ("clear", 18, (width/2)-95, 20, 80, 20);
clear_button = new TextButton ("clear", 18, 66, 20, 80, 24);
clear_button.h_buffer = 2 ; // horizontal buffer for vertical centering
clear_button.button_color_off = 0;
save_button = new TextButton ( "save", 18, 148, 20, 80, 24) ;
save_button.h_buffer = 2 ;
save_button.button_color_off = 0;
brush_button = new DrawingButton ( "b", 10, 14, 20, 24, 24 ) ;
brush_button.h_buffer = 1 ;
erase_button = new DrawingButton ( "e", 10, 40, 20, 24, 24 ) ;
erase_button.h_buffer = 1 ;
// activate brush tool
toggle_mode ( current_mode ) ;
// change drawing button to "selected" state
}
void draw ( )
{
clear_button.display ( ) ;
save_button.display ( ) ;
brush_button.display ( ) ;
erase_button.display ( ) ;
if ( current_mode.equals("drawing"))
{
//println ( "entering drawing mode" ) ;
brush_button.button_color = 100 ;
erase_button.button_color = 20 ;
activate_drawing ( ) ;
// make the cursor clickable
}
if ( current_mode.equals("erasing"))
{
//println ( "entering erasing mode" ) ;
erase_button.button_color = 100 ;
brush_button.button_color = 20 ;
activate_erasing ( ) ;
}
}
void toggle_mode ( String new_mode )
{
current_mode = new_mode ;
}
void activate_drawing ( )
{
if ( mousePressed && mouseY > 50 && pmouseY > 50 )
{
draw_correct ( ) ;
save_mirrored ( ) ;
}
}
void mousePressed ( )
{
if ( current_mode.equals("drawing") )
{
start_time = millis () ;
}
}
void activate_erasing ( )
{
if ( mousePressed && mouseY > (50+eraser_diameter) && pmouseY > (50+eraser_diameter) )
{
strokeWeight(eraser_diameter);
stroke(255);
line(mouseX, mouseY, pmouseX, pmouseY);
}
}
void draw_correct ( )
{
strokeWeight(brush_diameter);
stroke(0);
line(mouseX, mouseY, pmouseX, pmouseY);
}
void save_mirrored ( )
{
/*
strokeWeight(brush_diameter);
stroke(0);
line((width-mouseX), mouseY, (width-pmouseX), pmouseY);
*/
saved_coordinates.add ( new CoordinateSaver ( (width-mouseX), mouseY, (width-pmouseX), pmouseY ) ) ;
// println ( saved_coordinates ) ;
/*
if (mouseX > (width/2))
{
line((width-mouseX), mouseY, (width-pmouseX), pmouseY);
}
else
{
line((width-mouseX), mouseY, (width-pmouseX), pmouseY);
}
*/
}
void mouseReleased()
{
if ( current_mode.equals("drawing") )
{
end_time = millis() ;
// this conditional prevents a nasty dot from appearing in the header
if ( mouseY > 50 && pmouseY > 50 )
{
//delay(2000) ;
draw_mirror_image ( end_time - start_time ) ;
}
}
println ("start time: " + (start_time ) ) ;
println ("end time: " + (end_time ) ) ;
println ("elapsed time: " + ( end_time - start_time ) ) ;
}
void draw_mirror_image ( float duration )
{
strokeWeight(brush_diameter);
stroke(0);
line((width-mouseX), mouseY, (width-pmouseX), pmouseY);
for (int i = 0; i< saved_coordinates.size(); i++ )
{
CoordinateSaver coords = (CoordinateSaver) saved_coordinates.get(i);
line(coords.mx, coords.my, coords.pmx, coords.pmy);
}
}
void draw_heading ()
{
println ( "drawing heading" ) ;
int h1_text_color = 100 ;
int h1_text_size = 30 ;
int h2_text_color = 200 ;
int h2_text_size = 9 ;
fill ( h1_text_color ) ;
textAlign ( LEFT) ;
//textMode(SCREEN);
textFont ( font, h1_text_size) ;
text (line1, (width/2)+15, 40);
fill(h2_text_color);
//textMode(SCREEN);
textFont(font, h2_text_size);
text (line2, width-50, 40);
// draw a line to separate the header
stroke(h2_text_color);
line(0, 50, width, 50);
}