{
   "labels" : [
      "graphic"
   ],
   "id" : "1-1HR",
   "is_private" : null,
   "code" : "//redFrik - bufferdisplay\r\n(\r\nl= 1024;\t\t\t\t\t\t\t\t//global window/buffer size in pixels/samples\r\ns.latency= 0.05;\r\ns.waitForBoot{\r\n\t\r\n\t//--variables\r\n\tvar theta= 0;\r\n\tvar fps= 60;\r\n\tvar arr= Array.fill(l, 0);\r\n\tvar cnt= 0;\r\n\t\r\n\t//--window setup\r\n\tvar width= l, height= l;\r\n\tvar w= Window(\"waveform\", Rect(99, 99, width, height), false);\r\n\tvar u= UserView(w, Rect(0, 0, width, height));\r\n\tvar w2= width*0.5;\r\n\tvar h2= height*0.5;\r\n\t\r\n\t//--buffer\r\n\tb= Buffer.alloc(s, l, 1);\r\n\ts.sync;\r\n\t\r\n\t//--interface\r\n\t~trails= 1;\r\n\t~speed= 0;\r\n\t~amp= 0.5;\r\n\t~version= 0;\r\n\t\r\n\t//--main loop\r\n\tu.drawFunc= {\r\n\t\t\r\n\t\t//uncomment framerate display in the two lines below to gain some speed\r\n\t\tPen.color= Color.white;\r\n\t\tPen.stringAtPoint(\"\"++u.frameRate, Point(10, 10));\r\n\t\t\r\n\t\t\r\n\t\t//--\r\n\t\tb.getn(0, b.numFrames-1, {|data| arr= data});\r\n\t\t\r\n\t\tif(cnt==0, {\r\n\t\t\tPen.fillColor= Color.black;\t//erase first time\r\n\t\t\tPen.fillRect(Rect(0, 0, width, height));\r\n\t\t});\r\n\t\t\r\n\t\tPen.fillColor= Color.grey(0, ~trails);\r\n\t\tPen.fillRect(u.bounds);\t\t\t//manually clear\r\n\t\tPen.strokeColor= Color.green;\r\n\t\t\r\n\t\tswitch(~version,\r\n\t\t\t0, {\t\t\t\t\t\t\t\t\t//line\r\n\t\t\t\tPen.rotate(theta, w2, h2);\r\n\t\t\t\tPen.translate(0, h2);\r\n\t\t\t\tarr.do{|y, x|\r\n\t\t\t\t\tvar p= Point(x, y*(height*~amp));\r\n\t\t\t\t\tif(x==0, {Pen.moveTo(p)}, {Pen.lineTo(p)});\r\n\t\t\t\t};\r\n\t\t\t\tPen.stroke;\r\n\t\t\t},\r\n\t\t\t1, {\t\t\t\t\t\t\t\t\t//warp\r\n\t\t\t\tPen.rotate(theta, w2, h2);\r\n\t\t\t\tPen.translate(w2, h2);\r\n\t\t\t\tarr.do{|y, x|\r\n\t\t\t\t\tvar p= Point(x*~amp, y*~amp).rotate(y*2pi);\r\n\t\t\t\t\tif(x==0, {Pen.moveTo(p)}, {Pen.lineTo(p)});\r\n\t\t\t\t};\r\n\t\t\t\tPen.stroke;\r\n\t\t\t},\r\n\t\t\t2, {\t\t\t\t\t\t\t\t\t//flower\r\n\t\t\t\tPen.translate(w2, h2);\r\n\t\t\t\tPen.moveTo(Point(arr[0], 0)*arr[0]);\r\n\t\t\t\tarr.do{|y, x|\r\n\t\t\t\t\tvar p= Point(y, x)*y;\r\n\t\t\t\t\tvar a= x%width/width*2pi+theta;\r\n\t\t\t\t\tPen.lineTo(p.rotate(a));\r\n\t\t\t\t};\r\n\t\t\t\tPen.stroke;\r\n\t\t\t}\r\n\t\t);\r\n\t\ttheta= theta+~speed;\r\n\t\tcnt= cnt+1;\r\n\t\t\r\n\t\t\r\n\t};\r\n\t\r\n\t//--window management\r\n\tu.clearOnRefresh= false;\t\t\t//do not erase - just draw on top of\r\n\tw.onClose= {\r\n\t\tb.free;\r\n\t};\r\n\tw.front;\r\n\tCmdPeriod.doOnce({if(w.isClosed.not, {w.close})});\r\n\tu.animate= true;\r\n};\r\n)\r\n\r\n\r\n//some synth that writes into the buffer\r\nv= {RecordBuf.ar(Saw.ar, b)}.play\r\n\r\n//change these while the program is running\r\n~trails= 0.2;\r\n~speed= 0.1;\r\n~speed= -0.05;\r\n~trails= 0.01;\r\n~amp= 0.02;\r\n~speed= pi*0.25;\r\n~amp= 0.2;\r\n~version= 1;\r\n~trails= 0.2;\r\n~version= 2;\r\n~version= 1;\r\n~speed= 2pi*1.001;\r\n~amp= 0.5;\r\nv.free;\r\n\r\nv= {RecordBuf.ar(SinOsc.ar(0, BPF.ar(VarSaw.ar(MouseX.kr(1, 1000, 1)), MouseY.kr(50, 5000, 1), 0.5)), b)}.play\r\n~version= 1;\r\n~trails= 0.01;\r\n~speed= -0.03;\r\n~speed= -0.05;\r\n~trails= 1;\r\n~amp= 0.5;\r\n~speed= 2pi*0.25;\r\n~trails= 0.1\r\n~amp= 0.2;\r\n~version= 2;\r\n~version= 0;\r\n~speed= 2pi*1.001;\r\n~amp= 10;\r\n~speed= 0;\r\nv.free",
   "author" : "redFrik",
   "name" : "bufferdisplay",
   "ancestor_list" : [],
   "description" : "works with both qt and cocoa.  i get a steady 60fps on my machine.  try lowering 'l= 1024' at the top if it's too heavy on your cpu."
}
