-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathMouseDrawing.pde
75 lines (64 loc) · 1.64 KB
/
MouseDrawing.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
import com.krab.lazy.*;
LazyGui gui;
PGraphics canvas;
PickerColor circleColor;
PickerColor lineColor;
float lineWeight, circleSize;
void setup() {
size(800, 800, P2D);
gui = new LazyGui(this);
canvas = createGraphics(width, height);
colorMode(HSB, 1, 1, 1, 1);
clearCanvas();
noStroke();
}
void draw() {
gui.pushFolder("drawing");
circleColor = gui.colorPicker("circle color", color(0));
circleSize = gui.slider("circle size", 75);
lineColor = gui.colorPicker("line color", color(1, 0.5, 1));
gui.colorPickerHueAdd("line color", radians(gui.slider("line hue +", 0.5f)));
lineWeight = gui.slider("line weight", 50);
gui.popFolder();
if (gui.button("clear")) {
clearCanvas();
}
image(canvas, 0, 0);
boolean mouseOutsideGui = gui.isMouseOutsideGui();
textSize(32);
text(mouseOutsideGui ? "The mouse is now a brush." : "The mouse is now using the GUI.", 10, height - 12);
}
void mousePressed() {
if (gui.isMouseOutsideGui()) {
drawCircleAtMouse();
}
}
void mouseReleased() {
if (gui.isMouseOutsideGui()) {
drawCircleAtMouse();
}
}
void mouseDragged() {
if (gui.isMouseOutsideGui()) {
drawLineAtMouse();
}
}
void clearCanvas() {
canvas.beginDraw();
canvas.background(gui.colorPicker("background", color(50)).hex);
canvas.endDraw();
}
void drawCircleAtMouse() {
canvas.beginDraw();
canvas.noStroke();
canvas.fill(circleColor.hex);
canvas.ellipse(mouseX, mouseY, circleSize, circleSize);
canvas.endDraw();
}
void drawLineAtMouse() {
canvas.beginDraw();
canvas.stroke(lineColor.hex);
canvas.strokeWeight(lineWeight);
canvas.line(pmouseX, pmouseY, mouseX, mouseY);
canvas.endDraw();
}