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

              
                <!DOCTYPE html>
<html>
  <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.5.0/p5.min.js"></script>
    <script src="https://cdn.jsdelivr.net/gh/hapticdata/toxiclibsjs@0.3.2/build/toxiclibs.js"></script>
  </head>
  <body>
    <script src="sketch.js"></script>
  </body>
</html>

              
            
!

CSS

              
                
              
            
!

JS

              
                let physics;
let particleA;
let particleB;
let particleC;
let setuppringA;
const {VerletPhysics2D, VerletParticle2D, VerletSpring2D} = toxi.physics2d;
const {Vec2D, Rect} = toxi.geom;
function setup() {
    createCanvas(1200, 700);
    physics = new VerletPhysics2D();
    let bound = new Rect(0,0,1200,400);
    physics.setWorldBounds(bound);

    //shape1
    //particleA
    particleA = new VerletParticle2D(120,200);
    physics.addParticle(particleA);

    //particleB
    particleB = new VerletParticle2D(120,100);
    physics.addParticle(particleB);

    //particleC
    particleC = new VerletParticle2D(250,100);
    physics.addParticle(particleC);

    //particleD
    particleD = new VerletParticle2D(250,200);
    physics.addParticle(particleD);

    
    
    //springA
    springA = new VerletSpring2D(particleA, particleB, 100, 0.000001);
    physics.addSpring(springA);

    //springB
    springA = new VerletSpring2D(particleA, particleC, 100, 0.001);
    physics.addSpring(springA);

    //springC
    springA = new VerletSpring2D(particleC, particleB, 100, 0.0000000000000000000000000000001);
    physics.addSpring(springA);

    //springD
    springD = new VerletSpring2D(particleB, particleD, 100, 0.01);
    physics.addSpring(springD);

    //springE
    springE = new VerletSpring2D(particleA, particleD, 100, 0.00001);
    physics.addSpring(springE);

    //springF
    springF = new VerletSpring2D(particleC, particleD, 100, 0.00000001);
    physics.addSpring(springF);

    //shape2
    //particle1
    particle1 = new VerletParticle2D(320,200);
    physics.addParticle(particle1);

    //particle2
    particle2 = new VerletParticle2D(220,200);
    physics.addParticle(particle2);

    //particle3
    particle3 = new VerletParticle2D(250,100);
    physics.addParticle(particle3);

    //particle4
    particle4 = new VerletParticle2D(250,300);
    physics.addParticle(particle4);

    if(particleA.x = 1200)
    {
        springA = new VerletSpring2D(particleA, particleB, 0, 0);
        physics.addSpring(springA);
        springB = new VerletSpring2D(particleA, particleC, 0, 0);
        physics.addSpring(springB);
        springE = new VerletSpring2D(particleA, particleD, 0, 0);
        physics.addSpring(springE);
    }
    if(particleA.y = 400)
    {
        springA = new VerletSpring2D(particleA, particleB, 0, 0);
        physics.addSpring(springA);
        springB = new VerletSpring2D(particleA, particleC, 0, 0);
        physics.addSpring(springB);
        springE = new VerletSpring2D(particleA, particleD, 0, 0);
        physics.addSpring(springE);
    }
    
    }
  
function draw() {
    background(255);

    //shape1
    //particleA
    circle(particleA.x, particleA.y, 16);
    fill(0,0,255);

    //particleB
    circle(particleB.x, particleB.y, 16);
    fill(0,0,0);

    //particleC
    circle(particleC.x, particleC.y, 16);
    fill(0,255,0);

    //particleD
    circle(particleD.x, particleD.y, 16);
    fill(255,0,0);




    //springA
    line(particleA.x, particleA.y, particleB.x, particleB.y);

    //springB
    line(particleA.x, particleA.y, particleC.x, particleC.y);

    //springC
    line(particleC.x, particleC.y, particleB.x, particleB.y);

    //springD
    line(particleD.x, particleD.y, particleB.x, particleB.y);

    //springE
    line(particleA.x, particleA.y, particleD.x, particleD.y);

    //springF
    line(particleC.x, particleC.y, particleD.x, particleD.y);


    if(mouseIsPressed){
        particleA.lock();
        particleA.x = mouseX;
        particleA.y = mouseY;
        particleA.unlock();
    }


    physics.update();
}
  
              
            
!
999px

Console