Skip to content

Commit ca1e06e

Browse files
author
raywu6
committed
add K02
1 parent 678a5c5 commit ca1e06e

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -126,4 +126,6 @@ ehthumbs.db
126126

127127
# Filenames with special characters
128128
**/*[\\/\:;*?!'"<>|$º•¶§∞¢£]*
129-
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
129+
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
130+
131+
pristine*

02_canvas/clickdraw.html

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head> <!-- start head -->
4+
5+
<style>
6+
#playground {border: 1px solid black }
7+
</style>
8+
9+
</head> <!-- end head -->
10+
<body>
11+
12+
<h1>Bonjour monde!</h1>
13+
<h2>Demo</h2>
14+
<div>
15+
16+
<button id="clear">Clear</button>
17+
18+
<br>
19+
20+
<canvas height="600"
21+
width="600" id="playground">
22+
<!-- fallback/alternate display text here (for old, noncompliant browsers) -->
23+
dis dat alt txt
24+
</canvas>
25+
26+
</div>
27+
28+
<script src="dotconn.js"> </script>
29+
30+
</body> <!-- end body -->
31+
</html> <!-- end html -->

02_canvas/dotconn.js

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// team GreatBob (Raymond Wu, Jerry Ye)
2+
// SoftDev2 pd7
3+
// K02 -- Connecting the Dots
4+
// 2019-02-04
5+
6+
7+
var canvas = document.getElementById("playground");
8+
var ctx = canvas.getContext("2d");
9+
10+
var clearButton = document.getElementById("clear");
11+
12+
// clear canvas on button click
13+
clearButton.addEventListener( "click" , function() {
14+
15+
ctx.clearRect( 0, 0, canvas.width, canvas.height );
16+
console.log("canvas cleared");
17+
18+
previousX = previousY = undefined; //reset prev center coordinates
19+
});
20+
21+
var previousX; // store center coordinates of prev ellipse
22+
var previousY;
23+
24+
// draw dot upon click on canvas
25+
canvas.addEventListener( "click" , function(e) {
26+
27+
e.preventDefault(); // won't register a "click"
28+
29+
ctx.beginPath(); // start ellipse path
30+
ctx.ellipse( e.offsetX, e.offsetY, 25, 25, 0, 0, 2 * Math.PI );
31+
// x, y, radiusX, radiusY, rotation, startAngle, endAngle [, anticlockwise]
32+
ctx.strokeStyle = "#0000ff"; // blue
33+
ctx.stroke();
34+
35+
if (previousX != undefined) { // if not first circle
36+
ctx.beginPath(); // start line path
37+
ctx.moveTo(e.offsetX, e.offsetY); // move to center of circle
38+
ctx.lineTo( previousX, previousY ); // draw line to prev center
39+
ctx.strokeStyle = "#ff0000"; // red
40+
ctx.stroke();
41+
}
42+
43+
previousX = e.offsetX; // update prev center coordinates
44+
previousY = e.offsetY;
45+
46+
});
47+

0 commit comments

Comments
 (0)