forked from williamngan/pt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart.html
More file actions
58 lines (42 loc) · 1.63 KB
/
start.html
File metadata and controls
58 lines (42 loc) · 1.63 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<!DOCTYPE html>
<html>
<head>
<title>Pt - getting started</title>
<script type="text/javascript" src="../dist/pt.min.js"></script>
</head>
<body>
<div id="pt" style="width: 500px; height: 500px;"></div>
<script type="text/javascript">
(function() {
var space = new CanvasSpace( "hello", "#f1f1f1" ).display( "#pt" );
var form = new Form( space );
var dot = new Circle( 250, 250 ).setRadius( 50 );
var another = new Circle( 100, 100 ).setRadius( 50 );
var bot = {
animate: function ( time, fs, context ) {
form.fill( "#999" ).text( new Point( 20, 20 ), "frame rate is " + (1000 / fs) );
form.fill( "#5AF" ).stroke( false );
dot.setRadius( Math.abs( 500 - time % 1000 ) / 50 + 50 );
form.circle( dot );
form.fill( false ).stroke( "#fc0", 5 );
form.circle( another );
var hits = another.intersectCircle( dot );
if (hits.length > 0) {
form.stroke( "#fff" ).fill( "#0C9" );
form.line( new Line( hits[0] ).to( hits[1] ) );
form.points( hits, 5, true );
}
},
onMouseAction: function ( type, x, y, evt ) {
if (type == "move") {
another.set( x, y )
}
}
};
space.add( bot );
space.bindMouse();
space.play();
})();
</script>
</body>
</html>