Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                let font;
const points = {};
const shapes = {};
const params = {
  offY: 0,
  shoulder_l: Math.PI/2,
  shoulder_r: Math.PI/2,
  elbow_l: -Math.PI/4,
  elbow_r: -Math.PI/4,
  leg_l: Math.PI/2,
  leg_r: Math.PI/2,
  knee_l: 0,
  knee_r: 0
};
const FLOOR = 190;

const windAt = objPt => {
  const t = millis()/1000;
  const pt = objPt.copy().mult(100).add(createVector(1, 0.1, 1).mult(t));
  return createVector(
      noise(pt.x, pt.y, pt.z)-0.5,
      noise(pt.x, pt.y, pt.z)-0.5,
      noise(pt.x, pt.y, pt.z)-0.5).mult(900);
};

const objs = [];
//const chars = '!@#$%^&*()_+{}[]|;:<>/?'.split('');
const chars = "abcdefghijklmnopqrstuvwxyz".split('');

function preload() {
  font = loadFont('https://cdn.jsdelivr.net/npm/@typopro/dtp-e-b-garamond@3.7.5/TypoPRO-EBGaramond-Regular.ttf');
}

function setup() {
  createCanvas(600, 600, WEBGL);
  textFont(font);
  textSize(width / 30);
  textAlign(CENTER, CENTER);
  
  points.head = () => createVector(0, -40+params.offY, 10);
  points.neck = () => createVector(0, params.offY, 10);
  points.waist = () => createVector(0, 60+params.offY, 0);
  [-1, 1].forEach(side => {
    const suffix = side === 1 ? 'r' : 'l';
    const shoulder_key = 'shoulder_'+suffix;
    const elbow_key = 'elbow_'+suffix;
    const leg_key = 'leg_'+suffix;
    const knee_key = 'knee_'+suffix;
    
    points['shoulder_' + suffix] = 
      () => createVector(side*30, params.offY, 10);
    points['elbow_' + suffix] =
      () => createVector(side*36, sin(params[shoulder_key])*40+params.offY, cos(params[shoulder_key])*40+10);
    points['hand_' + suffix] =
      () => {
        const parent = points['elbow_'+suffix]();
        const angle = params[shoulder_key]+params[elbow_key];
        return parent.add(createVector(
          0,
          sin(angle)*40,
          cos(angle)*40));
      };
    
    points['leg_' + suffix] =
      () => createVector(side*15, 70+params.offY, 0);
    points['knee_' + suffix] =
      () => {
        const parent = points['leg_'+suffix]();
        const angle = params[leg_key];
        return parent.add(createVector(
          0,
          sin(angle)*50,
          cos(angle)*50));
      };
    points['heel_' + suffix] =
      () => {
        const parent = points['knee_'+suffix]();
        const angle = params[leg_key]+params[knee_key];
        return parent.add(createVector(
          0,
          sin(angle)*50,
          cos(angle)*50));
      };
    points['toe_' + suffix] =
      () => {
        const parent = points['heel_'+suffix]();
        const angle = params[leg_key]+params[knee_key]-PI*0.5;
        return parent.add(createVector(
          0,
          sin(angle)*25,
          cos(angle)*25));
      };
  });
  
  shapes.head = {
    from: points.head,
    to: points.head,
    r: 12
  };
  shapes.neck = {
    from: points.head,
    to: points.neck,
    r: 5
  };
  shapes.mid = {
    from: points.neck,
    to: points.waist,
    r: 10
  };
  [-1, 1].forEach(side => {
    const suffix = side === 1 ? 'r' : 'l';
    shapes['collar_'+suffix] = {
      from: points.neck,
      to: points['shoulder_'+suffix],
      r: 8
    };
    shapes['upperarm_'+suffix] = {
      from: points['shoulder_'+suffix],
      to: points['elbow_'+suffix],
      r: 5
    };
    shapes['lowerarm_'+suffix] = {
      from: points['elbow_'+suffix],
      to: points['hand_'+suffix],
      r: 5
    };
    shapes['waist_'+suffix] = {
      from: points.waist,
      to: points['leg_'+suffix],
      r: 5
    };
    shapes['thigh_'+suffix] = {
      from: points['leg_'+suffix],
      to: points['knee_'+suffix],
      r: 7
    };
    shapes['calf_'+suffix] = {
      from: points['knee_'+suffix],
      to: points['heel_'+suffix],
      r: 5
    };
    shapes['foot_'+suffix] = {
      from: points['heel_'+suffix],
      to: points['toe_'+suffix],
      r: 5
    };
  });
  
  let totalVol = 0;
  for (let s in shapes) {
    const {from, to, r} = shapes[s];
    const len = from().sub(to()).mag();
    const vol = 4/3*PI*r*r*r + len*PI*r*r;
    shapes[s].vol = vol;
    shapes[s].minSample = totalVol;
    totalVol += vol;
    shapes[s].maxSample = totalVol;
  }
  
  for (let i = 0; i < 200; i++) {
    const sample = random(totalVol);
    const shape = Object.values(shapes)
      .find(s => s.minSample <= sample && s.maxSample > sample);
    const sigma = shape.r / 2;
    const alpha = random();
    const offset = createVector(
      randomGaussian(0, sigma),
      randomGaussian(0, sigma),
      randomGaussian(0, sigma));
    const getPt = () => shape.from().mult(alpha)
        .add(shape.to().mult(1-alpha))
        .add(offset);
    
    const obj = {
      loc: getPt(),
      vel: createVector(0, 0, 0),
      mass: random(1, 5),
      k_spring: random(90, 100),
      c_damper: 5,
      target: getPt,
      letter: random(chars)
    };
    obj.update = (dt) => {
      const gravity = createVector(0, 10, 0).mult(obj.mass);
      const spring = getPt().sub(obj.loc).mult(obj.k_spring);
      const damper = obj.vel.copy().mult(-obj.c_damper);
      const wind = windAt(obj.loc);
      const normal = createVector(0, 0, 0);
      const accel = spring.copy()
        .add(gravity)
        .add(damper)
        .add(wind)
        .add(normal)
        .mult(1/obj.mass);
      obj.vel.add(accel.mult(dt));
      if (obj.loc.y + obj.mass + obj.vel.y >= FLOOR) {
        obj.vel.y = FLOOR - obj.loc.y - obj.mass;
      }
      obj.loc.add(obj.vel.copy().mult(dt));
    };
    objs.push(obj);
  }
}

