MCPcopy Create free account
hub / github.com/processing/p5.js / draw

Function draw

test/manual-test-examples/learningprocessing/chp5/example_5_2.js:18–52  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16}
17
18function draw() {
19 // Color the background and draw lines to divide the window in quadrants.
20 background(r, g, b);
21 stroke(0);
22 line(width / 2, 0, width / 2, height);
23 line(0, height / 2, width, height / 2);
24
25 // If the mouse is on the right hand side of the window, increase red.
26 // Otherwise, it is on the left hand side and decrease red.
27 if (mouseX > width / 2) {
28 r = r + 1;
29 } else {
30 r = r - 1;
31 }
32
33 // If the mouse is on the bottom of the window, increase blue.
34 // Otherwise, it is on the top and decrease blue.
35 if (mouseY > height / 2) {
36 b = b + 1;
37 } else {
38 b = b - 1;
39 }
40
41 // If the mouse is pressed (using the system variable mousePressed)
42 if (isMousePressed()) {
43 g = g + 1;
44 } else {
45 g = g - 1;
46 }
47
48 // Constrain all color values to between 0 and 255.
49 r = constrain(r, 0, 255);
50 g = constrain(g, 0, 255);
51 b = constrain(b, 0, 255);
52}

Callers

nothing calls this directly

Calls 1

constrainFunction · 0.85

Tested by

no test coverage detected