@@ -4,12 +4,12 @@ import Layout from "../../layouts/Layout.astro";
4
4
---
5
5
6
6
<script >
7
- import { useWebGLCanvas, useLoop, pauseAllLoops, playAllLoops } from "usegl";
8
- import { incrementRenderCount } from "../../components/renderCount";
7
+ import { useWebGLCanvas, useLoop, pauseAllLoops, playAllLoops } from "usegl";
8
+ import { incrementRenderCount } from "../../components/renderCount";
9
9
10
- const { onAfterRender, uniforms } = useWebGLCanvas({
11
- canvas: "#glCanvas",
12
- fragment: /* glsl */ `
10
+ const { onAfterRender, uniforms } = useWebGLCanvas({
11
+ canvas: "#glCanvas",
12
+ fragment: /* glsl */ `
13
13
varying vec2 vUv;
14
14
uniform float uTime1;
15
15
uniform float uTime2;
@@ -45,114 +45,114 @@ import Layout from "../../layouts/Layout.astro";
45
45
gl_FragColor = vec4(col, 1.);
46
46
}
47
47
`,
48
- uniforms: {
49
- uTime1: 0,
50
- uTime2: 0,
51
- uTime3: 0,
52
- },
53
- });
54
-
55
- const { play: play1, pause: pause1 } = useLoop(
56
- ({ deltaTime }) => {
57
- uniforms.uTime1 += deltaTime;
58
- },
59
- { immediate: false }
60
- );
61
-
62
- const { play: play2, pause: pause2 } = useLoop(
63
- ({ time }) => {
64
- uniforms.uTime2 = time;
65
- },
66
- { immediate: false }
67
- );
68
-
69
- const { play: play3, pause: pause3 } = useLoop(
70
- ({ elapsedTime }) => {
71
- uniforms.uTime3 = elapsedTime;
72
- },
73
- { immediate: false }
74
- );
75
-
76
- bindControl(".controls.local button:nth-of-type(1)", play1, pause1);
77
- bindControl(".controls.local button:nth-of-type(2)", play2, pause2);
78
- bindControl(".controls.local button:nth-of-type(3)", play3, pause3);
79
-
80
- function playAll() {
81
- playAllLoops();
82
- document.querySelectorAll(".controls.local button").forEach((button) => {
83
- button.ariaChecked = "true";
84
- });
85
- }
86
- function pauseAll() {
87
- pauseAllLoops();
88
- document.querySelectorAll(".controls.local button").forEach((button) => {
89
- button.ariaChecked = "false";
90
- });
91
- }
92
-
93
- bindControl(".global button", playAll, pauseAll);
94
-
95
- function bindControl(selector, play: () => void, pause: () => void) {
96
- document.querySelector(selector).addEventListener("click", (event) => {
97
- if ((event.currentTarget as HTMLElement).ariaChecked === "true") {
98
- play();
99
- } else {
100
- pause();
101
- }
102
- });
103
- }
104
-
105
- onAfterRender(incrementRenderCount);
48
+ uniforms: {
49
+ uTime1: 0,
50
+ uTime2: 0,
51
+ uTime3: 0,
52
+ },
53
+ });
54
+
55
+ const { play: play1, pause: pause1 } = useLoop(
56
+ ({ deltaTime }) => {
57
+ uniforms.uTime1 += deltaTime;
58
+ },
59
+ { immediate: false }
60
+ );
61
+
62
+ const { play: play2, pause: pause2 } = useLoop(
63
+ ({ time }) => {
64
+ uniforms.uTime2 = time;
65
+ },
66
+ { immediate: false }
67
+ );
68
+
69
+ const { play: play3, pause: pause3 } = useLoop(
70
+ ({ elapsedTime }) => {
71
+ uniforms.uTime3 = elapsedTime;
72
+ },
73
+ { immediate: false }
74
+ );
75
+
76
+ bindControl(".controls.local button:nth-of-type(1)", play1, pause1);
77
+ bindControl(".controls.local button:nth-of-type(2)", play2, pause2);
78
+ bindControl(".controls.local button:nth-of-type(3)", play3, pause3);
79
+
80
+ function playAll() {
81
+ playAllLoops();
82
+ document.querySelectorAll(".controls.local button").forEach((button) => {
83
+ button.ariaChecked = "true";
84
+ });
85
+ }
86
+ function pauseAll() {
87
+ pauseAllLoops();
88
+ document.querySelectorAll(".controls.local button").forEach((button) => {
89
+ button.ariaChecked = "false";
90
+ });
91
+ }
92
+
93
+ bindControl(".global button", playAll, pauseAll);
94
+
95
+ function bindControl(selector: string , play: () => void, pause: () => void) {
96
+ document.querySelector(selector)! .addEventListener("click", (event) => {
97
+ if ((event.currentTarget as HTMLElement).ariaChecked === "true") {
98
+ play();
99
+ } else {
100
+ pause();
101
+ }
102
+ });
103
+ }
104
+
105
+ onAfterRender(incrementRenderCount);
106
106
</script >
107
107
108
108
<Layout title =" Play/Pause" >
109
- <div class =" container" >
110
- <div class =" controls global" >
111
- Global : <PlayPause />
112
- </div >
113
- <div class =" controls local" >
114
- <PlayPause />
115
- <PlayPause />
116
- <PlayPause />
117
- </div >
118
- <canvas id =" glCanvas" ></canvas >
119
- </div >
109
+ <div class =" container" >
110
+ <div class =" controls global" >
111
+ Global : <PlayPause />
112
+ </div >
113
+ <div class =" controls local" >
114
+ <PlayPause />
115
+ <PlayPause />
116
+ <PlayPause />
117
+ </div >
118
+ <canvas id =" glCanvas" ></canvas >
119
+ </div >
120
120
</Layout >
121
121
122
122
<style is:global >
123
- .container {
124
- width: 100%;
125
- display: flex;
126
- flex-direction: column;
127
- align-items: center;
128
- justify-content: center;
129
- text-align: center;
130
- font-size: min(1em, 2svmin);
131
- gap: 2em;
132
- }
133
-
134
- .controls {
135
- display: flex;
136
- width: min(80%, 700px);
137
- max-width: 90svmin;
138
- justify-content: space-around;
139
- align-items: center;
140
- }
141
-
142
- .controls.local button {
143
- font-size: 0.8em;
144
- }
145
-
146
- .controls.global {
147
- justify-content: center;
148
- font-size: 1.5em;
149
- }
150
-
151
- .controls button {
152
- position: static;
153
- }
154
-
155
- canvas {
156
- aspect-ratio: 3/2;
157
- }
123
+ .container {
124
+ width: 100%;
125
+ display: flex;
126
+ flex-direction: column;
127
+ align-items: center;
128
+ justify-content: center;
129
+ text-align: center;
130
+ font-size: min(1em, 2svmin);
131
+ gap: 2em;
132
+ }
133
+
134
+ .controls {
135
+ display: flex;
136
+ width: min(80%, 700px);
137
+ max-width: 90svmin;
138
+ justify-content: space-around;
139
+ align-items: center;
140
+ }
141
+
142
+ .controls.local button {
143
+ font-size: 0.8em;
144
+ }
145
+
146
+ .controls.global {
147
+ justify-content: center;
148
+ font-size: 1.5em;
149
+ }
150
+
151
+ .controls button {
152
+ position: static;
153
+ }
154
+
155
+ canvas {
156
+ aspect-ratio: 3/2;
157
+ }
158
158
</style >
0 commit comments