Pen Settings



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


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


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.


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.




                body {
  margin: 0;
  padding: 0;

canvas { position:fixed; top:0; left:0; z-index:1; }



let chain = null;

function setup() {
  class Bone {
    constructor(x,y,angle,length,child) {
      this.x = x;
      this.y = y;
      this.length = length;
      this.angle = angle;
      this.child = child;

    draw() {
      this.child && this.child.draw();
    // takes in: a target point in the parent coordinate space
    // returns:  the endpoint of the chain, in that same parent
    //           coordinate space
    updateIK(target) {
      // convert from parent to local coordinates
      const localTarget = rotatePoint(translatePoint(target, -this.x, -this.y), -this.angle);
      let endPoint;
      if (this.child) {
        endPoint = this.child.updateIK(localTarget);
      } else {
        // base case:  the end point is the end of the current bone
        endPoint = [this.length, 0];
      // point towards the endpoint
      const shiftAngle = angle(localTarget) - angle(endPoint);
      this.angle += shiftAngle;
      // convert back to parent coordinate space
      return translatePoint(rotatePoint(endPoint, this.angle), this.x, this.y);
  chain = new Bone(200, 200, 0, 100,
    new Bone(100, 0, 0, 90,
      new Bone(90, 0, 0, 80,
        new Bone(80, 0, 0, 70)
  createCanvas(windowWidth, windowHeight);
  chain.updateIK([300, 50]);

function windowResized() {
	resizeCanvas(windowWidth, windowHeight);

function draw() {

function mouseMoved() {
  for (let i = 0; i < 5; i++) {
    chain.updateIK([mouseX, mouseY]);

// convenience methods for transforming points
// because P5.js doesn't have matrix classes :'(
function rotatePoint(point, angle) {
  const [x, y] = point;
  return [
    x*Math.cos(angle) - y*Math.sin(angle),
    x*Math.sin(angle) + y*Math.cos(angle)
function translatePoint(point, h, v) {
  const [x, y] = point;
  return [x+h, y+v];
function angle(point) {
  const [x, y] = point;
  return Math.atan2(y, x);