-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: brownian distribution geometries on background
- Loading branch information
1 parent
40ff091
commit d220a6b
Showing
5 changed files
with
89 additions
and
14 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
71 changes: 71 additions & 0 deletions
71
components/content/brownian-distribution/BrownianDistributionGroup.vue
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 |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<script setup lang="ts"> | ||
import { MathUtils, Vector3, Euler } from 'three' | ||
import { colors } from './constants' | ||
import { BoxGeometry, CylinderGeometry, SphereGeometry, MeshToonMaterial } from 'three' | ||
const { lerp } = MathUtils | ||
const COUNT = 2000 | ||
const brownian = (stepSize: number, xMin: number, xMax: number, yMin: number, yMax: number, zMin: number, zMax: number) => { | ||
let x = 0; let y = 0; let z = 0 | ||
const r = () => (Math.random() - 0.5) * 2 * stepSize | ||
const isInBounds = () => xMin < x && x < xMax && yMin < y && y < yMax && zMin < z && z < zMax | ||
const reset = () => { | ||
x = lerp(xMin, xMax, Math.random()) | ||
y = lerp(yMin, yMax, Math.random()) | ||
z = lerp(zMin, zMax, Math.random()) | ||
} | ||
reset() | ||
return () => { | ||
x += r() | ||
y += r() | ||
z += r() | ||
if (!isInBounds()) { reset() } | ||
return [x, y, z] | ||
} | ||
} | ||
const sphereGeometry = new SphereGeometry() | ||
const cubeGeometry = new BoxGeometry() | ||
const pyramidGeometry = new CylinderGeometry(0, 0.6, 1) | ||
const mainMaterial = new MeshToonMaterial({ | ||
color: colors.DARK, | ||
}) | ||
const hoverMaterial = new MeshToonMaterial({ | ||
color: colors.YELLOW, | ||
}) | ||
const getPosition = brownian(2, -60, 60, -40, 40, -30, 0) | ||
const getRotation = brownian(1, -20, 20, -10, 10, -20, 0) | ||
const objectPositions = Array.from({ length: COUNT }).map(() => new Vector3(...getPosition())) | ||
const objectRotations = Array.from({ length: COUNT }).map(() => new Euler(...getRotation())) | ||
function onPointerEnter(ev: ThreeEvent<PointerEvent>) { | ||
if (ev.eventObject.material !== hoverMaterial) { | ||
ev.eventObject.userData.material = ev.eventObject.material | ||
} | ||
ev.eventObject.material = hoverMaterial | ||
} | ||
function onPointerLeave(ev: ThreeEvent<PointerEvent>) { | ||
ev.eventObject.material = ev.eventObject.userData.material ?? mainMaterial | ||
} | ||
</script> | ||
|
||
<template> | ||
<TresGroup :position="[0, 0, -30]"> | ||
<TresGroup :position="[0, 0, -30]"> | ||
<TresMesh | ||
v-for="position, i of objectPositions" | ||
:key="i" | ||
:geometry="[sphereGeometry, cubeGeometry, pyramidGeometry][i % 3]" | ||
:material="mainMaterial" | ||
:position="position" | ||
:rotation="objectRotations[i]" | ||
@pointer-enter="onPointerEnter" | ||
@pointer-leave="onPointerLeave" | ||
/> | ||
</TresGroup> | ||
</TresGroup> | ||
</template> |
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
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
|
||
export const colors = { | ||
TEAL: '#7fdac6', | ||
ORANGE: '#eeac35', | ||
PURPLE: '#9b51e0', | ||
YELLOW: '#f7d060', | ||
BLUE: '#00b4d8', | ||
RED: '#ef476f', | ||
DARK: '#1e1f22', | ||
LIGHT: '#f8f8f8', | ||
} | ||
|
||
export const PI = Math.PI |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.