Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                body{
  margin:0;
}
              
            
!

JS

              
                var beds=[];
var timeOfDay=0.25;
var tick=2*1/(24*60);
var bedShadowX=new TimeTrack(0.25,0.5,0.75,0);
var bedShadowY=new TimeTrack(0.25,0.25,0.5,0.25);
var bedShadowA=new TimeTrack(0.25,0.25,0.5,0.25);
var bedWriggle=new TimeTrack(0.25,0.25,0.5,0.25);
var sky;

function setup() {
  createCanvas(windowWidth, windowHeight);
  beds.push(new Bed(width/2,height/2,height*0.25,height*0.4));
  sky=new Sky();
}

function draw() {
  background(200);
  sky.show(timeOfDay);
  beds.forEach(function(bed){
    bed.show(timeOfDay);
  });
  timeOfDay=(timeOfDay+tick)%1;
}

function Bed(x,y,w,h){
  var pillow=new Pillow(x,y-h*0.4,w*0.8,h*0.18);
  var duvet=new Duvet(x,y+h*0.1,w*1.1,h*0.9);
  
  this.show=function(tod){
    push();
    translate(x,y);
    rectMode(CENTER);
    var bsA=bedShadowA.getVal(tod);
    noStroke();
        fill(40,180*bsA);
    var bsX=bedShadowX.getVal(tod);
    var bsY=bedShadowY.getVal(tod);
    rect(-bsX*w/2+w/4, w/8+w/4-bsY*w/4, w, h, w*0.1);//light.bedShadowX*w/2-w/4
    fill(128);
    rect(0,0,w,h,w*0.1);
    pop();
    pillow.show(tod);
    duvet.show(tod);
  };
}

function Pillow(x,y,w,h){
  var shape=new Shape(x,y,w,h,10,0.5);
  
  this.show=function(tod){
    shape.show(tod);
  };
}

function Duvet(x,y,w,h){
  var shape=new Shape(x,y,w,h,10,2);
  
  this.show=function(tod){
    shape.show(tod);
  };
}

function Sky(){
  this.show=function(tod){
    var skyHue=80+140*abs((0.5-tod)/0.5);
    push();
    fill(skyHue/2,skyHue/2,skyHue);
    noStroke();
    rect(0,0,width,height);
    translate(width/2, height/2);
    push();
    rotate(tod*TWO_PI);
    translate(0,height*0.35);
    var dayNight=abs(0.5-tod)/0.5
    scale(1-dayNight);
    fill(255);
    ellipse(0,0,height*0.1);
    rotate(-tod*TWO_PI-PI/2);
    fill(skyHue/2,skyHue/2,skyHue);
    ellipse(0,height*0.02,height*0.1);
    pop();
    push();
    fill(255);
    rotate(tod*TWO_PI);
    translate(0,-height*0.35);
    scale(dayNight);
    ellipse(0,0,height*0.12);
    fill(255,100);
    ellipse(0,0,height*0.12*(0.5+dayNight)*(0.5+dayNight));
    pop();
    pop();
  };
  
}

function TimeTrack(ad,ar,dd,dr){
  
  this.getVal=function(time){
    var val=0;
    if(time>dd+dr){
      val=0;
    } else if(time>dd){
      val=1-(time-dd)/dr;
    } else if(time>ad+ar){
      val=1;
    } else if(time>ad){
      val=(time-ad)/ar;
    }
    return val;
  };
}

function Shape(x,y,w,h,n,magn){
  var ns=random(10);
  var vertices=[];
  var wriggle=0;
  var wriggleCount=60;
  var wriggleDisp=w/2;
  var wriggleInc=1;
  var wriggling=false;
  var noiseCount=0;
  var shade=random(-20,20);

  this.wriggleNow=function(){
    wriggling=true;
  }
  
  for(var i=0; i<n; i++){
    vertices.push({x:-w/2+i*w/n, y: -h/2, o:"h", s:0});
  }
  for(var i=0; i<n; i++){
    vertices.push({x:w/2, y:-h/2+i*h/n, o:"v", s:1});
  }
  for(var i=0; i<n; i++){
    vertices.push({x:w/2-i*w/n, y: h/2, o:"h", s:0});
  }
  for(var i=0; i<n; i++){
    vertices.push({x:-w/2, y:h/2-i*h/n, o:"v", s:1});
  }
  console.log(vertices);
  
  this.show=function(tod){
    var wrDisp=magn*wriggleDisp*bedWriggle.getVal(tod);//wriggleDisp*wriggle/wriggleCount;
    push();
    translate(x,y);
    beginShape();
    fill(200+shade);
    noStroke();
    vertices.forEach(function(vert,i){
      if(vert.o==="v"){
        vertex(vert.x+noise(ns+vert.y/50,vert.s,noiseCount/50)*wrDisp-wrDisp/2, vert.y);
      } else {
        vertex(vert.x, vert.y+noise(ns+vert.x/50,vert.s,noiseCount/50)*wrDisp-wrDisp/2);
      }
    });
    endShape(CLOSE);
    pop();
    noiseCount++;
  };
}
              
            
!
999px

Console