cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation


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.

              <script src="https://rawgit.com/kirbysayshi/6654845/raw/boid.js"></script><script src="https://rawgit.com/kirbysayshi/6654845/raw/drawing.js"></script>
<script src="https://rawgit.com/kirbysayshi/6654845/raw/stepstate.js"></script>
              html, body { margin: 0; padding: 5px; font-family: Helvetica, sans; }
canvas { padding: 10px; }
p { font-size: 10px; }
// Shared code available at https://gist.github.com/kirbysayshi/6654845

var ctx0 = ctx('Fixed DT (100) drawn at 60fps')
  , ctx1 = ctx('Fixed DT (100) drawn interpolated at 60fps')

var boid0 = new Boid(25, 25, 25)
  , boid1 = new Boid(25, 25, 25)

var acceleration = 5;

boid0.acel.x += acceleration;
boid1.acel.x += acceleration;

var ssi = new StepStateInterpolator(100, function logics(dt) {
  // dt is the target, constant dt.
  boid0.boundsCheck(ctx0.canvas.width, acceleration);
  boid1.boundsCheck(ctx1.canvas.width, acceleration);
}, function draws(dt, ratio) {
  drawCurrentPosition(ctx0, boid0);
  drawInterpolatedPosition(ctx1, boid1, ratio);

var lastTime = Date.now() - 16.666666;

(function frame() {
  var now = Date.now();
  var dt = now - lastTime;
  //return false; // Uncomment to halt drawing while developing :)
  lastTime = now;
Loading ..................