##- # Author: Brian Tiffin # Dedicated to the public domain # # Date: August 2016 # Modified: 2016-10-03/23:10-0400 ##+ # # plot-function, trigonometric plotting, function from command line # $define points 300 $define xoff 4 $define base 64 $define yscale 60 $define xscale 100 invocable "sin", "cos", "tan" # plot the given function, default to sine procedure main(args) func := map(args[1]) | "sin" if not func == ("sin" | "cos" | "tan") then func := "sin" # range of pixels for 300 points, y scaled at +/- 60, 4 pixel margins &window := open("Plotting", "g", "size=308,128", "canvas=hidden") # tan may cause runtime errors if func == "tan" then &error := 6 color := "vivid orange" Fg(color) write(&window, "\n " || func) Fg("gray") DrawLine(2, 64, 306, 64) DrawLine(2, 2, 2, 126) DrawString(8, 10, "1", 8, 69, "0", 2, 126, "-1") DrawString(270, 76, left(points * 2 * &pi / 100, 6)) Fg(color) every x := 0 to points do DrawPoint(xoff + x, base + yscale * func((2 * &pi * x) / xscale)) WSync() WriteImage("../images/plot-" || func || ".png") close(&window) end