"Drawing Circles"
Bootstrap 3.3.0 Snippet by duuraine

1
2
3
4
5
6
7
8
9
10
11
12
13
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<div class="container">
<div class="row">
<h2>Create your snippet's HTML, CSS and Javascript in the editor tabs</h2>
<canvas id="myCanvas" width="800" height="350"></canvas>
</div>
</div>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
7
8
9
body{
background: #ddd;
}
#myCanvas{
margin: 10px auto;
background: #444;
border: thin inset #000000;
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
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
$(window).load(function() {
var canvas = document.getElementById("myCanvas");
var context = canvas.getContext("2d");
context.font = "38pt Arial";
context.fillStyle = "cornflowerblue";
context.strokeStyle = "blue";
function drawCircle(e){
var loc = windowtoCanvas(canvas, e.clientX, e.clientY);
console.log(loc);
context.beginPath();
context.fillStyle = "#ffffff";
context.strokeStyle = "#125512";
context.lineWidth = 1;
context.arc(loc.x, loc.y, randRange(10, 24), 0, Math.PI*2);
context.fill();
context.stroke();
}
function windowtoCanvas(canvas, x, y){
var bbox = canvas.getBoundingClientRect();
return{x: x- bbox.left*(canvas.width/bbox.width), y: y - bbox.top*(canvas.height/bbox.height)
}
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Related: See More


Questions / Comments: