-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cellular-noise-first-neighbor-distance: SketchFrgで書き換え
- Loading branch information
1 parent
e897e1d
commit 3e1c8ca
Showing
2 changed files
with
29 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 29 additions & 52 deletions
81
src/canvas/cellular-noise-first-neighbor-distance/render.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,63 +1,40 @@ | ||
import { Space } from "@/lib/canvas/index" | ||
import { Program } from "@/lib/webgl/program" | ||
import { Timer } from "@/lib/control/timer" | ||
import { Clock } from "@/lib/event/clock" | ||
import { UniformLoader } from "@/lib/webgl/uniform-loader" | ||
import { MouseCoords } from "@/lib/control/mouse-coords" | ||
|
||
import vert from "./index.vert?raw" | ||
import frag from "./index.frag?raw" | ||
|
||
export const onload = () => { | ||
const space = new Space("gl-canvas") | ||
const canvas = space.canvas | ||
const gl = space.gl | ||
if (!canvas || !gl) return | ||
|
||
let timer: Timer | ||
let clock: Clock | ||
let mouse: MouseCoords | ||
|
||
const uniforms = new UniformLoader(gl, ["uResolution", "uTime", "uMouse"]) | ||
|
||
const onResize = () => { | ||
space.fitScreen() | ||
render() | ||
} | ||
import { SketchFrg, type FragmentSketchConfig, type FragmentSketchFn } from "sketchgl" | ||
import { Uniforms } from "sketchgl/program" | ||
import { Timer } from "sketchgl/interactive" | ||
|
||
const configure = () => { | ||
space.fitScreen() | ||
|
||
gl.clearColor(0.0, 0.0, 0.0, 1.0) | ||
gl.clearDepth(1.0) | ||
|
||
const program = new Program(gl, vert, frag) | ||
import frag from "./index.frag?raw" | ||
|
||
clock = new Clock() | ||
timer = new Timer() | ||
mouse = new MouseCoords(canvas) | ||
const sketch: FragmentSketchFn = ({ gl, canvas, program, renderToCanvas }) => { | ||
const uniforms = new Uniforms(gl, ["uResolution", "uTime"]) | ||
uniforms.init(program) | ||
|
||
uniforms.init(program) | ||
const timer = new Timer() | ||
timer.start() | ||
|
||
timer.start() | ||
space.onResize = onResize | ||
} | ||
gl.clearColor(0.0, 0.0, 0.0, 1.0) | ||
gl.clearDepth(1.0) | ||
|
||
const render = () => { | ||
gl.viewport(0, 0, gl.canvas.width, gl.canvas.height) | ||
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) | ||
return { | ||
drawOnFrame() { | ||
gl.viewport(0, 0, gl.canvas.width, gl.canvas.height) | ||
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT) | ||
|
||
uniforms.float("uTime", timer.elapsed * 0.001) | ||
uniforms.fvector2("uResolution", [canvas.width, canvas.height]) | ||
uniforms.fvector2("uMouse", mouse.xy) | ||
uniforms.float("uTime", timer.elapsed * 0.001) | ||
uniforms.fvector2("uResolution", [canvas.width, canvas.height]) | ||
|
||
gl.drawArrays(gl.TRIANGLE_FAN, 0, 3) | ||
renderToCanvas() | ||
} | ||
} | ||
} | ||
|
||
const init = () => { | ||
configure() | ||
clock.on("tick", render) | ||
export const onload = () => { | ||
const config: FragmentSketchConfig = { | ||
frag, | ||
canvas: { | ||
el: "gl-canvas", | ||
fitScreen: true, | ||
autoResize: true | ||
} | ||
} | ||
|
||
init() | ||
SketchFrg.init(config, sketch) | ||
} |