renderer = createCanvas(windowWidth, windowHeight, WEBGL)
const vert = `attribute vec3 aPosition;
attribute vec2 aTexCoord;
uniform mat4 uModelViewMatrix;
uniform mat4 uProjectionMatrix;
uniform mat3 uNormalMatrix;
varying vec3 vVertexNormal;
varying highp vec2 vVertTexCoord;
vec4 positionVec4 = vec4(aPosition, 1.0);
gl_Position = uProjectionMatrix * uModelViewMatrix * positionVec4;
vVertexNormal = normalize(vec3( uNormalMatrix * aNormal ));
vVertTexCoord = aTexCoord;
const frag = `precision mediump float;
varying vec3 vVertexNormal;
vec3 col1 = vec3(1., .56, .69);
vec3 col2 = vec3(.2, .9, .9);
vec3 col3 = vec3(0., 0., 0.);
vec3 col = mix(col1, col2, vVertexNormal.x);
col = mix(col, col3, vVertexNormal.y);
gl_FragColor = vec4(col, 1.0);
shading = new p5.Shader(renderer, vert, frag)
let shape = floor(random(3))
points = [[-1, -1], [1, -1], [1, 1], [-1, 1]]
let total = floor(random(5, 20))
total = total%2==0?total:total+1
for(let i=0; i<total; i++){
let radius = i%2==0 ? 1 : 0.5
let x = cos(i/total*TWO_PI)*radius
let y = sin(i/total*TWO_PI)*radius
geometries.push(new p5.Geometry(0, 0, function() {
points.forEach(p => this.vertices.push(new p5.Vector(p[0], p[1], top)))
points.forEach(p => this.vertices.push(new p5.Vector(p[0], p[1], bottom)))
this.vertices.forEach(vertex => {
this.vertexNormals.push(vertex.copy())
this.uvs.push([vertex.x, vertex.y])
for (var i = 0; i < n; i++) {
this.faces.push([i + n, n, i])
this.faces.push([0, i, n])
this.faces.push([i + n, i + n + 1, i])
this.faces.push([i + 1, i, i + n + 1])
let geometry = geometries[geometries.length - 1]
geometry._makeTriangleEdges()
geometry._edgesToVertices()
geometry.x = floor(random(width/(size*2))) * (width/floor(width/(size*2)));
geometry.y = floor(random(height/(size*2))) * (height/floor(height/(size*2)));
renderer.createBuffers(geometry.id, geometry)
geometries = geometries.filter(geometry => (time-geometry.time)/duration < 1)
translate(-width/2, -height/2)
geometries.forEach((geometry, index) => {
let percent = (time-geometry.time)/duration
let easy = easeInOutQuint(percent)
let s = (1-pow(easy*2-1, 2))*length/2
translate(geometry.x, geometry.y, -z)
renderer.drawBuffersScaled(geometry.id, size, size, s)
function easeInOutQuint(t) {
return t<.5 ? 16*t*t*t*t*t : 1+16*(--t)*t*t*t*t