“Wobbly Egg” by Dave Pagurek
https://openprocessing.org/sketch/1841149
License CreativeCommons Attribution NonCommercial ShareAlike
https://creativecommons.org/licenses/by-nc-sa/3.0
{{filePath}}
{{width}} x {{height}}
Report Sketch
Oh, that naughty sketch! Please let us know what the issue is below.
Apply Template
Applying this template will reset your sketch and remove all your changes. Are you sure you would like to continue?
Report Sketch
Report Comment
Please confirm that you would like to report the comment below.
We will review your submission and take any actions necessary per our Community Guidelines. In addition to reporting this comment, you can also block the user to prevent any future interactions.
Please report comments only when necessary. Unnecessary or abusive use of this tool may result in your own account being suspended.
Are you sure you want to delete your sketch?
Any files uploaded will be deleted as well.
Delete Comment?
This will also delete all the replies to this comment.
Delete this tab? Any code in it will be deleted as well.
Select a collection to submit your sketch
We Need Your Support
Since 2008, OpenProcessing has provided tools for creative coders to learn, create, and share over a million open source projects in a friendly environment.
Niche websites like ours need your continued support for future development and maintenance, while keeping it an ad-free platform that respects your data and privacy!
Please consider subscribing below to show your support with a "Plus" badge on your profile and get access to many other features!
Wiggle your mouse around. Watch the egg wiggle back.
CC Attribution NonCommercial ShareAlike
Wobbly Egg
Pagurek
xxxxxxxxxx
let displacement
let velocity
let eggWhite
let eggYolk
function preload() {
eggWhite = loadModel('egg-half.obj', () => {}, () => {})
eggYolk = loadModel('egg-devilled.obj', () => {}, () => {})
}
function setup() {
createCanvas(600, 600, WEBGL)
displacement = createVector(0, 0, 0)
velocity = createVector(0, 0, 0)
}
function draw() {
noStroke()
background('#edc385')
pointLight(100, 100, 100, width/2, -height/2, 100)
pointLight(50, 50, 50, width/3, -height/3, 200)
directionalLight(128, 128, 128, 1, 0, -1)
const dt = deltaTime/1000
if (dt > 0 && dt < 0.5) {
const dMouse = createVector(
mouseX - pmouseX,
mouseY - pmouseY,
).div(dt).mult(0.2)
const k_spring = 250
const c_damper = 5
const mass = 1
const f = displacement.copy().mult(-k_spring).add(
velocity.copy().mult(-c_damper)
).add(dMouse.copy().mult(10))
const accel = f.copy().div(mass)
velocity.add(accel.copy().mult(dt))
displacement.add(velocity.copy().mult(dt))
}
const tangentVec = displacement.magSq() < 1e-4
? createVector(1, 0, 0)
: displacement.copy().normalize()
const biTangentVec = createVector(0, 0, 1)
const normalVec = tangentVec.cross(biTangentVec)
const toTangentSpace = new DOMMatrixReadOnly([
tangentVec.x, tangentVec.y, tangentVec.z, 0,
normalVec.x, normalVec.y, normalVec.z, 0,
biTangentVec.x, biTangentVec.y, biTangentVec.z, 0,
0, 0, 0, 1,
])
const tangentMag = 1 + displacement.mag() * 0.0025
const scaleMatrix = new DOMMatrixReadOnly([
tangentMag, 0, 0, 0,
0, 1/tangentMag, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1,
])
const transform = new DOMMatrixReadOnly()
.multiply(toTangentSpace)
.multiply(scaleMatrix)
.multiply(toTangentSpace.inverse())
.translate(displacement.x, displacement.y, displacement.z)
push()
applyMatrix(...transform.toFloat32Array())
rotateZ(PI * 0.8)
rotateY(PI * 0.7)
rotateX(PI * -0.2)
scale(120)
push()
fill(255)
specularMaterial(255)
shininess(100)
ambientMaterial(255)
ambientLight('#948979')
model(eggWhite)
pop()
push()
ambientMaterial('#ede185')
specularMaterial(20)
shininess(1)
ambientLight('#9c8665')
model(eggYolk)
pop()
pop()
// sphere(20)
// push()
// translate(displacement.x, displacement.y, displacement.z)
// sphere(20)
// pop()
}
See More Shortcuts