«Simple animated 2D user interface» by rukano
on 29 May'12 01:45 inA more simple example using the shared memory interface to get the current status of a bus, and also setting a bus from the GUI. The circle turns red depending on the oscillator value, and the oscillator frequency and amplitude are controlled by the x, y position of the circle in the window.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
// needs shared memory interface (SC 3.5+) Server.default = s = Server.local; s.waitForBoot{ if (s.hasShmInterface) { w = Window().front; u = UserView(w, w.view.bounds); f = { |x, y| var size = 20 + (y/4); k = k.center_(Point(x, y)); k = k.size_(Size(size, size)); b.setSynchronous(x.linlin(0,u.bounds.width, 1/4, 16)); c.setSynchronous(50*(y/4)); }; w.onClose = { Ndef(\sound).end(1) }; u.background = Color.blue(0.5); u.animate = true; k = Rect(100, 100, 50, 50); u.drawFunc = { var osc = Ndef(\osc).bus.getSynchronous * 0.5 + 0.5; Pen.strokeColor = Color.blue; Pen.addOval(k); Pen.fillRadialGradient( k.center, k.center, k.width/8, k.width, Color(1,1,1,0), Color(1,0,0,osc) ); }; u.mouseMoveAction = { |u, x, y| f.(x, y) }; u.mouseDownAction = { |u, x, y| f.(x, y) }; b = Bus.control(s); c = Bus.control(s); b.setSynchronous(4); c.setSynchronous(500); Ndef(\osc, { SinOsc.kr(b.kr) }); Ndef(\sound).fadeTime = 1; Ndef(\sound, { MoogFF.ar(LFSaw.ar(50+[0,1]), Ndef(\osc).kr.linexp(-1,1,50,c.kr)) }).play; } { "get SC 3.5 or higher ;)".warn; }; };
descendants
full graph
«Re: Simple animated 2D user interface» by Don Smith (private)
reception
comments