UNPKG

cacatoo

Version:

Building, exploring, and sharing spatially structured models

98 lines (76 loc) 3.57 kB
<html> <script src="../../dist/cacatoo.js"></script> <!-- Include cacatoo library (compiled with rollup) --> <script src="../../lib/all.js"></script> <!-- Load other packages --> <link rel="shortcut icon" type="image/jpg" href="../../patterns/cacatoo.png"/> <link rel="stylesheet" href="../../style/cacatoo.css"> <!-- Set style sheet --> <script> /*-----------------------Start user-defined code ---------------------*/ let sim; function cacatoo() { let simconfig = { title: "Basic physics", // The name of your cacatoo-simulation description: "", // And a description if you wish maxtime: 10000, // How many time steps the model continues to run // (note, the onscreen FPS may drop below 60 fps when using fast mode, although many more timesteps may be handled per second) width: 400, // Number of columns (width of your grid) height: 400, // Number of rows (height of your grid) scale: 1.4, // Scale of the grid (nxn pixels per grid point) sleep: 0, wrap: [false,false], fpsmeter: true, statecolours: { 'type': { 1: 'violet', 2: 'gold', 3: 'cyan' } }, } let flockconfig = { shape: 'dot', // Shape of the boids drawn click: 'repel', // Clicking the boids pushes them away from the mouse max_speed: 30, // Maximum velocity of boids max_force: 0.1, // Maximum steering force applied to boids (separation/cohesion/alignment rules) init_velocity:0.0, friction: 0.1, gravity: 0.1, // Mouse parameters mouse_radius: 20, // Radius of boids captured by the mouse overlay draw_mouse_radius: true, // Show a circle where the mouse is // Collision behaviour collision_force: 0.01, size: 2.5, // Size of the boids (scales drawing and colision detection) // Optimalisation (speed) parameters //qt_colour: 'white', // Show quadtree (optimalisation by automatically tessalating the space) qt_capacity: 5, // How many boids can be in one subspace of the quadtree before it is divided further } sim = new Simulation(simconfig) // Initialise the Cacatoo simulation sim.makeFlockmodel("flock", flockconfig) // Add a flockmodel, which contains invidiuals (boids) in continuous space // Define some obstables for collision detection sim.flock.placeObstacle({x:200,y:200,r:30,fill:'#ffffff33'}) sim.flock.placeObstacle({x:85,y:15,w:15,h:285,fill:'#ffffff33'}) sim.flock.placeObstacle({x:300,y:15,w:15,h:285,fill:'#ffffff33'}) sim.flock.placeObstacle({x:85,y:300,w:110,h:15,fill:'#ffffff33'}) sim.flock.placeObstacle({x:205,y:300,w:110,h:15,fill:'#ffffff33'}) // Add 3000 particles in the top sim.flock.populateSpot(3000,215,90,70) for(let boid of sim.flock.boids) { boid.type=Math.round(sim.rng.random()*2)+1 } // Uncomment this line for a magic ball //sim.flock.boids[0].gravity = -1 sim.createFlockDisplay("flock", {legend: false, property:"type",label:"physics"}) // sim.addMovieButton(sim.flock, "physics",60) sim.start() } </script> <body onload="cacatoo()"> <div class="header" id="header"> <h2>Cacatoo </h2> </div> <div class="content" id="canvas_holder"></div> <div class="content" id="form_holder"></div> <div class="content" id="graph_holder"> </div> <div class="footer" id="footer"></div> </body> </html>