{
   "labels" : [
      "educational",
      "gui",
      "theory",
      "nyquist",
      "aliasing",
      "pen",
      "graphic"
   ],
   "id" : "1-10",
   "is_private" : null,
   "code" : "(\r\nvar screen = Window.screenBounds,\r\n\theight = (screen.height * 0.8).asInteger,\r\n\twidth = (screen.width * 0.8).asInteger,\r\n\twin = Window(\\aliasing, Rect.aboutPoint(screen.center, width / 2, height / 2 + 20)),\r\n\tsinPts = 400, sampPts = 20,\r\n\tfreq = 1, fsl,\r\n\tsinColor = Color.red, sampColor = Color.black;\r\n\r\nwin.drawHook = {\r\n\tvar pt;\r\n\tpt = Point(0, height/2);\r\n\tPen.color_(sampColor)\r\n\t\t.moveTo(pt);\r\n\t(1..sampPts).do { |x|\r\n\t\tPen.moveTo(pt);\r\n\t\tpt = Point(x * (width / sampPts), sin(x * freq / sampPts * 2pi).linlin(-1, 1, height, 0));\r\n\t\tPen.lineTo(pt).stroke\r\n\t\t\t.fillRect(Rect.aboutPoint(pt, 3, 3));\t\t\r\n\t};\r\n\r\n\tPen.color_(sinColor)\r\n\t\t.moveTo(Point(0, height/2));\r\n\t(1..sinPts).do { |x|\r\n\t\tPen.lineTo(Point(\r\n\t\t\tx * (width / sinPts),\r\n\t\t\tsin(x * freq / sinPts * 2pi).linlin(-1, 1, height, 0)\r\n\t\t));\r\n\t};\r\n\tPen.stroke;\r\n};\r\n\r\nfsl = EZSlider(win, Rect(5, height+10, width-10, 20), \"freq:\", [1, 20], { |view| freq = view.value; win.refresh }, 1, initAction: true);\r\n\r\nwin.front;\r\n)",
   "author" : "jamshark70",
   "name" : "Visual demonstration of aliasing/foldover",
   "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.\r\n\r\nTested with Qt and Swing GUIs. Should work in cocoa, but not tested.",
   "ancestor_list" : []
}
