Skip to content

Instantly share code, notes, and snippets.

View robksawyer's full-sized avatar
🎯
Focusing

Rob Sawyer robksawyer

🎯
Focusing
View GitHub Profile
function initDebug() {(
_debug = new Mesh(
new BoxGeometry(.25, .25, .5, 1, 1, 5),
new Shader("DebugCamera", {
uColor: {
value: new Color,
transparent: !0,
depthTest: !1
}
})
class Curve3D {
constructor() {
this.arcLengthDivisions = 200
}
getPointAt(u) {
let t = this.getUtoTmapping(u);
return this.getPoint(t)
}
getPoints(divisions = 5) {
let points = [];
function initScene() {
_triangleGeometry = World.QUAD, _luminosityShader = _this.initClass(Shader, "UnrealBloomLuminosity", {
tDiffuse: {
value: null,
ignoreUIL: !0
},
luminosityThreshold: {
value: 1
},
smoothWidth: {
@robksawyer
robksawyer / normalizing.js
Created September 14, 2020 02:45
Normalizing trigonometry functions.
// normalizing trigonometry functions (t is between 0 -1):
const t = (1 + Math.sin(clock.getElapsedTime())) / 2
// to alter speed
Math.sin(clock.getElapsedTime() / 2) // 2 times slower
Math.sin(clock.getElapsedTime() * 2) // 2 times faster
@robksawyer
robksawyer / useExtractPathsFromSvg
Created August 26, 2020 00:16
This handy hook extracts the paths from an SVG string.
/**
* extractPathsFromSvg
* Handles extracting paths from an svg string
* @param {string} svg
*/
const extractPathsFromSvg = (svg) => {
const pathSegmentPattern = /d="([a-z][^a-z]*)[^"]/gi
return svg.match(pathSegmentPattern).map((str) => str.replace('d="', ''))
}
@robksawyer
robksawyer / organicMovement.js
Created August 24, 2020 01:09
React Three Fiber organic movement snippet
// main sphere rotates following the mouse position
useFrame(({ clock, mouse }) => {
main.current.rotation.z = clock.getElapsedTime();
main.current.rotation.y = THREE.MathUtils.lerp(
main.current.rotation.y,
mouse.x * Math.PI,
0.1
);
main.current.rotation.x = THREE.MathUtils.lerp(
main.current.rotation.x,
export default function Stars({ count = 5000 }) {
const positions = useMemo(() => {
let positions = []
for (let i = 0; i < count; i++) {
const r = 4000
const theta = 2 * Math.PI * Math.random()
const phi = Math.acos(2 * Math.random() - 1)
const x = r * Math.cos(theta) * Math.sin(phi) + (-2000 + Math.random() * 4000)
const y = r * Math.sin(theta) * Math.sin(phi) + (-2000 + Math.random() * 4000)
const z = r * Math.cos(phi) + (-1000 + Math.random() * 2000)
function Cube() {
const cam = useRef()
const [scene, target] = useMemo(() => {
const scene = new THREE.Scene()
scene.background = new THREE.Color('orange')
const target = new THREE.WebGLRenderTarget(1024, 1024)
return [scene, target]
}, [])
useFrame(state => {
function Swarm({ count, mouse }) {
const mesh = useRef()
const light = useRef()
const { size, viewport } = useThree()
const aspect = size.width / viewport.width
const dummy = useMemo(() => new THREE.Object3D(), [])
// Generate some random positions, speed factors and timings
const particles = useMemo(() => {
const temp = []
<div className={styles.rain}>
<div className={styles.drop}></div>
<div className={styles.waves}>
<div></div>
<div></div>
</div>
<div className={styles.particles}>
<div></div>
<div></div>
<div></div>