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

              
                <!-- Trying to figure out how to make the banana attached to the rope at the top and not have it spin around so much.

Also tryign to figure out how to make the banana detach from the rope when pulled too hard and then run a function. 
-->
              
            
!

CSS

              
                body{
    background: #1d1d1d;
    margin: 0;
    padding: 0;
}

#click-bait {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
              
            
!

JS

              
                Physics(function(world) {
    var viewWidth = window.innerWidth,
      viewHeight = window.innerHeight,
      // bounds of the window
      viewportBounds = Physics.aabb(0, 0, viewWidth, viewHeight),
      edgeBounce,
      renderer;
  
    // create a renderer
    renderer = Physics.renderer("canvas", {
      el: "click-bait"
    });
    renderer.el.width = viewWidth;
    renderer.el.height = viewHeight;

    // add the renderer
    world.add(renderer);
    // render on each step
    world.on("step", function() {
      world.render();
    });

    // constrain objects to these bounds
    edgeBounce = Physics.behavior("edge-collision-detection", {
      aabb: viewportBounds,
      restitution: 1,
      cof: 1
    });

    var gravity = Physics.behavior("constant-acceleration", {
      acc: { x: 0, y: 0.0004 } // this is the default: .0004
    });

    // resize events
    window.addEventListener( "resize",
      function() {
        viewWidth = window.innerWidth;
        viewHeight = window.innerHeight;
        renderer.el.width = viewWidth;
        renderer.el.height = viewHeight;
        viewportBounds = Physics.aabb(0, 0, viewWidth, viewHeight);
        // update the boundaries
        edgeBounce.setAABB(viewportBounds);
      },
      true
    );

    // for constraints
    var rigidConstraints = Physics.behavior("verlet-constraints", {
      iterations: 10
    });

    // the "basket"
    var basket = [];
    var fpos = window.innerWidth / 2;
    var epos = window.innerHeight / 4;
    for (var i = fpos; i < fpos + epos; i += 5) {
      l = basket.push(
        Physics.body("circle", {
          x: i,
          y: 50 - (i - fpos),
          radius: 1,
          restitution: 0.5,
          mass: 1000,
          conf: 1,
          hidden: true
        })
      );

      rigidConstraints.distanceConstraint(basket[l - 1], basket[l - 2], 2);
    }
        
    console.log(i + " i");
    console.log(fpos + " fpos");
    console.log(i - fpos + " i - fpos");
    console.log(50 - (i - fpos) + " y");
  
    var box = Physics.body("rectangle", {
      x: i,
      y: 50 - (i - fpos),
      width: 84,
      height: 100,
      mass: 1,
      restitution: 0,
      styles: {
        fillStyle: '#EC2027',
        src: "https://www.wildmonkeydesign.com/wp-content/uploads/2018/08/click-bait.svg",
        height: 100,
        width: 84
      }
    });

    rigidConstraints.distanceConstraint(basket[l - 1], box, 2);

    world.add(box);

    world.on("render", function(data) {
      var renderer = data.renderer;
      for (var i = 1, l = basket.length; i < l; ++i) {
        renderer.drawLine(basket[i - 1].state.pos, basket[i].state.pos, {
          strokeStyle: "#8e593c",
          lineWidth: 5,
          restitution: 0.5,
          mass: 1000,
          conf: 1
        });
      }
    });

    // fix the ends
    basket[0].treatment = "static";

    world.add(basket);
    world.add(rigidConstraints);

    // add things to the world
    world.add([
      Physics.behavior("interactive", { el: renderer.el }),
      Physics.behavior("constant-acceleration"),
      Physics.behavior("body-impulse-response"),
      //     ,Physics.behavior('body-collision-detection')
      Physics.behavior("sweep-prune"),
      edgeBounce,
      gravity
    ]);

    // subscribe to ticker to advance the simulation
    Physics.util.ticker.on(function(time) {
      world.step(time);
    });

    // start the ticker
    Physics.util.ticker.start();
  });
              
            
!
999px

Console