Snow fullscreen effect implemented

This commit is contained in:
Mal
2024-12-08 16:53:56 +01:00
parent 4bf46d99fd
commit 4b85a314c4
13 changed files with 250 additions and 2 deletions

View File

@@ -0,0 +1,22 @@
export class FullscreenEffect
{
static NAME = '';
constructor(canvas)
{
this.canvas = canvas;
}
update(timestamp)
{
}
render(context)
{
}
getName()
{
return this.constructor.NAME;
}
}

View File

@@ -0,0 +1,27 @@
import {SnowEffect} from "./SnowEffect.js";
export class FullscreenEffectFactory
{
static EFFECTS = {
[SnowEffect.NAME]: SnowEffect,
}
getEffect(name)
{
return new FullscreenEffectFactory.EFFECTS[name]();
}
static getNames()
{
const names = [];
for (const name in FullscreenEffectFactory.EFFECTS) {
console.log(name);
names.push(name);
}
console.log(names);
return names;
}
}

31
js/effects/SnowEffect.js Normal file
View File

@@ -0,0 +1,31 @@
import {FullscreenEffect} from "./FullscreenEffect.js";
export class SnowEffect extends FullscreenEffect
{
static NAME = 'snow';
constructor()
{
super();
this.image = new Image();
this.image.src = '/js/effects/snow.png';
this.offset = 0;
}
update(timestamp)
{
super.update(timestamp);
this.offset = timestamp % 512;
}
render(context)
{
super.render(context);
for (let y = -1; y < Math.ceil(context.canvas.height / 512); y++) {
for (let x = -1; x < Math.ceil(context.canvas.width / 512); x++) {
context.drawImage(this.image, this.offset + 512 * x, this.offset + 512 * y);
}
}
}
}

BIN
js/effects/snow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB