cacatoo
Version:
Building, exploring, and sharing spatially structured models
95 lines (73 loc) • 3.52 kB
HTML
<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.8, // Scale of the grid (nxn pixels per grid point)
sleep: 0,
wrap: [false,false],
fpsmeter: true,
statecolours: {
'type': 'pride'
},
}
let flockconfig = {
shape: 'dot', // Shape of the boids drawn
click: 'repel', // Clicking the boids pushes them away from the mouse
max_speed: 10, // Maximum velocity of boids
max_force: 0.5, // Maximum steering force applied to boids (separation/cohesion/alignment rules)
init_velocity:0.0,
friction: 0.05,
gravity: 0.05,
// 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.5,
size: 2.4, // 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
let objforce = 1
sim.flock.placeObstacle({x:200,y:200,r:30,fill:'#ffffff33',force:objforce})
sim.flock.placeObstacle({x:85,y:15,w:15,h:285,fill:'#ffffff33',force:objforce})
sim.flock.placeObstacle({x:300,y:15,w:15,h:285,fill:'#ffffff33',force:objforce})
sim.flock.placeObstacle({x:85,y:300,w:110,h:15,fill:'#ffffff33',force:objforce})
sim.flock.placeObstacle({x:205,y:300,w:110,h:15,fill:'#ffffff33',force:objforce})
// Add 3000 particles in the top
sim.flock.populateSpot(3000,200,90,30)
for(let boid of sim.flock.boids) {
boid.type=Math.floor(sim.rng.random()*100)+1
}
sim.createFlockDisplay("flock", {legend: false, property:"type",label:"Basic physics (please do not build bridges with physics this bad)"})
sim.flock.update = function(){
for(let i=0; i<2; i++) this.flock()
}
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>