is there any way to change the background colour with minim using the line in code ?
in
Core Library Questions
•
1 year ago
could anyone plz help, all i am trying to do is to get the background colour to flash a different colour using the line in. i have started it by trying to do an if statement, but it can not convert to boolean.
import toxi.geom.*;
ArrayList ballNetwork;
import ddf.minim.*;
Minim minim;
AudioInput in;
void setup(){
size(1300,300);
smooth();
ballNetwork = new ArrayList();
minim = new Minim(this);
minim.debugOn();
in = minim.getLineIn(Minim.STEREO, 512);
for (int i = 0; i < 150; i++){
Vec3D origin = new Vec3D(random(width),random(200),0);
ball myBall = new ball(origin);
ballNetwork.add(myBall);
}
}
void draw(){
background(#62AFFA);
if(in = true);
background(0);
for(int i = 0; i < ballNetwork.size(); i++) {
ball mb = (ball) ballNetwork.get(i);
mb.run();
}
}
void stop()
{
// always close Minim audio classes when you are done with them
in.close();
minim.stop();
super.stop();
}
class ball{
Vec3D loc = new Vec3D (0,0,0);
Vec3D speed = new Vec3D (random(-2,5), random(-2,5),0);
Vec3D acc = new Vec3D ();
ball(Vec3D _loc) {
loc = _loc;
}
void run(){
display();
move();
bounce();
lineBetween();
flock();
}
void flock(){
separate(4);
cohesion(0.001);
//align();
}
void cohesion(float magnitude){
Vec3D sum = new Vec3D();
int count = 0;
for (int i = 0; i < ballNetwork.size(); i++) {
ball other = (ball) ballNetwork.get(i);
float distance = loc.distanceTo(other.loc);
if (distance> 0 && distance < 60){
sum.addSelf(other.loc);
count++;
}
}
if (count > 0){
sum.scaleSelf(1.0/count);
}
Vec3D steer = sum.sub(loc);
steer.scaleSelf(magnitude);
acc.addSelf(steer);
}
void separate (float magnitude){
Vec3D steer = new Vec3D();
int count = 0;
for (int i = 0; i < ballNetwork.size(); i++) {
ball other = (ball) ballNetwork.get(i);
float distance = loc.distanceTo(other.loc);
if (distance> 0 && distance < 30){
Vec3D diff = loc.sub(other.loc);
diff. normalizeTo(1.0/distance);
steer.addSelf(diff);
count++;
}
}
if(count > 0){
steer.scaleSelf(1.0/count);
}
steer.scaleSelf(4);
acc.addSelf(steer);
}
void lineBetween(){
for (int i = 0; i < ballNetwork.size(); i++) {
ball other = (ball) ballNetwork.get(i);
float distance = loc.distanceTo(other.loc);
if (distance> 0 && distance < 90){
stroke(250);
strokeWeight(0.1);
line(loc.x,loc.y,other.loc.x,other.loc.y);
}
}
}
void move(){
speed.addSelf(acc);
speed.limit(2);
loc.addSelf(speed);
acc.clear();
}
void bounce() {
if(loc.x > width) {
speed.x = speed.x * -1;
}
if(loc.x < 0) {
speed.x = speed.x * -1;
}
if(loc.y > height) {
speed.y = speed.y * -1;
}
if(loc.y < 0) {
speed.y = speed.y * -1;
}
}
void display(){
fill(0);
stroke(0);
ellipse(loc.x,loc.y,2,2);
}
}
1