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

              
                
              
            
!

CSS

              
                body{
  margin:0;
}
              
            
!

JS

              
                var numberSpots;
var dominoSecUnits;
var dominoSecTens;
var dominoMinUnits;
var dominoMinTens;
var dominoHour;
var colon1;
var colon2;
var tic=0;

function setup() {
  createCanvas(1000,200);
  var t=680;
  var offX=20/t*width;
  var offY=20/t*width;
  var domW=100/t*width;
  var domH=100/t*width;
  var colonW=40/t*width;
  var gap=10/t*width;
  numberSpots=new NumberSpots();
  dominoHour=new Domino(numberSpots, 1, 12, domW, domH, offX, offY);
  offX+=domW+gap;
  colon1=new Colon(colonW, domH, offX, offY);
  offX+=colonW+gap;
  dominoMinTens=new Domino(numberSpots, 0, 5, domW, domH, offX, offY);
  offX+=domW+gap;
  dominoMinUnits=new Domino(numberSpots, 0, 9, domW, domH, offX, offY);
  offX+=domW+gap;
  colon2=new Colon(colonW, domH, offX, offY);
  offX+=colonW+gap;
  dominoSecTens=new Domino(numberSpots, 0, 5, domW, domH, offX, offY);
  offX+=domW+gap;
  dominoSecUnits=new Domino(numberSpots, 0, 9, domW, domH, offX, offY);
  setInterval("tick()",1000);
  tick();
}

function mousePressed(){
  // tick();
}

function draw() {
  background(200);
  dominoHour.show();
  colon1.show();
  dominoMinTens.show();
  dominoMinUnits.show();
  colon2.show();
  dominoSecTens.show();
  dominoSecUnits.show();
}

function setDominoTimeNow(){
  var d=new Date();
  var hours=d.getHours()%12;
  if(hours===0) hours=12;
  var mins=d.getMinutes();
  var minUnits=mins%10;
  var minTens=floor(mins/10);
  var secs=d.getSeconds();
  var secUnits=secs%10;
  var secTens=floor(secs/10);
  // console.log(hours+":"+minTens+minUnits+":"+secTens+secUnits);
  dominoHour.setNum(hours);
  dominoMinTens.setNum(minTens);
  dominoMinUnits.setNum(minUnits);
  dominoSecTens.setNum(secTens);
  dominoSecUnits.setNum(secUnits);
}

function tickUp(){
  if(dominoSecUnits.nextNum()>0){
    if(dominoSecTens.nextNum()>0){
      if(dominoMinUnits.nextNum()>0){
        dominoMinTens.nextNum();
      }
    }
  }
}

function tick(){
  setDominoTimeNow();
}


function NumberSpots(){
  this.spots={
    0: [],
    1: [7],
    2: [2,3],
    3: [2,3,7],
    4: [0,2,3,5],
    5: [0,2,3,5,7],
    6: [0,1,2,3,4,5],
    7: [0,1,2,3,4,5,7],
    8: [0,1,2,3,4,5,6,8],
    9: [0,1,2,3,4,5,6,7,8],
    10:[0,1,2,3,4,5,6,9,10,11],
    11:[0,1,2,3,4,5,6,7,9,10,11],
    12:[0,1,2,3,4,5,6,7,8,9,10,11]
  };
  
  this.getSpots=function(n){
    if(n<0) return false;
    return this.spots[n].slice();
  };
}

