|
1 | | -var s0 = function( sketch ) { |
| 1 | +var sketch0 = function( p ) { |
2 | 2 |
|
3 | 3 | var gray = 0; |
4 | 4 | var h = 10; |
5 | 5 |
|
6 | | - sketch.setup = function() { |
7 | | - var cnv = sketch.createCanvas(400, 400); |
| 6 | + p.setup = function() { |
| 7 | + var cnv = p.createCanvas(400, 400); |
8 | 8 | cnv.mousePressed(increaseH); |
9 | | - sketch.rectMode(sketch.CENTER); |
10 | | - sketch.print("both gray values should change, rect in sketch0 should change only when clicking on canvas0"); |
| 9 | + p.rectMode(p.CENTER); |
| 10 | + p.print("both gray values should change, rect in sketch0 should change only when clicking on canvas0"); |
11 | 11 | }; |
12 | 12 |
|
13 | | - sketch.draw = function() { |
14 | | - sketch.background(gray); |
15 | | - sketch.rect(sketch.width/2, sketch.height/2, h, h); |
| 13 | + p.draw = function() { |
| 14 | + p.background(gray); |
| 15 | + p.rect(p.width/2, p.height/2, h, h); |
16 | 16 | }; |
17 | 17 |
|
18 | | - sketch.mousePressed = function() { |
| 18 | + p.mousePressed = function() { |
19 | 19 | gray += 10; |
20 | 20 | }; |
21 | 21 |
|
22 | | - sketch.mouseMoved = function() { |
23 | | - sketch.print("sketch0 x:"+sketch.mouseX+" y:"+sketch.mouseY); |
| 22 | + p.mouseMoved = function() { |
| 23 | + p.print("sketch0 x:"+p.mouseX+" y:"+p.mouseY); |
24 | 24 | }; |
25 | 25 |
|
26 | 26 | function increaseH() { |
27 | 27 | h += 5; |
28 | 28 | } |
29 | 29 | }; |
30 | 30 |
|
31 | | -var myp5_0 = new p5(s0, 'div0'); |
| 31 | +var myp5_0 = new p5(sketch0, 'div0'); |
32 | 32 |
|
33 | 33 |
|
34 | 34 |
|
35 | 35 |
|
36 | 36 |
|
37 | | -var s1 = function( sketch ) { |
| 37 | +var sketch1 = function( p ) { |
38 | 38 |
|
39 | 39 | var gray = 0; |
40 | 40 |
|
41 | | - sketch.setup = function() { |
42 | | - sketch.createCanvas(400, 400); |
| 41 | + p.setup = function() { |
| 42 | + p.createCanvas(400, 400); |
43 | 43 | }; |
44 | 44 |
|
45 | | - sketch.draw = function() { |
46 | | - sketch.background(255, 0, 100); |
47 | | - sketch.fill(gray); |
48 | | - sketch.rect(sketch.width/2, sketch.height/2, 50, 50); |
| 45 | + p.draw = function() { |
| 46 | + p.background(255, 0, 100); |
| 47 | + p.fill(gray); |
| 48 | + p.rect(p.width/2, p.height/2, 50, 50); |
49 | 49 | }; |
50 | 50 |
|
51 | | - sketch.mousePressed = function() { |
| 51 | + p.mousePressed = function() { |
52 | 52 | gray += 10; |
53 | 53 | }; |
54 | 54 |
|
55 | | - sketch.mouseMoved = function() { |
56 | | - console.log("sketch1 x:"+sketch.mouseX+" y:"+sketch.mouseY); |
| 55 | + p.mouseMoved = function() { |
| 56 | + console.log("sketch1 x:"+p.mouseX+" y:"+p.mouseY); |
57 | 57 | }; |
58 | 58 |
|
59 | | - sketch.mouseReleased = function() { |
| 59 | + p.mouseReleased = function() { |
60 | 60 | console.log("mouseReleased"); |
61 | 61 | }; |
62 | 62 |
|
63 | | - sketch.keyPressed = function() { |
| 63 | + p.keyPressed = function() { |
64 | 64 | console.log("keyPressed"); |
65 | 65 | }; |
66 | 66 |
|
67 | | - sketch.mouseDragged = function() { |
| 67 | + p.mouseDragged = function() { |
68 | 68 | console.log("mouseDragged"); |
69 | 69 | }; |
70 | 70 | }; |
71 | 71 |
|
72 | 72 |
|
73 | | -var myp5_1 = new p5(s1, 'div1'); |
| 73 | +var myp5_1 = new p5(sketch1, 'div1'); |
74 | 74 |
|
0 commit comments