##- # Authors: Ralph Griswold, Clinton L. Jeffery, Gregg M. Townsend # Updated: Brian Tiffin # Dedicated to the public domain # # Date: 1998 # Modified: 2016-10-03/22:56-0400 ##+ # # linedrawing.icn, from the Graphics Programming in Icon book # # Draw a regular polygon with the specified number of vertices and # radius, centered at (cx,cy). # procedure main() &window := open("linedrawing", "g", "size=200,200", "canvas=hidden") | stop("Cannot open graphics window") Fg("vivid orange") rpolystars(100, 100, 90, 8) Fg("blue") rpolystars(100, 100, 90, 8, 3) WSync() WriteImage("../images/linedrawing.png") close(&window) end procedure rpolystars(cx, cy, radius, vertices, skips) local theta, incr, xprev, yprev, x, y theta := 0 # initial angle /skips := 1 incr := skips * 2 * &pi / vertices xprev := cx + radius * cos(theta) # initial position yprev := cy + radius * sin(theta) every 1 to vertices do { theta +:= incr x := cx + radius * cos(theta) # new position y := cy + radius * sin(theta) DrawLine(xprev, yprev, x, y) xprev:= x # update old position yprev:= y } return end