-
Notifications
You must be signed in to change notification settings - Fork 1
/
unit1.pas
327 lines (253 loc) · 8.47 KB
/
unit1.pas
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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
unit Unit1;
{
10/19/2021 08:22:13 PM
Noella Hazel Sketch is a program my daughter Noella wanted to write so I can
teach her some basics about programming. Most of it is her design and I
only helped write code that would implement how she described the desire
behavior. I kept it as simple as possible but functional. I am currently
a hobbyist and beginner programmer myself. There may be plenty of room for
improvement in the code, however it was coded with a 7 year old child who has
never had any programming experience. I am very proud of my daughters efforts
here and her well thought out design. I hope in several years she can look
back at this and say "This is where i got my start and became a succesful and
amazing programmer!" Love you Noella! :-*
Copyright (c) 2021 Noella Stone
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to
deal in the Software without restriction, including without limitation the
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
sell copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
IN THE SOFTWARE.
}
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, StdCtrls,
Spin, LCLType, ComCtrls, Menus, PrintersDlgs;
type
{ TForm1 }
TForm1 = class(TForm)
btnErase: TButton;
ColorButton1: TColorButton;
ColorDialog1: TColorDialog;
imgDrawingSpace: TImage;
Label1: TLabel;
Label2: TLabel;
MenuItem1: TMenuItem;
mnuSuperDuperFast: TMenuItem;
mnuAbout: TMenuItem;
mnuExtraFast: TMenuItem;
mnuSlow: TMenuItem;
mnuMedSlow: TMenuItem;
mnuMedium: TMenuItem;
mnuMedFast: TMenuItem;
mnuFast: TMenuItem;
pmnuSpeed: TPopupMenu;
PrintDialog1: TPrintDialog;
shpPointer: TShape;
shpX: TShape;
shpY: TShape;
sedtX: TSpinEdit;
sedtY: TSpinEdit;
tmrDrawer: TTimer;
TrackBar1: TTrackBar;
procedure btnEraseClick(Sender: TObject);
procedure ColorDialog1Close(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
procedure FormKeyUp(Sender: TObject; var Key: word; Shift: TShiftState);
procedure FormResize(Sender: TObject);
procedure mnuAboutClick(Sender: TObject);
procedure mnuExtraFastClick(Sender: TObject);
procedure mnuSlowClick(Sender: TObject);
procedure mnuMedSlowClick(Sender: TObject);
procedure mnuMedFastClick(Sender: TObject);
procedure mnuFastClick(Sender: TObject);
procedure mnuMediumClick(Sender: TObject);
procedure mnuSuperDuperFastClick(Sender: TObject);
procedure sedtXChange(Sender: TObject);
procedure sedtYChange(Sender: TObject);
procedure tmrDrawerTimer(Sender: TObject);
procedure TrackBar1Change(Sender: TObject);
private
public
procedure DoDrawBlankBoard;
procedure DoDrawPoint;
end;
var
Form1: TForm1;
eraserUp, eraseLeft: boolean;
drPntX, drPntY, tmpAr: integer;
kbUp: boolean = False;
kbDn: boolean = False;
kbLt: boolean = False;
kbRt: boolean = False;
kbShft: boolean = False;
kbAlt: boolean = False;
implementation
{$R *.lfm}
{ TForm1 }
procedure TForm1.btnEraseClick(Sender: TObject);
var
shakeStart, startTop, StartLeft: integer;
begin
Randomize;
shakeStart := GetTickCount64;
startTop := Form1.Top;
StartLeft := form1.Left;
while GetTickCount64 - shakeStart < 2000 do
begin
Form1.Left := StartLeft + Random(200) - 100;
Form1.Top := startTop + Random(200) - 100;
Application.ProcessMessages;
sleep(75);
end;
Form1.Left := StartLeft;
Form1.Top := startTop;
DoDrawBlankBoard;
end;
procedure TForm1.ColorDialog1Close(Sender: TObject);
begin
//shpPointer.Brush.Color:=ColorDialog1.Color;
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
DoDrawBlankBoard;
ColorDialog1.Color := clBlack;
//shpPointer.Brush.Color:=ColorDialog1.Color;
tmpAr := 0;
end;
procedure TForm1.FormKeyDown(Sender: TObject; var Key: word; Shift: TShiftState);
begin
if key = VK_LEFT then kbLt := True;
if key = VK_RIGHT then kbRt := True;
if key = VK_UP then kbUp := True;
if key = VK_DOWN then kbDn := True;
if key = VK_SHIFT then kbShft := True;
if Key = VK_MENU then kbAlt := True;
key := 0;
tmrDrawer.Enabled := True;
end;
procedure TForm1.FormKeyUp(Sender: TObject; var Key: word; Shift: TShiftState);
begin
if key = VK_LEFT then kbLt := False;
if key = VK_RIGHT then kbRt := False;
if key = VK_UP then kbUp := False;
if key = VK_DOWN then kbDn := False;
if key = VK_SHIFT then kbShft := False;
if Key = VK_MENU then kbAlt := False;
if not kbDn and not kbUp and not kbLt and not kbRt then tmrDrawer.Enabled := False;
key := 0;
end;
procedure TForm1.tmrDrawerTimer(Sender: TObject);
var
fastloop: integer = 1;
i: integer;
begin
if mnuExtraFast.Checked then
fastloop := 2
else if mnuSuperDuperFast.Checked then
fastloop := 7
else if kbShft then
fastloop := 40
else
fastloop := 1;
for i := 0 to fastloop do
begin
if kbLt then sedtX.Value := sedtX.Value - 1;
if kbRt then sedtX.Value := sedtX.Value + 1;
if kbUp then sedtY.Value := sedtY.Value - 1;
if kbDn then sedtY.Value := sedtY.Value + 1;
end;
end;
procedure TForm1.FormResize(Sender: TObject);
begin
imgDrawingSpace.Picture.Bitmap.SetSize(imgDrawingSpace.Width, imgDrawingSpace.Height);
sedtX.MaxValue := imgDrawingSpace.Width - 30;
sedtY.MaxValue := imgDrawingSpace.Height - 30;
DoDrawBlankBoard;
end;
procedure TForm1.mnuAboutClick(Sender: TObject);
begin
ShowMessage('This Etch A Sketch program was designed by Noella Stone using Lazarus.' +
sLineBreak + 'Code is also her design with her fathers assistance.' +
sLineBreak + 'Not bad for a 7 year old! Good job Noella!' +
sLineBreak + '10/19/2021');
end;
procedure TForm1.mnuExtraFastClick(Sender: TObject);
begin
tmrDrawer.Interval := 1;
end;
procedure TForm1.mnuSlowClick(Sender: TObject);
begin
tmrDrawer.Interval := 75;
end;
procedure TForm1.mnuMedSlowClick(Sender: TObject);
begin
tmrDrawer.Interval := 40;
end;
procedure TForm1.mnuMedFastClick(Sender: TObject);
begin
tmrDrawer.Interval := 10;
end;
procedure TForm1.mnuFastClick(Sender: TObject);
begin
tmrDrawer.Interval := 5;
end;
procedure TForm1.mnuMediumClick(Sender: TObject);
begin
tmrDrawer.Interval := 20;
end;
procedure TForm1.mnuSuperDuperFastClick(Sender: TObject);
begin
tmrDrawer.Interval := 1;
end;
procedure TForm1.sedtXChange(Sender: TObject);
begin
drPntX := sedtX.Value;
DoDrawPoint;
end;
procedure TForm1.sedtYChange(Sender: TObject);
begin
drPntY := sedtY.Value;
DoDrawPoint;
end;
procedure TForm1.TrackBar1Change(Sender: TObject);
begin
shpPointer.Width := TrackBar1.Position * 2;
shpPointer.Height := TrackBar1.Position * 2;
end;
procedure TForm1.DoDrawBlankBoard;
begin
imgDrawingSpace.Canvas.Pen.Style := psInsideframe;
imgDrawingSpace.Canvas.Pen.Color := clGray;
imgDrawingSpace.Canvas.Pen.Width := 10;
imgDrawingSpace.Canvas.Brush.Style := bsSolid;
imgDrawingSpace.Canvas.Brush.Color := clWhite;
imgDrawingSpace.Canvas.Rectangle(0, 0, imgDrawingSpace.Width, imgDrawingSpace.Height);
end;
procedure TForm1.DoDrawPoint;
begin
imgDrawingSpace.Canvas.Pen.Color := ColorDialog1.Color;
imgDrawingSpace.Canvas.Pen.Width := TrackBar1.Position;
if not kbAlt then
begin
imgDrawingSpace.Canvas.MoveTo(drPntX + 15, drPntY + 15);
imgDrawingSpace.Canvas.LineTo(drPntX + 15, drPntY + 15);
end;
shpPointer.Left := (drPntX + imgDrawingSpace.Left + 15) - (shpPointer.Width div 2);
shpPointer.Top := (drPntY + imgDrawingSpace.Top + 15) - (shpPointer.Height div 2);
//Memo1.Lines.Add('Points[' + IntToStr(tmpAr) + '] := Point(' + IntToStr(drPntX) + ',' +
// IntToStr(drPntY) + ');');
//Inc(tmpAr, 1);
end;
end.