function Domino(numSpots, num, maxNum, w, h, x, y, spaces){
  var spotSize;
  var positions=[];
  setupPositions();
  var spots=[];
  var dyingSpots=[];
  var spotPos=[];
  var currentNum=1;
  // var maxNum=12;
  var numNow=0;
  
  this.nextNum=function(){
    num++;
    var over=0;
    if(num>maxNum){
      num=0;
      over=1;
    }
    setSpots(num);
    shakeUp();
    // console.log(spaces+num);
    return over;
  }
  
  this.setNum=function(n){
    if(n!=currentNum){
      setSpots(n);
      shakeUp();
    }
  }

  
  function getPosVec(npi){
    if(npi<0){
      return createVector(-50,-50);
    }
    // return createVector(300,300);
    var coords=positions[npi];
    return createVector(coords.x, coords.y);
  }
  
  function setSpots(n){
    currentNum=n;
    spotPos=numSpots.getSpots(n);
    while(spots.length<spotPos.length){
      spots.push(new Spot(spotSize, -1, getStartPos(w,h,x,y)));
    }
    while(spots.length>spotPos.length){
      var s=spots.pop();
      dyingSpots.push(s);
      s.dieNow();
    }
  };
  
  function getStartPos(w,h,x,y){
    var sx, sy;
    var s=random(w*2+h*2);
    if(s>w*2+h){
      sy=s-(w*2+h);
      sx=spotSize/2;
    }else if(s>w+h){
      sx=s-(w+h);
      sy=h-spotSize/2;
    }else if(s>w){
      sy=s-w;
      sx=w-spotSize/2;
    }else {
      sx=s;
      sy=spotSize/2;
    }
    return createVector(sx, sy);
  }
  
  function shakeUp(){
    var places=numSpots.getSpots(currentNum);
    for(var i=0; i<spots.length; i++){
      var select=floor(random(places.length));
      while(places[select]===spots[i].nextPosIndex){
        select=floor(random(places.length));
      }
      var p=places[select];
      spots[i].transitionNow(places[select]);
      places.splice(select,1);
      // console.log(p+" "+ places);
    }
  }

  setSpots(num);
  shakeUp();

  
  function setupPositions(){
    var ratio=w/h;
    var base=ratio<=1?w:h;
    var vSpace=base/4;
    var vHS=base/8;
    var hSpace=vSpace;
    spotSize=base/8;
    positions[0]={x:w/2-hSpace, y:h/2-vSpace-vHS};
    positions[1]={x:w/2-hSpace, y:h/2-vHS};
    positions[2]={x:w/2-hSpace, y:h/2+vSpace-vHS};
    positions[3]={x:w/2+hSpace, y:h/2-vSpace-vHS};
    positions[4]={x:w/2+hSpace, y:h/2-vHS};
    positions[5]={x:w/2+hSpace, y:h/2+vSpace-vHS};
    positions[6]={x:w/2, y:h/2-vSpace-vHS};
    positions[7]={x:w/2, y:h/2-vHS};
    positions[8]={x:w/2, y:h/2+vSpace-vHS};
    positions[9]={x:w/2-hSpace, y:h/2+vSpace*2-vHS};
    positions[10]={x:w/2, y:h/2+vSpace*2-vHS};
    positions[11]={x:w/2+hSpace, y:h/2+vSpace*2-vHS};
  }
  
  this.show=function(){
    showBase();
    spots.forEach(function(s){
      s.show();
      s.run();
    });
    for(var i=dyingSpots.length-1; i>=0; i--){
      if(!dyingSpots[i].dieRun()){
        dyingSpots.splice(i,1);
      }
    }
  };
  
  function showBase(){
    push();
    translate(x,y);
    fill(60);
    noStroke();
    rectMode(CORNER);
    rect(0,0,w,h);
    positions.forEach(function(p){
      fill(75);
      noStroke();
      ellipse(p.x, p.y, spotSize, spotSize);
    });
    pop();
  }
  
  function Spot(size, initPos, startPos){
    this.prevPosIndex=-1;
    this.nextPosIndex=pos;
    var pos=startPos||createVector(100,100);
    var dest;//=getPosVec(this.nextPosIndex);
    var cHue=random(0,360);
    
    var transitioning=false;
    var transDur=30;
    var dieTTL=0;
    var dieRad=0;
    var shrink;
    var transTTL=transDur;
    var vel=createVector(0,0);
    var acc=createVector(0,0);
    var distToDest=0;
    var trip;

    
    this.transitionNow=function(newPosIndex){
      dest=getPosVec(newPosIndex);
      this.prevPosIndex=this.NextPosIndex;
      this.nextPosIndex=newPosIndex;
      transitioning=true;
      transTTL=transDur;
      trip=p5.Vector.sub(dest, pos)
      distToDest=trip.copy().mag();
      trip.mult(1/transDur);
      vel=trip;
    }
    
    this.transitionNow(initPos);
    

    this.run=function(){
      if(transitioning){
        transTTL--;
        pos.add(vel);
        distToDest=p5.Vector.sub(dest, pos).mag();
        if(transTTL<0 || distToDest<1){
          transitioning=false;
          pos=dest.copy();
        }
      }
    }
    
    this.dieNow=function(){
      dieTTL=transDur;
      dieRad=0;
      shrink=size/transDur;
    };
    
    this.dieRun=function(){
      dieTTL--;
      dieRad+=shrink;
      push();
      translate(x,y);
      colorMode(HSB);
      var a=map(dieTTL, transDur, 0, 1, 0.3);
      var s=map(dieTTL, transDur, 0, 50, 100);
      stroke(cHue,s,100, a);
      fill(cHue,s,100, a);
      ellipse(pos.x, pos.y, size-dieRad, size-dieRad);
      noFill();
      ellipse(pos.x, pos.y, size+dieRad, size+dieRad);
      pop();
      return dieTTL>0;
    };
    
    this.show=function(){
      push();
      translate(x,y);
      // stroke(0);
      noStroke();
      colorMode(HSB);
      fill(cHue, 50, 100, 1);
      ellipse(pos.x, pos.y, size, size);
      pop();
    }
  }
}

function Colon(w,h, x, y){
  
  var blink=true;
  
  this.show=function(){
    push();
    translate(x, y);
    fill(60);
    noStroke();
    rectMode(CORNER);
    rect(0,0,w,h);
    noStroke();
    fill(blink?255:75);
    ellipse(w/2, h/8+h/4, w/3, w/3);
    ellipse(w/2, h-h/8-h/4, w/3, w/3);
    pop();
    if(frameCount%30===0){
      blink=!blink;
    }
  }
}
              
            
!
999px

Console