Skip to content

Commit 3e8ca27

Browse files
committed
[css-paint-api] Move circle demo into circle/ folder.
Begins to address #340.
1 parent 63e782e commit 3e8ca27

File tree

3 files changed

+86
-23
lines changed

3 files changed

+86
-23
lines changed

css-paint-api/Overview.bs

+38-23
Original file line numberDiff line numberDiff line change
@@ -623,41 +623,56 @@ Example 1: A colored circle. {#example-1}
623623
-----------------------------------------
624624

625625
<pre class='lang-markup'>
626-
&lt;div id="myElement">
627-
CSS is awesome.
628-
&lt;/div>
629-
626+
&lt;!DOCTYPE html>
630627
&lt;style>
631-
#myElement {
632-
--circle-color: red;
628+
#example {
629+
--circle-color: deepskyblue;
630+
633631
background-image: paint(circle);
634-
}
632+
font-family: sans-serif;
633+
font-size: 36px;
634+
transition: --circle-color 1s;
635+
}
636+
637+
#example:focus {
638+
--circle-color: purple;
639+
}
635640
&lt;/style>
636641

642+
&lt;textarea id="example">
643+
CSS is awesome.
644+
&lt;/textarea>
645+
637646
&lt;script>
647+
CSS.registerProperty({
648+
name: '--circle-color',
649+
syntax: '&lt;color>',
650+
initialValue: 'black',
651+
inherit: false
652+
});
638653
CSS.paintWorklet.import('circle.js');
639654
&lt;/script>
640655
</pre>
641656

642657
<pre class='lang-javascript'>
643658
// circle.js
644659
registerPaint('circle', class {
645-
static get inputProperties() { return ['--circle-color']; }
646-
paint(ctx, geom, properties) {
647-
// Change the fill color.
648-
const color = properties.get('--circle-color');
649-
ctx.fillStyle = color;
650-
651-
// Determine the center point and radius.
652-
const x = geom.width / 2;
653-
const y = geom.height / 2;
654-
const radius = Math.min(x, y);
655-
656-
// Draw the circle \o/
657-
ctx.beginPath();
658-
ctx.arc(x, y, radius, 0, 2 * Math.PI, false);
659-
ctx.fill();
660-
}
660+
static get inputProperties() { return ['--circle-color']; }
661+
paint(ctx, geom, properties) {
662+
// Change the fill color.
663+
const color = properties.get('--circle-color');
664+
ctx.fillStyle = color.cssText;
665+
666+
// Determine the center point and radius.
667+
const x = geom.width / 2;
668+
const y = geom.height / 2;
669+
const radius = Math.min(x, y);
670+
671+
// Draw the circle \o/
672+
ctx.beginPath();
673+
ctx.arc(x, y, radius, 0, 2 * Math.PI, false);
674+
ctx.fill();
675+
}
661676
});
662677
</pre>
663678

css-paint-api/circle/circle.js

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
registerPaint('circle', class {
2+
static get inputProperties() { return ['--circle-color']; }
3+
paint(ctx, geom, properties) {
4+
// Change the fill color.
5+
const color = properties.get('--circle-color');
6+
ctx.fillStyle = color.cssText;
7+
8+
// Determine the center point and radius.
9+
const x = geom.width / 2;
10+
const y = geom.height / 2;
11+
const radius = Math.min(x, y);
12+
13+
// Draw the circle \o/
14+
ctx.beginPath();
15+
ctx.arc(x, y, radius, 0, 2 * Math.PI, false);
16+
ctx.fill();
17+
}
18+
});

css-paint-api/circle/index.html

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE html>
2+
<style>
3+
#example {
4+
--circle-color: deepskyblue;
5+
6+
background-image: paint(circle);
7+
font-family: sans-serif;
8+
font-size: 36px;
9+
transition: --circle-color 1s;
10+
}
11+
12+
#example:focus {
13+
--circle-color: purple;
14+
}
15+
</style>
16+
17+
<textarea id="example">
18+
CSS is awesome.
19+
</textarea>
20+
21+
<script>
22+
CSS.registerProperty({
23+
name: '--circle-color',
24+
syntax: '<color>',
25+
initialValue: 'black',
26+
inherit: false
27+
});
28+
CSS.paintWorklet.import('circle.js');
29+
</script>
30+

0 commit comments

Comments
 (0)