-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathindex.html
126 lines (108 loc) · 3.38 KB
/
index.html
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!DOCTYPE html>
<html>
<head>
<script src="CodeMirror-2.21/lib/codemirror.js"></script>
<script src="CodeMirror-2.21/mode/javascript/javascript.js"></script>
<script src="scripts/editor.js"></script>
<link rel="stylesheet" href="CodeMirror-2.21/lib/codemirror.css">
<link rel="stylesheet" href="styles/xcodeTheme.css">
<link rel="stylesheet" href="styles/editor_stylesheet.css">
<title>CodeBook</title>
</head>
<body>
<div class="links">
<a target="_blank" href="http://danielhooper.tumblr.com/post/19313911658/codebook">What is this?</a>
<a target="_blank" href="https://twitter.com/danielchooper">@danielchooper</a>
<a target="_blank" href="https://github.com/danielchasehooper/CodeBook">Fork this</a>
</div>
<div id="superContainer">
<div id="codeContainer">
<textarea id="code" name="code">
// Interactive Javascript editor
// By Daniel Hooper
// Based on a talk by Bret Victor
//
// Alt+Drag numbers to change their values
// Have Fun!
var paralaxOffset = 732;
var paralaxSpeed = 4;
var forestHeight = 50;
var movementSpeed = 5;
var images;
framerate(50);
function circle(ctx,x,y,r){
ctx.beginPath();
ctx.arc(x, y, r, 0, Math.PI*2, true);
ctx.closePath();
ctx.fill();
}
function draw(ctx) {
// Sky
ctx.fillStyle = color(121,172,217);
ctx.fillRect(0,0,500,500);
// Sun
ctx.fillStyle=color(295,236,91);
circle(ctx,385,121,56);
// Trees
ctx.fillStyle = color(2,138,100);
ctx.fillRect(0,500-forestHeight,500,forestHeight);
var offset = -(Math.floor(paralaxOffset / 4)%538);
if(offset > 0) { offset -= 538; }
var foresty = 500-images[0].height-forestHeight;
ctx.drawImage(images[0], offset, foresty);
ctx.drawImage(images[0], offset+538, foresty);
offset = -(Math.floor(paralaxOffset)%538);
if(offset > 0) { offset -= 538; }
// telephone poles
var poleY = 500 - images[1].height;
ctx.drawImage(images[2], offset+538, poleY-140);
ctx.drawImage(images[2], offset, poleY-140);
// grass
ctx.drawImage(images[1], offset, poleY);
ctx.drawImage(images[1], offset+538, poleY);
// Input
if(Keys.left) {
paralaxOffset -= movementSpeed;
} else if(Keys.right) {
paralaxOffset += movementSpeed;
} else {
paralaxOffset++;
}
}
function getimg(src) {
var i = new Image();
i.src = "demoimages/"+src;
return i;
}
if (!images) {
images = [];
images[0] = getimg("forest.png");
images[1] = getimg("grass.png");
images[2] = getimg("pole2.png");
}
</textarea>
</div>
<div id="displayContainer">
<canvas id="TouchCodeMainCanvas" width="500" height="500">
Your Browser does not support Canvas
</canvas>
<div id="sourceHolder"></div>
<canvas id="TouchCodeHiddenCanvas" width="500" height="500">
Your Browser does not support Canvas
</canvas>
</div>
</div>
<div id="errorReport" class="hideReport">No one should ever see this! Hi Mom!</div>
<div id="inspectButton" class="button">Inspect</div>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-30047548-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>