diff --git a/projects/flock-chorus/index.html b/projects/flock-chorus/index.html
index 0cb7e19..ee018cc 100644
--- a/projects/flock-chorus/index.html
+++ b/projects/flock-chorus/index.html
@@ -4,9 +4,8 @@
Sketch: Flock chorus
-
-
+
@@ -20,6 +19,19 @@
}
+
@@ -31,13 +43,11 @@ @hannahilea > projects > Sk
Details
-
Built on top of the p5 flocking demo.
Usage: Drag on screen to loose flocks of birds. Make sure your computer sound is on. May not yet work on mobile.
+
-
+
diff --git a/projects/flock-chorus/sketch.js b/projects/flock-chorus/sketch.js
index 98554ba..159c8a2 100644
--- a/projects/flock-chorus/sketch.js
+++ b/projects/flock-chorus/sketch.js
@@ -1,31 +1,35 @@
// Built off of p5 flocking demo sketch https://p5js.org/examples/simulate-flocking.html
-
+console.log("Access to tone module?", Tone)
let flock;
const params = {
worldWraps: false,
- maxspeed: 2,
+ maxspeed: .5, //2,
maxforce: 0.05, // Maximum steering force
radius: 3,
+ targetFreqHz: 440,
+ maxStartOffsetHz: 100,
};
const gui = new GUI();
gui.add(params, 'worldWraps').name("Wrap world");
const guiFolder = gui.addFolder( 'Settings for spawned boids' );
+guiFolder.add(params, 'targetFreqHz', 27, 2350, 5).name("Target freq (Hz)");
+guiFolder.add(params, 'maxStartOffsetHz', 0, 100, 1);
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();
+ Tone.start();
flock = new Flock();
// Add an initial set of boids into the system
- for (let i = 0; i < 100; i++) {
- let b = new Boid(width / 2, height / 2);
- flock.addBoid(b);
- }
+ // for (let i = 0; i < 100; i++) {
+ // let b = new Boid(width / 2, height / 2);
+ // flock.addBoid(b);
+ // }
}
function windowResized() {
@@ -34,14 +38,14 @@ 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();
}
// Add a new boid into the System
-function mouseDragged() {
+function mouseClicked() {
flock.addBoid(new Boid(mouseX, mouseY));
}
@@ -87,7 +91,11 @@ function Boid(x, y) {
this.r = params.radius;
this.maxspeed = params.maxspeed; // Maximum speed
this.maxforce = params.maxforce; // Maximum steering force
- // this.synth = new Tone.Synth().toDestination();
+ this.targetFreqHz = params.targetFreqHz;
+ this.synth = new Tone.PolySynth().toDestination();
+ this.synth.volume.value = -12
+ this.currentFreqHz = this.targetFreqHz + params.maxStartOffsetHz; //TODO: allow negative, randomize idff
+ this.synth.triggerAttack(this.currentFreqHz)
}
Boid.prototype.run = function (boids) {
@@ -187,6 +195,14 @@ Boid.prototype.separate = function (boids) {
// Average -- divide by how many
if (count > 0) {
steer.div(count);
+ // console.log(count,this.currentFreqHz, this.targetFreqHz)
+ if (this.currentFreqHz > this.targetFreqHz) {
+ this.currentFreqHz = this.currentFreqHz - 1;
+ // this.synth.triggerRelease()
+ this.synth.triggerAttack(this.currentFreqHz, Tone.now())
+ this.synth.releaseAll()
+ console.log("OK")
+ }
}
// As long as the vector is greater than 0
@@ -199,7 +215,6 @@ Boid.prototype.separate = function (boids) {
// Play collision sound!
// console.log(this, "ping", steer.mag())
- // this.synth.triggerAttackRelease("C4", "8n")
}
return steer;
diff --git a/projects/index.html b/projects/index.html
index 2b7470d..a68e7d1 100644
--- a/projects/index.html
+++ b/projects/index.html
@@ -58,11 +58,11 @@ Virtual Gallery
One-off creative coding projects, often small and interactive.