{
   "code" : "(\r\nServer.default.waitForBoot({\r\n\tSynthDef(\\SimpleHarmonicPing, { |out, freq, amp, sustain, pan|\r\n\t\tvar snd = BLowPass4.ar(Saw.ar(freq), freq*Line.kr(2, 1, sustain/4), 1);\r\n\t\tsnd = snd * EnvGen.ar(Env.perc(0.01, sustain), doneAction:2);\r\n\t\tOffsetOut.ar(out, Pan2.ar(snd, pan, amp))\r\n\t}).add;\r\n});\r\n~scale = Scale.chinese;\r\n~octave = 4;\r\n~sustain = 1.25;\r\n~root = 0;\r\n~mtranspose = 0;\r\n~ctranspose = 0;\r\n)\r\n\r\n(\r\nvar n = 7*2;\r\nvar w = 1024, h = 600;\r\nvar win = Window(\"\", Rect(100, 100, w, h)).front;\r\nvar uv = UserView(win, win.view.bounds);\r\nvar sinFunc = { |i, periode=2pi| sin((i/n)*periode) };\r\nvar lastValues = { 0 }.dup(n);\r\nuv.background = Color.black;\r\nuv.animate = true;\r\nuv.frameRate = 120;\r\nuv.drawFunc = { |uv|\r\n\tvar values = Array.fill(n, { |i| sinFunc.((i-1) + (uv.frame/100), uv.frame.linexp(1,60*(60*12), pi, 24pi)) }); // for 2 min\r\n\tQPen.strokeColor = Color.white;\r\n\tQPen.line( Point(0, h/2), Point(w, h/2) );\r\n\tQPen.stroke;\r\n\tQPen.fillColor = Color.red;\r\n\tQPen.use{\r\n\t\tQPen.translate(w/n/2,0);\r\n\t\tvalues.do{ |value, i|\r\n\t\t\tvar lastValue = lastValues[i];\r\n\t\t\tvar center = Point( (i/n) * w,  (h/2) + (value * (h/3)));\r\n\t\t\tQPen.fillOval(Rect.aboutPoint( center, 3, 3 ));\r\n\t\t\tif( ((lastValue < 0) and: { value > 0 }) or: { (lastValue > 0) and: { value < 0 } } ) {\r\n\t\t\t\tQPen.strokeColor = Color.white;\r\n\t\t\t\tQPen.strokeOval(Rect.aboutPoint( center, 5, 5) );\r\n\t\t\t\tQPen.strokeOval(Rect.aboutPoint( center, 10, 10) );\r\n\t\t\t\t(\r\n\t\t\t\t\tscale: ~scale,\r\n\t\t\t\t\tinstrument: \\SimpleHarmonicPing,\r\n\t\t\t\t\toctave: ~octave,\r\n\t\t\t\t\tdegree:i,\r\n\t\t\t\t\tamp:0.1,\r\n\t\t\t\t\tmtranspose: ~mtranspose,\r\n\t\t\t\t\tctranspose: ~ctranspose,\r\n\t\t\t\t\troot: ~root,\r\n\t\t\t\t\tsustain: ~sustain,\r\n\t\t\t\t\tpan:i.linlin(0,n,-1, 1),\r\n\t\t\t\t\tdetune:2.0.rand2,\r\n\t\t\t\t).play;\r\n\t\t\t\t\"trig %\".format(i).postln;\r\n\t\t\t};\r\n\t\t};\r\n\t};\r\n\tlastValues = values;\r\n};\r\n)",
   "id" : "1-4WL",
   "is_private" : null,
   "labels" : [
      "sine",
      "sinewaves",
      "simple harmonic motion"
   ],
   "ancestor_list" : [],
   "description" : "Was just trying to reproduce the simple harmonic motion videos i've been watching. I think this is a compact and yet flexible way where you are able to change the scale, octave, frequency, etc very easily.",
   "author" : "rukano",
   "name" : "Simple Harmonic Motion"
}
