Skip to content

Commit f8533d8

Browse files
committed
- refine sketch code
1 parent 6111af4 commit f8533d8

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

chapter-11-mouse_and_keyboard_interaction/paint_app/paint_app.pyde

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,19 +36,18 @@ def draw():
3636

3737
# black panel
3838
noStroke()
39-
fill('#000000'); rect(0, 0, palette, height)
39+
fill('#000000')
40+
rect(0, 0, palette, height)
4041
# color swatches
41-
p, p2 = palette, palette/2
42-
fill(swatches[0]); square(0, 0, p2)
43-
fill(swatches[1]); square(p2, 0, p2)
44-
fill(swatches[2]); square(0, p2, p2)
45-
fill(swatches[3]); square(p2, p2, p2)
46-
fill(swatches[4]); square(0, p, p2)
47-
fill(swatches[5]); square(p2, p, p2)
42+
for (i, swatch) in enumerate(swatches):
43+
sx = int(i%2) * palette/2
44+
sy = int(i/2) * palette/2
45+
fill(swatch)
46+
square(sx, sy, palette/2)
4847
# brush preview
4948
fill(brushcolor)
5049
if brushshape == ROUND:
51-
circle(30, 123, brushsize)
50+
circle(palette/2, 123, brushsize)
5251
paintmode = 'free'
5352
# clear button
5453
fill('#FFFFFF')
@@ -98,6 +97,6 @@ def keyPressed():
9897

9998
def mouseClicked():
10099
# clear canvas
101-
if mouseButton == LEFT and mouseX < 60 and mouseY > height-30:
100+
if mouseButton == LEFT and mouseX < palette and mouseY > height-30:
102101
fill('#004477')
103102
rect(palette, 0, width, height)

0 commit comments

Comments
 (0)