Skip to content

Commit 2b86c8e

Browse files
authored
Merge pull request #969 from suhascv/example3
Added Conditional Shapes example |Prof Harris |Open@RIT
2 parents 191fc58 + d87e1d8 commit 2b86c8e

File tree

3 files changed

+144
-0
lines changed

3 files changed

+144
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* @name Conditional Shapes
3+
* @frame 400,400
4+
* @description contributed by <a href="https://www.rit.edu/directory/wmhics-w-michelle-harris">
5+
<b>Prof WM Harris,</b></a> How
6+
to draw different shapes mid canvas depending on the mouse position.<br/>
7+
<b>Functions</b>
8+
are created for the main canvas set up with the markers on the left and
9+
right hand sides. One is also created for the location of the mouse
10+
regarding the canvas and the markers. If the mouse is within the
11+
outer left hand beige rectangle, then the shape of circle is drawn
12+
down the center of the canvas. If the mouse is within the outer right
13+
hand beige rectangle, then the shape of square is drawn down the
14+
center of the canvas.
15+
*/
16+
function setup() {
17+
createCanvas(400, 400);
18+
strokeWeight(3);
19+
//center squares to match circles
20+
rectMode(CENTER);
21+
22+
//draw rects to mark far sides
23+
noStroke();
24+
fill("beige");
25+
rect(5, height / 2, 10, height);
26+
rect(width - 5, height / 2, 10, height);
27+
fill("orange");
28+
stroke("brown");
29+
30+
}
31+
32+
function draw() {
33+
point(mouseX, mouseY);
34+
35+
//if (test) {doThis; }
36+
//test: mouseX on far left of canvas
37+
//doThis: draw a circle at mouseY
38+
if (mouseX < 10) {
39+
circle(width / 2, mouseY, 20);
40+
}
41+
42+
//test: mouseX on far right of canvas
43+
//doThis: draw a square at mouseY
44+
if (mouseX > width - 10) {
45+
square(width / 2, mouseY, 20);
46+
}
47+
48+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* @name Conditional Shapes
3+
* @frame 400,400
4+
* @description contributed by <a href="https://www.rit.edu/directory/wmhics-w-michelle-harris">
5+
<b>Prof WM Harris,</b></a> How
6+
to draw different shapes mid canvas depending on the mouse position.<br/>
7+
<b>Functions</b>
8+
are created for the main canvas set up with the markers on the left and
9+
right hand sides. One is also created for the location of the mouse
10+
regarding the canvas and the markers. If the mouse is within the
11+
outer left hand beige rectangle, then the shape of circle is drawn
12+
down the center of the canvas. If the mouse is within the outer right
13+
hand beige rectangle, then the shape of square is drawn down the
14+
center of the canvas.
15+
*/
16+
function setup() {
17+
createCanvas(400, 400);
18+
strokeWeight(3);
19+
//center squares to match circles
20+
rectMode(CENTER);
21+
22+
//draw rects to mark far sides
23+
noStroke();
24+
fill("beige");
25+
rect(5, height / 2, 10, height);
26+
rect(width - 5, height / 2, 10, height);
27+
fill("orange");
28+
stroke("brown");
29+
30+
}
31+
32+
function draw() {
33+
point(mouseX, mouseY);
34+
35+
//if (test) {doThis; }
36+
//test: mouseX on far left of canvas
37+
//doThis: draw a circle at mouseY
38+
if (mouseX < 10) {
39+
circle(width / 2, mouseY, 20);
40+
}
41+
42+
//test: mouseX on far right of canvas
43+
//doThis: draw a square at mouseY
44+
if (mouseX > width - 10) {
45+
square(width / 2, mouseY, 20);
46+
}
47+
48+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* @name Conditional Shapes
3+
* @frame 400,400
4+
* @description contributed by <a href="https://www.rit.edu/directory/wmhics-w-michelle-harris">
5+
<b>Prof WM Harris,</b></a> How
6+
to draw different shapes mid canvas depending on the mouse position.<br/>
7+
<b>Functions</b>
8+
are created for the main canvas set up with the markers on the left and
9+
right hand sides. One is also created for the location of the mouse
10+
regarding the canvas and the markers. If the mouse is within the
11+
outer left hand beige rectangle, then the shape of circle is drawn
12+
down the center of the canvas. If the mouse is within the outer right
13+
hand beige rectangle, then the shape of square is drawn down the
14+
center of the canvas.
15+
*/
16+
function setup() {
17+
createCanvas(400, 400);
18+
strokeWeight(3);
19+
//center squares to match circles
20+
rectMode(CENTER);
21+
22+
//draw rects to mark far sides
23+
noStroke();
24+
fill("beige");
25+
rect(5, height / 2, 10, height);
26+
rect(width - 5, height / 2, 10, height);
27+
fill("orange");
28+
stroke("brown");
29+
30+
}
31+
32+
function draw() {
33+
point(mouseX, mouseY);
34+
35+
//if (test) {doThis; }
36+
//test: mouseX on far left of canvas
37+
//doThis: draw a circle at mouseY
38+
if (mouseX < 10) {
39+
circle(width / 2, mouseY, 20);
40+
}
41+
42+
//test: mouseX on far right of canvas
43+
//doThis: draw a square at mouseY
44+
if (mouseX > width - 10) {
45+
square(width / 2, mouseY, 20);
46+
}
47+
48+
}

0 commit comments

Comments
 (0)