RedConstruct a constructive constructor



can be used for drawing or as lfos.  from old f0.construct max external and Construct2 java class.


*new(bounds, variant, mapping, cols, rows, movementX, movementY, stepX, stepY)

these arguments can also be functions.

bounds - Rect

variant - Integer (1-6)

mapping - Integer (1-16)

cols - 

rows - 

movementX - Float (default 0.95)

movementY - Float (default 0.95)

stepX - Float (default 1)

stepY - Float (default 1)

init

reset values

next(n= 1)

calculate and return new points.

n - iterations



/*

GUI.swing;

GUI.cocoa;

*/


a= RedConstruct.new;

a.next //return an array of points



//--drawing the points - 'press space'

(

var clear= false, speed= 1;

var a= RedConstruct.new;

var w= Window("construct", Rect(100, 100, 320+100, 240+100), false);

var u= UserView(w, Rect(0, 0, w.bounds.width, w.bounds.height));

u.background= Color.white;

u.keyDownAction= {|v, x| if(x==$ , {clear= true; a.init(argCols:{[8.rand, 100].choose})})};

u.clearOnRefresh= false;

u.focus;

u.drawFunc= {

if(clear, {

clear= false;

Pen.fillColor= Color.white;

Pen.fillRect(u.bounds);

});

Pen.setSmoothing(false);

Pen.strokeColor= Color.black;

Pen.translate(50, 50);

a.next(speed).do{|x| Pen.line(x, x+#[0, 0.5])};

Pen.stroke;

};

Routine({while({w.isClosed.not}, {u.refresh; (1/30).wait})}).play(AppClock);

w.front;

"press 'space' to generate new pattern";

)



//--example with sound - 'press space'

(

s.waitForBoot{

var clear= false, speed= 3;

var a= RedConstruct(Rect(0, 0, 640, 480));

var w= Window("redConstruct", Rect(100, 100, 640, 480), false);

var u= UserView.new(w, Rect(0, 0, w.bounds.width, w.bounds.height));

var reset= {

a.init(

argCols:{[6, 30].linrand.choose+1},

argRows:{[4, 20].linrand.choose+1},

argMovementX:{(1-[0.5, 0.1, 0].linrand.choose)},

argMovementY:{1-[0.5, 0.1, 0].linrand.choose},

argStepX:{[0.4, 0.1, 0].bilinrand.choose+1},

argStepY:{[0.4, 0.1, 0].bilinrand.choose+1}

);

};

var b= Buffer.alloc(s, w.bounds.width+1, 1);

var syn1, syn2;

SynthDef(\redConstruct, {|out= 0, bufnum, pan= 0, t_trig= 1|

var r= TRand.kr(0, 1.5, t_trig);

var z= BufRd.ar(1, bufnum, Phasor.ar(0, r*pan, 0, BufFrames.ir(bufnum)));

Out.ar(out, Pan2.ar(LeakDC.ar(z, 0.9999), pan, 0.7));

}).send(s);

reset.value;

w.onClose= {b.free};

u.background= Color.white;

u.keyDownAction_{|v, x|

if(x==$ , {

clear= true;

reset.value;

syn1.set(\t_trig, 1);

syn2.set(\t_trig, 1);

});

};

u.clearOnRefresh= false;

u.focus;

u.drawFunc= {

if(clear, {

clear= false;

Pen.fillColor= Color.white;

}, {

Pen.fillColor= Color.grey(1, 0.01);

});

Pen.fillRect(u.bounds);

Pen.setSmoothing(false);

Pen.strokeColor= Color.red;

a.next(speed).do{|p|

b.set(p.x.clip(0, w.bounds.width), p.y/w.bounds.height);

if(GUI.scheme.name=='SwingGUI', {

Pen.line(p, p+#[0.5, 0.5]);

}, {

Pen.line(p, p);

});

};

Pen.stroke;

};

Routine({

0.5.wait;

syn1= Synth(\redConstruct, [\bufnum, b.bufnum, \pan, -1]);

syn2= Synth(\redConstruct, [\bufnum, b.bufnum, \pan, 1]);

w.front;

while({w.isClosed.not}, {

u.refresh;

(1/30).wait;

});

}).play(AppClock);

"press 'space' to generate new pattern";

})