xxxxxxxxxx
130
/*
- Turn on Sound
- Run the sketch
- Enter US state initials
- The number of chords represents
Native American tribes located in the state
- You can change states
*/
let tribes = [];
let button;
let a = 0;
let c1 = 0;
let c2 = 0;
let c3 = 0;
let c4 = 0;
let speed1 = 1;
let speed2 = 2;
let speed3 = 1;
let speed4 = 2;
let op = false;
let col = 0;
let colSpeed = 1;
let song;
var amp;
var vol;
var fft;
var peakDetect;
let count = 0;
function setup() {
createCanvas(1080,608);
loadJSON('Tribes.json', stateCount);
stateInput = createInput('');
button = createButton('Enter');
button.mousePressed(use);
angleMode(DEGREES);
song = loadSound('Shaman.m4a');
amp = new p5.Amplitude();
fft = new p5.FFT();
peakDetect = new p5.PeakDetect(20, 20000, 0.08);
}
function stateCount(data) {
tribes = data;
}
function draw() {
background(0, 10);
translate(width/2, height/2);
vol = amp.getLevel();
//print(vol);
fft.analyze();
peakDetect.update(fft);
if (op) {
noFill();
if (tribes.length > 0) {
a = 0;
for (let i = 0; i < tribes.length; i++) {
if (tribes[i].FIELD1 == stateInput.value()) {
a++;
}
}
}
for (let ang = 0; ang < 360; ang += (360 / a) / 2) {
rotate(ang);
stroke(0, 10);
fill(col, 10);
bezier(a, 0, c1, c2, c3, c4, 0,0);
}
c1 = c1 + speed1;
c2 = c2 + speed2;
c3 = c3 + speed3;
c4 = c4 + speed4;
if (peakDetect.isDetected) {
count++;
}
if (count % 2 == 0 || c1 < 0 || c1 > width) {
speed1 = -speed1;
//speed1 = random([1.1, 0.8]) * speed1;
}
if (count % 3 == 0 || c2 < 0 || c2 > height) {
speed2 = -speed2;
//speed2 = 0.95 * speed2
}
if (count % 5 == 0 || c3 < 0 || c3 > width) {
speed3 = -speed3;
//speed3 = random([1.1, 0.95]) * speed3;
}
if (count % 7 == 0 || c4 < 0 || c4 > height) {
speed4 = -speed4;
//speed4 = 1.05 * speed4
}
//col = col + colSpeed;
if (peakDetect.isDetected) {
//colSpeed = -colSpeed;
col = [150, 20, 10, 70];
} else {
col = 255;
}
}
}
function use() {
op = !op
song.play();
}