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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

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

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 Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

HTML

              
                
              
            
!

CSS

              
                body{
  margin: 0;
}
              
            
!

JS

              
                var cx,cy;
var moveRad=100;
var skates=[];
var numSkates=10;
var friction=0.1;

function setup() {
  createCanvas(windowWidth, windowHeight);
  for(var i=0; i<numSkates;i++){
    if(random(10)<5){
      skates.push(new Skate(random(width/2)+width/4, -100,100));
    } else {
      skates.push(new Skate(random(width/2)+width/4, height+100,100));
    }
  }
  cx=width/2;
  cy=height/2;
}

function draw() {
  background(100,200,255);
  skates.forEach(function(skate){
    skate.show();
    skate.run();
  });
}

function Skate(x,y,s){
  var vel=createVector(0,0);
  var pos=createVector(x,y);
  var acc,drift, orbit;
  var nBase=random(10);
  var maxVel=random(0.5,2);
  var grey=random(10,100);

  var tail=new Tail(x,y,s,15,grey);

  this.show=function(){
    push();
    translate(pos.x, pos.y);
    rotate(vel.heading());
    translate(s/4,0);
    drawSkate(s/2);
    pop();
    tail.show(pos.x, pos.y, vel.heading()-PI); 
    tail.run(vel.mag());
  };
  
  function drawSkate(s){
    noStroke();
    rotate(-PI/2);
    fill(grey);
    ellipse(0,0,s*0.8,s*1.1);
    ellipse(0,-s*0.45,s*0.4);
    ellipse(0,s*0.45,s*0.25,s*0.4);
    arc(0,s*0.707,s*1.8, s*2.3, -PI*0.75, -PI*0.25,CHORD);
    arc(0,-s*0.72,s*2, s*2, PI*0.25, PI*0.75,CHORD);
  }
  
  this.run=function(){
    acc=createVector(width/2, height/2).sub(pos).mult(0.0004);
    acc.rotate(PI/4);
    drift=p5.Vector.fromAngle(noise(nBase+x/100, y/100, nBase+frameCount/1000)*2*TWO_PI).setMag(0.1);
    acc.add(drift);
    vel.add(acc);
    vel.mult(0.9);
    vel.limit(maxVel);
    pos.add(vel);
  }
}

function Tail(x,y,l,n,g){
  var segs=[];
  var segLen=l/10;
  var seg;
  var aSwim=0;
  var aSwimPrev=0;
  var aSwimRange=PI/200;
  var aSwimDrive=random(PI);
  var aSwimDriveInc=PI/(random(100,200));
  var aSwimDelta=0;
  var energyProp=1.1;//random(1,1.2);
  for(var i=0; i<n; i++){
    seg=new Seg(segLen,segLen/2,g);
    segs.push(seg);
    segLen*=0.9;
  }
  
  this.run=function(speed){
    aSwim=sin(aSwimDrive)*(aSwimRange/2+aSwimRange*speed);
    aSwimDrive+=(aSwimDriveInc/2+aSwimDriveInc*speed);
    aSwimDelta=aSwim-aSwimPrev;
    aSwimPrev=aSwim;
    // console.log(aSwim);
  }
  
  this.show=function(x,y,a){
    push();
    translate(x,y);
    rotate(a);
    
    var pos={x:0, y:0, a:0};
    segs.forEach(function(seg){
      pos=seg.show(pos);
      aSwimDelta=seg.run(aSwimDelta,energyProp);
    });
    pop();
  };
}

function Seg(l,w,g){
  var aFlex=0;
  var aVel=0;
  var aAcc=0;
  var prevEnergy=0;
  var energyTrail=[];
  var energyTrailLen=12;
  for(var i=0; i<energyTrailLen; i++){
    energyTrail[i]=0;
  }
  
  this.run=function(energy,energyProp){
    energyTrail.push(energy*energyProp);
    aAcc=energy;
    aVel+=aAcc;
    aVel*=(1-friction);
    aFlex+=aVel;
    return energyTrail.shift();
  }
  
  this.show=function(pos){
    push();
    translate(pos.x,pos.y);
    rotate(pos.a);
    rotate(aFlex);
    strokeWeight(w);
    stroke(g);
    line(0,0,l,0);
    pop();
    return {
      x: pos.x+cos(pos.a+aFlex)*l,
      y: pos.y+sin(pos.a+aFlex)*l,
      a: pos.a+aFlex
    };
  };
}
              
            
!
999px

Console