Submit
Browse
Anonymous
Login
RSS
SuperCollider Code
Fork Code: Visual demonstration of aliasing/foldover
name
code content
( var screen = Window.screenBounds, height = (screen.height * 0.8).asInteger, width = (screen.width * 0.8).asInteger, win = Window(\aliasing, Rect.aboutPoint(screen.center, width / 2, height / 2 + 20)), sinPts = 400, sampPts = 20, freq = 1, fsl, sinColor = Color.red, sampColor = Color.black; win.drawHook = { var pt; pt = Point(0, height/2); Pen.color_(sampColor) .moveTo(pt); (1..sampPts).do { |x| Pen.moveTo(pt); pt = Point(x * (width / sampPts), sin(x * freq / sampPts * 2pi).linlin(-1, 1, height, 0)); Pen.lineTo(pt).stroke .fillRect(Rect.aboutPoint(pt, 3, 3)); }; Pen.color_(sinColor) .moveTo(Point(0, height/2)); (1..sinPts).do { |x| Pen.lineTo(Point( x * (width / sinPts), sin(x * freq / sinPts * 2pi).linlin(-1, 1, height, 0) )); }; Pen.stroke; }; fsl = EZSlider(win, Rect(5, height+10, width-10, 20), "freq:", [1, 20], { |view| freq = view.value; win.refresh }, 1, initAction: true); win.front; )
code description
I needed to demonstrate the importance of the Nyquist frequency to a class, so I wrote this visual, interactive demonstration. Use the slider at the bottom to set the frequency -- 1.0 corresponds to one cycle shown in the window. Tested with Qt and Swing GUIs. Should work in cocoa, but not tested.
use markdown for formating
category tags
comma separated, i.g. "wild, siren" (do not enter default SC class names, please)
ancestor(s)
comma separated identificators, i.g. "1-C,1-1,1-4M,1-x"
Private?
the code will be accessible by direct url and not visible in public activity
signup to submit public code without captcha
comment of change