Skip to content

Commit 65f3300

Browse files
domenicannevk
authored andcommitted
Fix clock and blue-robot demos
- #468 pointed out that the clock demos were kind of confused as to which filenames they were using. This is now fixed. - The blue robot demo was missing some files, and had a useless base URL. This fixes https://www.w3.org/Bugs/Public/show_bug.cgi?id=28200.
1 parent 62bb233 commit 65f3300

File tree

10 files changed

+215
-25
lines changed

10 files changed

+215
-25
lines changed

.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ indent_size = 2
88
indent_style = space
99
trim_trailing_whitespace = true
1010

11+
[demos/**]
12+
insert_final_newline = false
13+
1114
[source]
1215
indent_size = 1
1316
max_line_length = 100
2.44 KB
Loading
+187
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
<!DOCTYPE HTML>
2+
<title>Blue Robot Demo</title>
3+
<style>
4+
html { overflow: hidden; min-height: 200px; min-width: 380px; }
5+
body { height: 200px; position: relative; margin: 8px; }
6+
.buttons { position: absolute; bottom: 0px; left: 0px; margin: 4px; }
7+
</style>
8+
<canvas width="380" height="200"></canvas>
9+
<script>
10+
var Landscape = function (context, width, height) {
11+
this.offset = 0;
12+
this.width = width;
13+
this.advance = function (dx) {
14+
this.offset += dx;
15+
};
16+
this.horizon = height * 0.7;
17+
// This creates the sky gradient (from a darker blue to white at the bottom)
18+
this.sky = context.createLinearGradient(0, 0, 0, this.horizon);
19+
this.sky.addColorStop(0.0, 'rgb(55,121,179)');
20+
this.sky.addColorStop(0.7, 'rgb(121,194,245)');
21+
this.sky.addColorStop(1.0, 'rgb(164,200,214)');
22+
// this creates the grass gradient (from a darker green to a lighter green)
23+
this.earth = context.createLinearGradient(0, this.horizon, 0, height);
24+
this.earth.addColorStop(0.0, 'rgb(81,140,20)');
25+
this.earth.addColorStop(1.0, 'rgb(123,177,57)');
26+
this.paintBackground = function (context, width, height) {
27+
// first, paint the sky and grass rectangles
28+
context.fillStyle = this.sky;
29+
context.fillRect(0, 0, width, this.horizon);
30+
context.fillStyle = this.earth;
31+
context.fillRect(0, this.horizon, width, height-this.horizon);
32+
// then, draw the cloudy banner
33+
// we make it cloudy by having the draw text off the top of the
34+
// canvas, and just having the blurred shadow shown on the canvas
35+
context.save();
36+
context.translate(width-((this.offset+(this.width*3.2)) % (this.width*4.0))+0, 0);
37+
context.shadowColor = 'white';
38+
context.shadowOffsetY = 30+this.horizon/3; // offset down on canvas
39+
context.shadowBlur = '5';
40+
context.fillStyle = 'white';
41+
context.textAlign = 'left';
42+
context.textBaseline = 'top';
43+
context.font = '20px sans-serif';
44+
context.fillText('WHATWG ROCKS', 10, -30); // text up above canvas
45+
context.restore();
46+
// then, draw the background tree
47+
context.save();
48+
context.translate(width-((this.offset+(this.width*0.2)) % (this.width*1.5))+30, 0);
49+
context.beginPath();
50+
context.fillStyle = 'rgb(143,89,2)';
51+
context.lineStyle = 'rgb(10,10,10)';
52+
context.lineWidth = 2;
53+
context.rect(0, this.horizon+5, 10, -50); // trunk
54+
context.fill();
55+
context.stroke();
56+
context.beginPath();
57+
context.fillStyle = 'rgb(78,154,6)';
58+
context.arc(5, this.horizon-60, 30, 0, Math.PI*2); // leaves
59+
context.fill();
60+
context.stroke();
61+
context.restore();
62+
};
63+
this.paintForeground = function (context, width, height) {
64+
// draw the box that goes in front
65+
context.save();
66+
context.translate(width-((this.offset+(this.width*0.7)) % (this.width*1.1))+0, 0);
67+
context.beginPath();
68+
context.rect(0, this.horizon - 5, 25, 25);
69+
context.fillStyle = 'rgb(220,154,94)';
70+
context.lineStyle = 'rgb(10,10,10)';
71+
context.lineWidth = 2;
72+
context.fill();
73+
context.stroke();
74+
context.restore();
75+
};
76+
};
77+
</script>
78+
<script>
79+
var BlueRobot = function () {
80+
this.sprites = new Image();
81+
this.sprites.src = 'blue-robot.png'; // this sprite sheet has 8 cells
82+
this.targetMode = 'idle';
83+
this.walk = function () {
84+
this.targetMode = 'walk';
85+
};
86+
this.stop = function () {
87+
this.targetMode = 'idle';
88+
};
89+
this.frameIndex = {
90+
'idle': [0], // first cell is the idle frame
91+
'walk': [1,2,3,4,5,6], // the walking animation is cells 1-6
92+
'stop': [7], // last cell is the stopping animation
93+
};
94+
this.mode = 'idle';
95+
this.frame = 0; // index into frameIndex
96+
this.tick = function () {
97+
// this advances the frame and the robot
98+
// the return value is how many pixels the robot has moved
99+
this.frame += 1;
100+
if (this.frame >= this.frameIndex[this.mode].length) {
101+
// we've reached the end of this animation cycle
102+
this.frame = 0;
103+
if (this.mode != this.targetMode) {
104+
// switch to next cycle
105+
if (this.mode == 'walk') {
106+
// we need to stop walking before we decide what to do next
107+
this.mode = 'stop';
108+
} else if (this.mode == 'stop') {
109+
if (this.targetMode == 'walk')
110+
this.mode = 'walk';
111+
else
112+
this.mode = 'idle';
113+
} else if (this.mode == 'idle') {
114+
if (this.targetMode == 'walk')
115+
this.mode = 'walk';
116+
}
117+
}
118+
}
119+
if (this.mode == 'walk')
120+
return 8;
121+
return 0;
122+
},
123+
this.paint = function (context, x, y) {
124+
if (!this.sprites.complete) return;
125+
// draw the right frame out of the sprite sheet onto the canvas
126+
// we assume each frame is as high as the sprite sheet
127+
// the x,y coordinates give the position of the bottom center of the sprite
128+
context.drawImage(this.sprites,
129+
this.frameIndex[this.mode][this.frame] * this.sprites.height, 0, this.sprites.height, this.sprites.height,
130+
x-this.sprites.height/2, y-this.sprites.height, this.sprites.height, this.sprites.height);
131+
};
132+
};
133+
</script>
134+
<script>
135+
var animating = false;
136+
var canvas = document.getElementsByTagName('canvas')[0];
137+
var context = canvas.getContext('2d');
138+
var landscape = new Landscape(context, canvas.width, canvas.height);
139+
var blueRobot = new BlueRobot();
140+
// paint when the browser wants us to, using requestAnimationFrame()
141+
function paint() {
142+
context.clearRect(0, 0, canvas.width, canvas.height);
143+
landscape.paintBackground(context, canvas.width, canvas.height);
144+
blueRobot.paint(context, canvas.width/2, landscape.horizon*1.1);
145+
landscape.paintForeground(context, canvas.width, canvas.height);
146+
if (animating)
147+
requestAnimationFrame(paint);
148+
}
149+
var interval = null;
150+
var cancelingTimeout = null;
151+
function startAnim() {
152+
if (cancelingTimeout) {
153+
clearTimeout(cancelingTimeout);
154+
cancelingTimeout = null;
155+
}
156+
if (!animating) {
157+
animating = true;
158+
paint();
159+
// but tick every 150ms, so that we don't slow down when we don't paint
160+
interval = setInterval(function () {
161+
var dx = blueRobot.tick();
162+
landscape.advance(dx);
163+
}, 100);
164+
}
165+
}
166+
function stopAnim() {
167+
if (cancelingTimeout) return;
168+
cancelingTimeout = setTimeout(function () {
169+
cancelingTimeout = null;
170+
if (animating) {
171+
clearInterval(interval);
172+
animating = false;
173+
}
174+
}, 1000);
175+
}
176+
paint();
177+
blueRobot.sprites.onload = paint;
178+
</script>
179+
<p class="buttons">
180+
<input type=button value="Walk" onclick="blueRobot.walk(); startAnim();">
181+
<input type=button value="Stop" onclick="blueRobot.stop(); stopAnim();">
182+
<footer>
183+
<small> Blue Robot Player Sprite by <a href="https://johncolburn.deviantart.com/">JohnColburn</a>.
184+
Licensed under the terms of the Creative Commons Attribution Share-Alike 3.0 Unported license.</small>
185+
<small> This work is itself licensed under a <a rel="license" href="https://creativecommons.org/licenses/by-sa/3.0/">Creative
186+
Commons Attribution-ShareAlike 3.0 Unported License</a>.</small>
187+
</footer>

demos/canvas/blue-robot/index.html

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<!DOCTYPE HTML>
22
<title>Blue Robot Demo</title>
3-
<base href="https://www.whatwg.org/demos/canvas/blue-robot/">
43
<style>
54
html { overflow: hidden; min-height: 200px; min-width: 380px; }
65
body { height: 200px; position: relative; margin: 8px; }
@@ -43,7 +42,7 @@
4342
context.textBaseline = 'top';
4443
context.font = '20px sans-serif';
4544
context.fillText('WHATWG ROCKS', 10, -30); // text up above canvas
46-
context.restore();
45+
context.restore();
4746
// then, draw the background tree
4847
context.save();
4948
context.translate(width-((this.offset+(this.width*0.2)) % (this.width*1.5))+30, 0);
@@ -156,8 +155,8 @@
156155
<input type=button value="Walk" onclick="blueRobot.walk()">
157156
<input type=button value="Stop" onclick="blueRobot.stop()">
158157
<footer>
159-
<small> Blue Robot Player Sprite by <a href="http://johncolburn.deviantart.com/">JohnColburn</a>.
158+
<small> Blue Robot Player Sprite by <a href="https://johncolburn.deviantart.com/">JohnColburn</a>.
160159
Licensed under the terms of the Creative Commons Attribution Share-Alike 3.0 Unported license.</small>
161-
<small> This work is itself licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/3.0/">Creative
160+
<small> This work is itself licensed under a <a rel="license" href="https://creativecommons.org/licenses/by-sa/3.0/">Creative
162161
Commons Attribution-ShareAlike 3.0 Unported License</a>.</small>
163162
</footer>
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
CACHE MANIFEST
2-
clock.html
2+
clock2.html
33
clock.css
44
clock.js
File renamed without changes.
File renamed without changes.

demos/offline/clock/clock1.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- clock.html -->
1+
<!-- clock1.html -->
22
<!DOCTYPE HTML>
33
<html>
44
<head>

demos/offline/clock/clock2.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!-- clock.html -->
1+
<!-- clock2.html -->
22
<!DOCTYPE HTML>
33
<html manifest="clock.appcache">
44
<head>

source

+19-18
Original file line numberDiff line numberDiff line change
@@ -72179,7 +72179,7 @@ END:VCARD</pre>
7217972179
&lt;figcaption>
7218072180
&lt;p>&lt;cite <strong>itemprop="title"</strong>>My Pond&lt;/cite>&lt;/p>
7218172181
&lt;p>&lt;small>Licensed under the &lt;a <strong>itemprop="license"</strong>
72182-
href="http://creativecommons.org/licenses/by-sa/3.0/us/">Creative
72182+
href="https://creativecommons.org/licenses/by-sa/3.0/us/">Creative
7218372183
Commons Attribution-Share Alike 3.0 United States License&lt;/a>
7218472184
and the &lt;a <strong>itemprop="license"</strong>
7218572185
href="http://www.opensource.org/licenses/mit-license.php">MIT
@@ -83226,23 +83226,23 @@ dictionary <dfn>PageTransitionEventInit</dfn> : <span>EventInit</span> {
8322683226
of the files for use offline.</p>
8322783227

8322883228
<p>To illustrate this, consider a simple clock applet consisting of an HTML page "<code
83229-
data-x="">clock.html</code>", a CSS style sheet "<code data-x="">clock.css</code>", and a JavaScript
83230-
script "<code data-x="">clock.js</code>".</p>
83229+
data-x="">clock1.html</code>", a CSS style sheet "<code data-x="">clock.css</code>", and a
83230+
JavaScript script "<code data-x="">clock.js</code>".</p>
8323183231

8323283232
<p>Before adding the manifest, these three files might look like this:</p>
8323383233

8323483234
<pre>EXAMPLE offline/clock/clock1.html</pre>
83235-
<pre>EXAMPLE offline/clock/clock1.css</pre>
83236-
<pre>EXAMPLE offline/clock/clock1.js</pre>
83235+
<pre>EXAMPLE offline/clock/clock.css</pre>
83236+
<pre>EXAMPLE offline/clock/clock.js</pre>
8323783237

83238-
<p>If the user tries to open the "<code data-x="">clock.html</code>" page while offline, though,
83238+
<p>If the user tries to open the "<code data-x="">clock1.html</code>" page while offline, though,
8323983239
the user agent (unless it happens to have it still in the local cache) will fail with an
8324083240
error.</p>
8324183241

8324283242
<p>The author can instead provide a manifest of the three files, say "<code
8324383243
data-x="">clock.appcache</code>":</p>
8324483244

83245-
<pre>EXAMPLE offline/clock/clock2.appcache</pre>
83245+
<pre>EXAMPLE offline/clock/clock.appcache</pre>
8324683246

8324783247
<p>With a small change to the HTML file, the manifest (served as <code>text/cache-manifest</code>)
8324883248
is linked to the application:</p>
@@ -83261,7 +83261,7 @@ dictionary <dfn>PageTransitionEventInit</dfn> : <span>EventInit</span> {
8326183261
overridden by manifests. Thus, pages will not expire from an application cache before the user
8326283262
agent has updated it, and even applications served over TLS can be made to work offline.</p>
8326383263

83264-
<p><a href="/demos/offline/clock/live-demo/clock.html">View this example online</a>.</p>
83264+
<p><a href="/demos/offline/clock/clock2.html">View this example online</a>.</p>
8326583265

8326683266

8326783267

@@ -117978,6 +117978,7 @@ INSERT INTERFACES HERE
117978117978
Justin Sinclair,
117979117979
Ka-Sing Chou,
117980117980
Kai Hendry,
117981+
Kamishetty Sreeja,
117981117982
&#x5442;&#x5eb7;&#x8c6a; (KangHao Lu)<!-- Kenny, kennyluck-->,
117982117983
Karl Dubost,
117983117984
Karl Tomlinson,
@@ -118352,38 +118353,38 @@ INSERT INTERFACES HERE
118352118353
<div w-nodev>
118353118354
<div itemscope itemtype="http://n.whatwg.org/work">
118354118355
<p>The image in the introduction is based on <a itemprop="work" href="http://www.flickr.com/photos/wonderlane/2986252088/">a photo</a>
118355-
by <a itemprop="http://creativecommons.org/ns#attributionURL" href="http://www.flickr.com/photos/wonderlane/">Wonderlane</a>.
118356-
(<a itemprop="license" href="http://creativecommons.org/licenses/by/2.0/">CC BY 2.0</a>)
118356+
by <a itemprop="https://creativecommons.org/ns#attributionURL" href="http://www.flickr.com/photos/wonderlane/">Wonderlane</a>.
118357+
(<a itemprop="license" href="https://creativecommons.org/licenses/by/2.0/">CC BY 2.0</a>)
118357118358
</div>
118358118359
</div>
118359118360

118360118361
<div itemscope itemtype="http://n.whatwg.org/work">
118361118362
<p>The image of two cute kittens in a basket used in the context menu example is based on
118362118363
<a itemprop="work" href="http://www.flickr.com/photos/digidreamgrafix/8370087640/">a photo</a>
118363-
by <a itemprop="http://creativecommons.org/ns#attributionURL" href="http://www.flickr.com/photos/digidreamgrafix/">Alex G</a>.
118364-
(<a itemprop="license" href="http://creativecommons.org/licenses/by/2.0/">CC BY 2.0</a>)
118364+
by <a itemprop="https://creativecommons.org/ns#attributionURL" href="http://www.flickr.com/photos/digidreamgrafix/">Alex G</a>.
118365+
(<a itemprop="license" href="https://creativecommons.org/licenses/by/2.0/">CC BY 2.0</a>)
118365118366
</div>
118366118367

118367118368
<div itemscope itemtype="http://n.whatwg.org/work">
118368118369
<p>The Blue Robot Player sprite used in the canvas demo is based on
118369-
<a itemprop="work" href="http://johncolburn.deviantart.com/art/Blue-Robot-Player-Sprite-323813997">a work</a> by
118370-
<a itemprop="http://creativecommons.org/ns#attributionURL" href="http://johncolburn.deviantart.com/">JohnColburn</a>.
118371-
(<a itemprop="license" href="http://creativecommons.org/licenses/by-sa/3.0/">CC BY-SA 3.0</a>)</p>
118370+
<a itemprop="work" href="https://johncolburn.deviantart.com/art/Blue-Robot-Player-Sprite-323813997">a work</a> by
118371+
<a itemprop="https://creativecommons.org/ns#attributionURL" href="http://johncolburn.deviantart.com/">JohnColburn</a>.
118372+
(<a itemprop="license" href="https://creativecommons.org/licenses/by-sa/3.0/">CC BY-SA 3.0</a>)</p>
118372118373
</div>
118373118374

118374118375
<div itemscope itemtype="http://n.whatwg.org/work">
118375118376
<p>The photograph of robot 148 climbing the tower at the FIRST Robotics Competition 2013 Silicon Valley Regional is based on
118376118377
<a itemprop="work" href="http://www.flickr.com/photos/lenore-m/8631391979/">a work</a> by
118377-
<a itemprop="http://creativecommons.org/ns#attributionURL" href="http://www.flickr.com/photos/lenore-m/">Lenore Edman</a>.
118378-
(<a itemprop="license" href="http://creativecommons.org/licenses/by/2.0/">CC BY 2.0</a>)</p>
118378+
<a itemprop="https://creativecommons.org/ns#attributionURL" href="http://www.flickr.com/photos/lenore-m/">Lenore Edman</a>.
118379+
(<a itemprop="license" href="https://creativecommons.org/licenses/by/2.0/">CC BY 2.0</a>)</p>
118379118380
</div>
118380118381

118381118382
<div itemscope itemtype="http://n.whatwg.org/work">
118382118383
<p>The diagram showing how <code data-x="attr-script-async">async</code> and <code
118383118384
data-x="attr-script-defer">defer</code> impact <code>script</code> loading is based on a
118384118385
similar diagram from <a itemprop="work"
118385118386
href="http://peter.sh/experiments/asynchronous-and-deferred-javascript-execution-explained/">a
118386-
blog post</a> by <a itemprop="http://creativecommons.org/ns#attributionURL"
118387+
blog post</a> by <a itemprop="https://creativecommons.org/ns#attributionURL"
118387118388
href="http://peter.sh/about/">Peter Beverloo</a>.
118388118389
(<a itemprop="license" href="https://creativecommons.org/publicdomain/zero/1.0/">CC0 1.0</a>)</p>
118389118390
</div>

0 commit comments

Comments
 (0)