Skip to content

Commit a951343

Browse files
author
Dylan McGannon
committed
Added extreme mode.
Use "requestAnimationFrame()" to shcedule the next tick.
1 parent 385f4be commit a951343

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

js/gl.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export class GL {
2828
this.zoom_speed = 0;
2929
this.zoom_level = 1;
3030
this.color_cycle = 0;
31+
this.extreme_mode = false;
3132

3233
this.drag_active = false;
3334
this.drag_point = new Vector(0, 0, 0, 1);
@@ -37,6 +38,14 @@ export class GL {
3738
this.resize();
3839
});
3940

41+
// Add keyboard event listener
42+
window.addEventListener('keypress', (event) => {
43+
if (event.key === 'x') {
44+
this.extreme_mode = !this.extreme_mode;
45+
event.preventDefault();
46+
}
47+
});
48+
4049
// Add click listeners
4150
canvas.addEventListener('mousedown', (event) => {
4251
this.drag_active = true;
@@ -369,7 +378,11 @@ export class GL {
369378
* @param {integer} frame_delta
370379
*/
371380
cycle(frame_delta) {
372-
this.color_cycle = (this.color_cycle + frame_delta / 200) % 1024.0;
381+
let speed = 200;
382+
if (this.extreme_mode) {
383+
speed = 10;
384+
}
385+
this.color_cycle = (this.color_cycle + frame_delta / speed) % 1024.0;
373386

374387
this.get_shader_program().set_uniform_float(
375388
'continuous_cycle',
@@ -403,6 +416,6 @@ export class GL {
403416
}
404417

405418
// Schedule another tick
406-
window.setTimeout(() => this.event_loop(), (1000 / 60) - (Date.now() - frame_time));
419+
requestAnimationFrame(() => this.event_loop());
407420
}
408421
}

0 commit comments

Comments
 (0)