Skip to content

Commit

Permalink
wip working
Browse files Browse the repository at this point in the history
  • Loading branch information
hannahilea committed May 9, 2024
1 parent 5a1e4fc commit 2d3e5b8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
3 changes: 2 additions & 1 deletion projects/flock-chorus/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
<title>Sketch: Flock chorus</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.7.0/p5.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.7.0/addons/p5.sound.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script> <!--TODO: get local version of p5 libraries-->
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<!-- <script type="module" src="http://unpkg.com/tone"></script> -->
<script>
var GUI = lil.GUI;
</script>
Expand Down
24 changes: 19 additions & 5 deletions projects/flock-chorus/sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,22 @@
let flock;

const params = {
worldWraps: true,
worldWraps: false,
maxspeed: 2,
maxforce: 0.05, // Maximum steering force
radius: 3,
};

const gui = new GUI();
gui.add(params, 'worldWraps').name("Wrap world");
const guiFolder = gui.addFolder( 'Settings for spawned boids' );
guiFolder.add(params, 'maxspeed', 0, 8, .5).name("Max speed");
guiFolder.add(params, 'maxforce', 0, .1, .01).name("Max steering force");
guiFolder.add(params, 'radius', .1, 10, .3).name("Size");

function setup() {
createCanvas(windowWidth, windowHeight)
// Tone.start();

flock = new Flock();
// Add an initial set of boids into the system
Expand All @@ -26,7 +34,7 @@ function windowResized() {

function draw() {
// https://stackoverflow.com/questions/55026293/google-chrome-javascript-issue-in-getting-user-audio-the-audiocontext-was-not
// getAudioContext().resume();
getAudioContext().resume();

background(51);
flock.run();
Expand Down Expand Up @@ -76,9 +84,10 @@ function Boid(x, y) {
this.acceleration = createVector(0, 0);
this.velocity = createVector(random(-1, 1), random(-1, 1));
this.position = createVector(x, y);
this.r = 3.0;
this.maxspeed = 3; // Maximum speed
this.maxforce = 0.05; // Maximum steering force
this.r = params.radius;
this.maxspeed = params.maxspeed; // Maximum speed
this.maxforce = params.maxforce; // Maximum steering force
// this.synth = new Tone.Synth().toDestination();
}

Boid.prototype.run = function (boids) {
Expand Down Expand Up @@ -187,7 +196,12 @@ Boid.prototype.separate = function (boids) {
steer.mult(this.maxspeed);
steer.sub(this.velocity);
steer.limit(this.maxforce);

// Play collision sound!
// console.log(this, "ping", steer.mag())
// this.synth.triggerAttackRelease("C4", "8n")
}

return steer;
}

Expand Down

0 comments on commit 2d3e5b8

Please sign in to comment.