Genetic Collision Network

OpenFrameworks application with Box2d Physics library, Genetic Algorithm and Osc comunications.
The particles represent the population of the genetic algorithm, when a collision occur, a new generation will start.

GenoTypes

  • Width
  • Height
  • Depth

The Radius of the particle is obtained as follow :

Area = Width x Height;

Radius = sqrt(Area/PI)

The size of the particle is directly connected to the frequency of the sound.

Fitness Function

The algorithm attempts to maximize the square side lengths while minimizing the volume.

Code


c = GeneticCollisonNet.new(\gen,100,4000)

//CLASS
GeneticCollisonNet{
var <>oscListener,<>oscListener_edge;
*new { arg osc_address,lo,hi;
^super.new.init(osc_address,lo,hi);
}
init_synth{
(
SynthDef(\bell, { |outbus=0, trig = 1, sing_switch = 0, freq = 243, amp = 0.5, rel = 3,pan=0|
var sig, input, first, freqscale, mallet, sing,frqs,amps,rings;
freqscale = freq / freq;
freqscale = Lag3.kr(freqscale, rel);
rel = Lag3.kr(rel, rel);

mallet = LPF.ar(Trig.ar(trig, SampleDur.ir)!2, 10000 * freqscale);
sing = LPF.ar(
LPF.ar(
{
BrownNoise.ar * Integrator.kr(sing_switch * 0.001, 0.999).linexp(0, 1, 0.01, 1) * amp
} ! 2,
freq * freqscale
) + Dust.ar(0.1), 10000 * freqscale
) * LFNoise1.kr(0.5).range(-45, -30).dbamp;
input = mallet + (sing_switch.clip(0, 1) * sing);
frqs = Array.series(12,freq,rrand(25,30));
amps = Array.rand(12,0.1,1);
rings = Array.rand(12,0.1,rel);
sig = Pan2.ar(DynKlank.ar(`[frqs,amps,rings], input, freqscale, 0, rel),pan);
sig = LPF.ar(sig,freq);
DetectSilence.ar(sig, doneAction: 2);
Out.ar(outbus, sig);
}).add;
)
}
init {arg osc_address,lo,hi;
var frq,rel,trig,pan;
this.init_synth;
“> Starting Osc…”.postln;
oscListener = OSCresponder.new(nil, osc_address , { |time, resp, msg|
msg.postln;
frq = msg[2].linexp(0.1,1.0,lo,hi);
frq.postln;
rel = msg[2].linexp(0.1,1.0,0.1,0.6);
pan = msg[4];
Synth(\bell,[\trig,0.1,\freq,frq,\rel,rel,\pan,pan]);
}).add;
“> Listening address: “.post;
osc_address. postln;
}
}