Improve demos

This commit is contained in:
Andras Schmelczer 2026-06-11 08:26:26 +01:00
parent 414149293a
commit 491d5817c2
6 changed files with 319 additions and 22 deletions

View file

@ -6,34 +6,41 @@ export const Droplet = DropletFactory(rgb255(122, 122, 255));
export class DropletWrapper {
public readonly drawable: InstanceType<typeof Droplet>;
private speed = Random.getRandom() * 0.2 + 0.2;
private speed = Random.getRandom() * 0.45 + 0.45;
private position = vec2.fromValues(
Random.getRandomInRange(0.1, 0.9),
Random.getRandom()
);
private length = Random.getRandom() * 20 + 4;
private length = Random.getRandom() * 14 + 8;
constructor() {
const size = Random.getRandom() * 2 + 2;
const size = Random.getRandom() * 1.2 + 1;
this.drawable = new Droplet(
vec2.create(),
vec2.create(),
size + Random.getRandom() * 2 + 2,
size + Random.getRandom() + 1,
size
);
}
public animate(currentTime: number, viewAreaSize: ReadonlyVec2) {
public animate(currentTime: number, viewAreaSize: ReadonlyVec2, windSlant: number) {
const heightOffset = 100;
const fall = this.speed * currentTime;
vec2.set(
this.drawable.from,
this.position.x * viewAreaSize.x,
(this.position.x * viewAreaSize.x + fall * windSlant) % viewAreaSize.x,
viewAreaSize.y -
((this.position.y * viewAreaSize.y + this.speed * currentTime) %
(viewAreaSize.y + heightOffset))
((this.position.y * viewAreaSize.y + fall) % (viewAreaSize.y + heightOffset))
);
vec2.add(this.drawable.to, this.drawable.from, vec2.fromValues(0, this.length));
// the tail points opposite to the direction of motion
const norm = this.length / Math.sqrt(1 + windSlant * windSlant);
vec2.add(
this.drawable.to,
this.drawable.from,
vec2.fromValues(-windSlant * norm, norm)
);
}
}