templates: Fix music visualizer aspect ratio #18
4
templates/.dir-locals.el
Normal file
4
templates/.dir-locals.el
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
((nil . ((indent-tabs-mode . nil)
|
||||||
|
(tab-width . 4)
|
||||||
|
(fill-column . 80)
|
||||||
|
(projectile-project-run-cmd . "cd templates && parcel serve --no-autoinstall"))))
|
|
@ -84,8 +84,16 @@ class Renderer {
|
||||||
this.canvas.parentElement.getBoundingClientRect());
|
this.canvas.parentElement.getBoundingClientRect());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.canvas.width = width;
|
// Preserve the aspect ratio
|
||||||
this.canvas.height = height;
|
const aspect_ratio = (this.analyser.frequencyBinCount * 2) / 512;
|
||||||
|
const target_height = width / aspect_ratio;
|
||||||
|
if (target_height > height) {
|
||||||
|
this.canvas.width = aspect_ratio * height;
|
||||||
|
this.canvas.height = height;
|
||||||
|
} else {
|
||||||
|
this.canvas.width = width;
|
||||||
|
this.canvas.height = width / aspect_ratio;
|
||||||
|
}
|
||||||
|
|
||||||
gl.viewport(0, 0, this.canvas.clientWidth, this.canvas.clientHeight);
|
gl.viewport(0, 0, this.canvas.clientWidth, this.canvas.clientHeight);
|
||||||
this.updateProjection(gl, shader);
|
this.updateProjection(gl, shader);
|
||||||
|
@ -230,12 +238,8 @@ class Renderer {
|
||||||
this.rotation += (this.dTime / 1000.0) * ROTATION_SPEED;
|
this.rotation += (this.dTime / 1000.0) * ROTATION_SPEED;
|
||||||
|
|
||||||
const modelViewMatrix = mat4.create();
|
const modelViewMatrix = mat4.create();
|
||||||
mat4.translate(modelViewMatrix, modelViewMatrix, [
|
mat4.translate(modelViewMatrix, modelViewMatrix, [0.0, 0.0, -0.8]);
|
||||||
0.0,
|
mat4.rotateX(modelViewMatrix, modelViewMatrix, Math.PI / 32);
|
||||||
0.025,
|
|
||||||
-((this.analyser.frequencyBinCount / gl.canvas.clientWidth) * 3),
|
|
||||||
]);
|
|
||||||
mat4.rotateX(modelViewMatrix, modelViewMatrix, Math.PI / 16);
|
|
||||||
mat4.rotateY(modelViewMatrix, modelViewMatrix, this.rotation);
|
mat4.rotateY(modelViewMatrix, modelViewMatrix, this.rotation);
|
||||||
mat4.translate(modelViewMatrix, modelViewMatrix, [-1.0, 0.0, 0.0]);
|
mat4.translate(modelViewMatrix, modelViewMatrix, [-1.0, 0.0, 0.0]);
|
||||||
gl.uniformMatrix4fv(
|
gl.uniformMatrix4fv(
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import React, { useCallback, useState } from "react";
|
import React, { useCallback, useState } from "react";
|
||||||
import { Renderer, RendererError } from "./Renderer";
|
import { Renderer, RendererError } from "./Renderer";
|
||||||
import { ShaderError } from "./Shader";
|
import { ShaderError } from "./Shader";
|
||||||
|
import classNames from "classnames";
|
||||||
|
|
||||||
import { useAppSelector } from "../../hooks";
|
import { useAppSelector } from "../../hooks";
|
||||||
import { PlayState, musicPlayer } from "../musicplayer/musicPlayerSlice";
|
import { PlayState, musicPlayer } from "../musicplayer/musicPlayerSlice";
|
||||||
|
@ -125,7 +126,14 @@ function Visualizer() {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={visualizer}
|
ref={visualizer}
|
||||||
className="is-flex-grow-1 is-clipped is-relative"
|
className={classNames({
|
||||||
|
"is-flex-grow-1": true,
|
||||||
|
"is-clipped": true,
|
||||||
|
"is-relative": true,
|
||||||
|
"is-flex": true,
|
||||||
|
"is-align-items-center": true,
|
||||||
|
"is-justify-content-center": true,
|
||||||
|
})}
|
||||||
>
|
>
|
||||||
<canvas className="is-block is-absolute is-border-box"></canvas>
|
<canvas className="is-block is-absolute is-border-box"></canvas>
|
||||||
<span className="is-bottom-left"></span>
|
<span className="is-bottom-left"></span>
|
||||||
|
|
Loading…
Reference in a new issue