Skip to content

Instantly share code, notes, and snippets.

View sketchpunk's full-sized avatar
🏠
Working from home

SketchPunk sketchpunk

🏠
Working from home
View GitHub Profile
audioContainer: {
height: '30px',
overflow: 'hidden',
backgroundColor: '#26476F',
boxShadow: '0px 0px 5px 2px rgba( 0,0,0,0.55 )',
borderRadius: '4px',
color: '#ffffff',
},
audio: {
/**
* \brief Returns positional offset for a given point as a result of summing 4 gerstner waves
* \param positionWS point in world space
* \param wavelengths wavelength of each of the 4 waves
* \param amplitudes amplitudes of each of the 4 waves
* \param directions direction of each of the 4 waves (each row = one direction). MUST BE NORMALIZED!
* \param speed global speed multiplier. Individual wave speed depends on Wavelength
* \param steepness Gerstner wave 'Steepness' parameter. Modulates the horizontal offset of points
* \param normal returns the normal of given point.
* \return positional offset of the given point
@sketchpunk
sketchpunk / color_ramp.txt
Last active February 1, 2024 23:10
WebGL : Blender 4.0 GLSL Nodes
// #region CUSTOM - NON-BLENDER CODE
/*
USAGE
vec3 ramp_col[9] = vec3[](
rgb(0x0F2936),
rgb(0x123243),
rgb(0x24525D),
rgb(0x437274),
rgb(0x263F41),
@sketchpunk
sketchpunk / pipeGenerator.cs
Created September 27, 2023 12:05 — forked from antonkudin/pipeGenerator.cs
Generates pipe mesh from mesh segments
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class pipeGenerator : MonoBehaviour
{
[SerializeField] Mesh straightMesh;
[SerializeField] Mesh elbowMesh;
[Space]
[SerializeField] Vector3[] pathPoints;
@sketchpunk
sketchpunk / BinaryTree_Heap.js
Created April 1, 2023 16:45
Min and Max Heap
/*
const heap = new BinaryHeap( IsMinCompare );
heap.add( 5 );
heap.add( 8 );
heap.add( 6 );
heap.add( 9 );
heap.add( 13 );
heap.add( 3 );
heap.add( 1 );
@sketchpunk
sketchpunk / arcball.js
Last active July 22, 2023 06:24
Maths for various camera movement ( Orbit, Arcball, FPS, Zoom, etc )
/** Using a faux sphere in screen space, determine the arc transform to orbit
* the camera around a target position. A continuous orientation will
* be provided for further calls.
*/
function arcBallTransform(
scrSize, // Screen size, vec2
scrPos0, // Starting mouse position, vec2
scrPos1, // Ending Mouse Positiong, vec2
rotOrientation, // Current arc orientation, quaternion
targetPos, // Position to orbit around
@sketchpunk
sketchpunk / eulerRotation.c
Last active March 16, 2023 03:24
Apply Euler Rotation on position & normals in GLSL
/*
vec3 rot = vec3( 90.0, 90.0, 0.0 );
vec3 pos = position * scale;
vec3 norm = normal;
eulerRotation( rot * DEG2RAD, pos, norm );
*/
const float DEG2RAD = 0.01745329251; // PI / 180
// Apply YXZ radian rotation
@sketchpunk
sketchpunk / Vec3.js
Last active February 11, 2023 02:47
Vector 3 Allocator with Mutable Slices
class Vec3 extends Float32Array{
constructor( arg0=null, arg1=null, arg2=null ){
// Slice of an existing Array Buffer
if( arg0 instanceof ArrayBuffer && typeof arg1 === 'number' ){
super( arg0, arg1 * 3 * 4, 3 );
}else{
super( 3 );
// First Argument is a vector3 like
if( ( Array.isArray( arg0 ) || arg0 instanceof Float32Array ) && arg0.length === 3 ){
@sketchpunk
sketchpunk / create_array.txt
Last active December 19, 2022 23:05
create array without an array
const num=2;
console.log( Array.from( {length:5}, (_,i,v=i+num )=>{
console.log( i, v );
return v;
} ));
@sketchpunk
sketchpunk / _roundedline.js
Last active January 4, 2023 15:18
Round the edges of a multi part line or 2d polygon in a flat array of vec3
/*
const pnts = [
-2,0,-2,
-2,0,2,
2,0,2,
4,0,1,
];
const poly = roundedline( pnts );
const buf = new Vec3Buffer( poly );