Add insights

This commit is contained in:
schmelczerandras 2020-10-20 23:09:53 +02:00
commit b445961ad5
5 changed files with 94 additions and 1 deletions

View file

@ -10,6 +10,7 @@ const Circle = CircleFactory(rgb255(119, 143, 120));
export class BlobScene implements Scene {
private canvas: HTMLCanvasElement;
private overlay: HTMLDivElement;
public renderer?: Renderer;
public async run(canvas: HTMLCanvasElement, overlay: HTMLDivElement): Promise<void> {
this.canvas = canvas;
@ -52,6 +53,8 @@ export class BlobScene implements Scene {
currentTime: DOMHighResTimeStamp,
deltaTime: DOMHighResTimeStamp
): boolean {
this.renderer = renderer;
const { width, height } = this.canvas.getBoundingClientRect();
renderer.setViewArea([0, height], [width, height]);

View file

@ -11,6 +11,7 @@ export class MetaballScene implements Scene {
private canvas: HTMLCanvasElement;
private overlay: HTMLDivElement;
public renderer?: Renderer;
public async run(canvas: HTMLCanvasElement, overlay: HTMLDivElement): Promise<void> {
this.canvas = canvas;
@ -57,6 +58,8 @@ export class MetaballScene implements Scene {
currentTime: DOMHighResTimeStamp,
deltaTime: DOMHighResTimeStamp
): boolean {
this.renderer = renderer;
const { width, height } = this.canvas.getBoundingClientRect();
const viewAreaWidth = width / Math.max(width, height);
const viewAreaHeight = height / Math.max(width, height);

View file

@ -12,6 +12,7 @@ export class RainScene implements Scene {
private canvas: HTMLCanvasElement;
private overlay: HTMLDivElement;
public renderer?: Renderer;
public async run(canvas: HTMLCanvasElement, overlay: HTMLDivElement): Promise<void> {
this.canvas = canvas;
@ -46,6 +47,8 @@ export class RainScene implements Scene {
currentTime: DOMHighResTimeStamp,
deltaTime: DOMHighResTimeStamp
): boolean {
this.renderer = renderer;
const { width, height } = this.canvas.getBoundingClientRect();
renderer.setViewArea(vec2.fromValues(0, height), vec2.fromValues(width, height));
this.overlay.innerText = prettyPrint(renderer.insights);

View file

@ -1,3 +1,6 @@
import { Renderer } from 'sdf-2d';
export interface Scene {
run(canvas: HTMLCanvasElement, overlay: HTMLDivElement): Promise<void>;
readonly renderer?: Renderer;
}

View file

@ -24,6 +24,7 @@ export class TunnelScene implements Scene {
private tunnels: Array<InstanceType<typeof InvertedTunnel>> = [];
private lights: Array<CircleLight> = [];
public renderer?: Renderer;
private generateTunnel() {
const canvasSize = this.canvas.getBoundingClientRect();
@ -116,6 +117,8 @@ export class TunnelScene implements Scene {
currentTime: DOMHighResTimeStamp,
deltaTime: DOMHighResTimeStamp
): boolean {
this.renderer = renderer;
const { width, height } = this.canvas.getBoundingClientRect();
this.deltaSinceStart += deltaTime;
const startX = this.deltaSinceStart / 3;