(
	var color=Color.new(0,0,0,0.5), colors, sz=1;
	colors = [[0,0,1],[0,0.5,1],[0,1,1],[0,1,0.5],[0,1,0],[0.5,1,0],
		[1,1,0],[1,0.5,0],[1,0,0],[1,0,0.5],[1,0,1],[0.5,0,1]];

	SynthDef("synth", {arg out=0, freq=220, amp=0, width=0.5, pan=0, mod=1;
		var osc;
		
		osc = Pulse.ar(Slew.kr(freq,400,400), width, amp).distort*0.75;
		//osc = osc * EnvGen.kr(Env.perc(0,0.1), Dust.kr(amp*freq));
		osc = BPF.ar(osc, SinOsc.kr(2/mod,0,500,1000));
		osc = Pan2.ar(osc, pan);
		Out.ar(out, osc);
	}).store;
	
	a = Synth.new("synth");
	
	b = SCWindow("Boxes", Rect(50, 200, 1200, 690));
	b.view.decorator = FlowLayout(b.view.bounds);
	b.view.background = Color.white;
	b.drawHook = { |me| var pix=9.29687*sz; Pen.use{
		
		(73/sz).do{ arg i;
			(64/sz).do{ arg j;
				Pen.fillColor = color.vary(alphaVal: 0.5);
				Pen.addRect(Rect((j*pix)+5,(i*pix)+5,pix,pix));
				Pen.fill;
		};};
		(64/sz).do{ arg j;
			Pen.fillColor= color.vary(alphaVal: 0.5);
			Pen.addRect(Rect((j*pix)+5,((73/sz).floor*pix)+5,pix,(680-((73/sz).floor*pix))));
			Pen.fill;
		};

	};};
	
	c = SCEnvelopeView(b, Rect(0, 0, 1190, 680))
		.thumbWidth_(150)
		.thumbHeight_(150)
		.drawLines_(false)
		.drawRects_(true)
		.selectionColor_(Color.black)
		.value_([[0.5,0.5,0.5],[0.5,0.5,0.5]])
		.setFillColor(-1, Color.black)
		.connect(1, [0]).setThumbWidth(1, 140).setThumbHeight(1, 140)
		.connect(2, [0]).setThumbWidth(2, 130).setThumbHeight(2, 130);
	
	c.action_({|boxes| 
		var b1, b2, b3, d12, d13, a12, a13, d23, freq, col;
		
		b1 = Point.new(boxes.value[0][0], boxes.value[1][0]);
		b2 = Point.new(boxes.value[0][1], boxes.value[1][1]);
		b3 = Point.new(boxes.value[0][2], boxes.value[1][2]);
		
		d12 = (((b1.y-b2.y).squared)+((b1.x-b2.x).squared)).sqrt;
		d13 = (((b1.y-b3.y).squared)+((b1.x-b3.x).squared)).sqrt;
		d23 = (((b2.y-b3.y).squared)+((b2.x-b3.x).squared)).sqrt;
		
		a12 = atan2((b2.x-b1.x).abs,(b2.y-b1.y).abs);
		a13 = atan2((b3.x-b1.x),(b3.y-b1.y).abs);
		
		freq = (((d12*700)+55).cpsmidi + 0.5).floor;
		
		a.set(\freq,freq.midicps,\amp,(d13*2/3),\width,((a12/pi)+0.3),\pan,(a13/pi),\mod,(d23*10));
		c.setString(1, freq.asString);
		
		col = colors[(freq%12)]*(freq/85);
		color = Color.new(col[0],col[1],col[2]);
		
		sz = 2**(((((d13)*2/3)/0.15).floor));
	});
	
	b.front;
	
	r = Routine({ while(true, {b.refresh; 0.1.wait; })});
	AppClock.play(r);
)