function draw() {
  const t = millis()/400;
  params.shoulder_l = PI/2 + PI*0.2*sin(t);
  params.shoulder_r = PI/2 - PI*0.2*sin(t);
  params.elbow_l = -PI/8 + PI/8*sin(t);
  params.elbow_r = -PI/8 - PI/8*sin(t);
  params.leg_l = PI/2 + PI*0.1*sin(t);
  params.leg_r = PI/2 - PI*0.1*sin(t);
  params.knee_l = max(0, PI/4*sin(t-PI*0.6));
  params.knee_r = max(0, -PI/4*sin(t-PI*0.6));
  params.offY = 10*pow(0.5*(1+sin((t-PI/2)*2)), 0.5);
  
  background(222, 94, 69);
  stroke(97, 47, 189);
  fill(97, 47, 189);
  
  translate(0, -100, 0);
  const currentR = millis()/6000;
  const currentAngle = sin(currentR)*PI/2;
  rotateY(currentAngle);
  translate(
    40*(noise(currentR, 0)-0.5),
    40*(noise(currentR, 1000)-0.5),
    20*(noise(currentR, 2000)-0.5));
  scale(1.6);
  
  objs.forEach(obj => obj.update(1/30));
  objs.forEach(obj => {
    const ptA = obj.target();
    const ptB = obj.loc;
    line(ptA.x, ptA.y, ptA.z, ptB.x, ptB.y, ptB.z);
    point(ptA.x, ptA.y, ptA.z);
  });
  noStroke();
  objs.forEach(obj => {
    const ptB = obj.loc;
    push();
    translate(ptB.x, FLOOR, ptB.z);
    rotateX(PI/2);
    circle(0, 0, obj.mass*5);
    pop();
  });
  
  fill(255);
  objs.forEach(obj => {
    const pt = obj.loc;
    /*const toTarget = obj.target().sub(pt);
    const fwd = createVector(0, 0, 1);
    const angle = fwd.angleBetween(toTarget);
    const axis = fwd.copy().cross(toTarget);*/
    push();
    translate(pt.x, pt.y, pt.z);
    //rotate(angle, axis);
    rotateY(-currentAngle);
    scale(obj.mass/5);
    text(obj.letter, 0, 0);
    pop();
  });
  /*for (let pt in points) {
    point(points[pt].x, points[pt].y, points[pt].z);
  }*/
  
  /*let time = millis();
  rotateX(time / 1000);
  rotateZ(time / 1234);
  line(0,0,0, 100,100,100);*/
  //text('p5.js', 0, 0);
}
              
            
!
999px

Console