Fitting In is a project I was inspired to do while playing with Processing 3’s sound library oscillators. The project starts with a blank screen and then blue circles begin to spawn in. All of the circles push each other away from each other. When you click the mouse on the screen it creates an orange circle. Over time that orange circle will change to blue, just like the rest. The orange circle will either become just like all of the other blue circles or be able to make it out (off the screen) being at least somewhat unique. The amount and placements of the orange circles influences the larger group in some interesting ways. The oscillators are tuned to minor chords that changed (or not changed) randomly and are there to provide a sort of soundtrack for the piece. This was done using Java in Processing 3. Source code below.
import processing.sound.*;
int count;
ArrayList<MCircle> circles;
TriOsc n1,n2,n3,n4;
float bpm;
int size;
void setup(){
size(1440,900);
//size(600,400);
noFill();
bpm = 80;
size = 120;
strokeWeight(5);
n1 = new TriOsc(this);
n2 = new TriOsc(this);
n3 = new TriOsc(this);
n4 = new TriOsc(this);
circles = new ArrayList<MCircle>();
setCm4();
stopPlay();
n1.play();
n2.play();
n3.play();
n4.play();
play(.1);
}
void draw(){
background(51);
if(count % 15 == 0){
circles.add(new MCircle(random(50,width-50),random(50,height-50), 10, false));
}
if(count % bpm == 0){
choseFreq();
}
for(MCircle c : circles){
if(c.getR()<=size){
c.setR(c.getR()+1.0);
}
}
for(MCircle c : circles){
for(MCircle d : circles){
if(d == c){
break;
}else{
c.setCol(c.collided(d));
c.update(d);
}
}
c.show();
}
for(int i = 0; i < circles.size(); i ++){
if(circles.get(i).offScreen()){
circles.remove(circles.get(i));
}
}
if(count % 20 == 0){
for(int i = 0; i < circles.size(); i ++){
circles.get(i).changeColor();
}
}
count ++;
if(count >= 10000){
count = 0;
}
}
void mousePressed(){
circles.add(new MCircle(mouseX,mouseY,10,true));
}
void choseFreq(){
switch(floor(random(0,8))){
case 0:
setCm3();
break;
case 1:
setCm4();
break;
case 2:
setDm4();
break;
case 3:
setEm3();
break;
case 4:
setFm3();
break;
case 5:
setGm3();
break;
case 6:
setAm3();
break;
case 7:
setBm3();
break;
}
}
void play(float amp){
n1.amp(amp);
n2.amp(amp);
n3.amp(amp);
n4.amp(amp);
}
void stopPlay(){
n1.amp(0);
n2.amp(0);
n3.amp(0);
n4.amp(0);
}
void setCm3(){
//c3, eb3, g3, c4
n1.freq(130.81);
n2.freq(155.56);
n3.freq(196.00);
n4.freq(261.63);
}
void setCm4(){
//c4, eb4, g4, c5
n1.freq(261.63);
n2.freq(311.13);
n3.freq(392.00);
n4.freq(523.25);
}
void setDm4(){
//d4, f4, a4, d5
n1.freq(293.66);
n2.freq(349.23);
n3.freq(440.00);
n4.freq(587.33);
}
void setEm3(){
//e3, g3, b3, e4
n1.freq(164.81);
n2.freq(196.00);
n3.freq(246.94);
n4.freq(329.63);
}
void setFm3(){
//f3, ab3, c4, f4
n1.freq(174.61);
n2.freq(207.65);
n3.freq(261.63);
n4.freq(349.23);
}
void setGm3(){
//g3, bb3, d4, g4
n1.freq(196.00);
n2.freq(233.08);
n3.freq(293.66);
n4.freq(392.00);
}
void setAm3(){
//a3, c4, e4, a4
n1.freq(220.00);
n2.freq(261.63);
n3.freq(329.63);
n4.freq(440.00);
}
void setBm3(){
//b3, d4, f#4, b4
n1.freq(246.94);
n2.freq(293.66);
n3.freq(369.99);
n4.freq(493.88);
}
class MCircle {
float x, y, r;
boolean collide;
float rate;
boolean clicked;
int timer;
color def, cl;
MCircle(float x_, float y_, float r_, boolean clicked_) {
x = x_;
y = y_;
r = r_;
clicked = clicked_;
rate = 1.5;
cl = color(200, 130, 80);
def = color(80, 130, 200);
}
void show() {
if (clicked) {
stroke(cl);
} else {
stroke(def);
}
ellipse(x, y, r, r);
}
void update(MCircle c) {
if (collide) {
if (x < c.x || x == c.x) {
if ((c.x-x) > (c.y-y)) {
x -= rate+.2;
c.x += rate+.2;
} else {
x -= rate;
c.x += rate;
}
} else if (x > c.x) {
if ((x-c.x) > (y-c.y)) {
x += rate+.2;
c.x -= rate+.2;
} else {
x += rate;
c.x -= rate;
}
}
if (y < c.y || y == c.y) {
if ((c.y-y) > (c.x-x)) {
y -= rate+rate;
c.y += rate+rate;
} else {
y -= rate;
c.y += rate;
}
} else if (y > c.y) {
if ((y-c.y) > (x-c.x)) {
y += rate+rate;
c.y -= rate+rate;
} else {
y += rate;
c.y -= rate;
}
}
if (!collided(c)) {
collide = false;
}
}
}
boolean offScreen() {
if (((x-r) > width)||((x+r) < 0)||((y-r) > height)||((y+r) < 0)) {
return true;
} else {
return false;
}
}
void setCol(boolean val) {
collide = val;
}
boolean collided(MCircle c) {
if (dist(x, y, c.x, c.y) < r+2) {
return true;
} else {
return false;
}
}
void changeColor() {
if (clicked) {
if (red(cl) != red(def)) {
float newR = red(cl)-1;
cl = color(newR, green(cl), blue(cl));
}
if (blue(cl) != blue(def)) {
float newB = blue(cl)+1;
cl = color(red(cl), green(cl), newB);
}
if ((red(cl) == red(def)) && (blue(cl) != blue(def))) {
timer = 0;
}
}
}
float getX() {
return x;
}
float getY() {
return y;
}
float getR() {
return r;
}
void setX(float nx) {
x = nx;
}
void setY(float ny) {
y = ny;
}
void setR(float nr) {
r = nr;
}
}