Index: graphics.awk =================================================================== --- graphics.awk (revision 20748) +++ graphics.awk (revision 20749) @@ -14,72 +14,23 @@ } } -# spiral from x,y pos, and inradius does nothing -function a_spiral(xcen ,ycen, radius, inradius, turns, deg_offset) +# Archimedean spirals +function a_spiral(xcen ,ycen, radius, inradius, turns, sides, phase) { - x = xcen - y = ycen - angle = turns * 2 * 3.141592654 - phi = deg_to_rad(deg_offset) - factor = 24 - interval = angle*factor - theta = 0 - for (i=0 ; i < interval+0; i++ ){ - theta += 1/factor - message("theta is: " theta) - message("interval is: " interval) - xn = x + (theta*radius)/(interval)*cos(theta + phi) - yn = y + (theta*radius)/(interval)*sin(theta + phi) - ddraft("line from " x "," y " to " xn "," yn ) - x = xn - y = yn + if (sides+0 < 3){ + message ("must have 3 or more sides") + return 0 } -} - -# function for spirals defined with annular ring and # of turns -function spiral_by_turns(xcen ,ycen, radius, inradius, turns, deg_offset,xrad,yrad) -{ x = xcen y = ycen - phi = deg_to_rad(deg_offset) - factor = 24 - theta = 0 - if (xrad == ""){ - xrad = 1 - } - if (yrad == ""){ - yrad = 1 - } - if (inradius > 0 ){ - if (inradius == radius){ - message ("inradius cannot be equal to radius") - return 0 - } - annular_turns = turns - full_turns = turns*radius/(radius-inradius) - offset = (full_turns - annular_turns) * 2 *3.141592654 - } - else { - annular_turns = 0 - full_turns = turns - offset = 0 - } - angle = full_turns * 2 * 3.141592654 - interval = angle*factor - message ("xrad:" xrad) - spiral_length = 0 - for (i= 0 ; i < interval -1 ; i++ ){ - theta += 1/factor - if (theta < offset){ - ignore = 1 - } - else if (theta >= offset){ - ignore = 0 - } - message("ignore is: " ignore) - xn = x + xrad*(theta*radius)/(interval)*cos(theta + phi) - yn = y + yrad*(theta*radius)/(interval)*sin(theta + phi) - if (!ignore){ + steps = sides * turns + phi = deg_to_rad(phase) + for (i=0 ; i <= steps; i++ ){ + r = inradius + (i*(radius - inradius))/steps + angle = 2 * 3.141592654 * i/sides + xn = xcen + r * cos(angle + phi) + yn = ycen + r * sin(angle + phi) + if ( i > 0) { ddraft("line from " x "," y " to " xn "," yn ) spiral_length += sqrt((xn-x)^2 + (yn-y)^2) } @@ -87,17 +38,11 @@ y = yn } message("spiral length is: " spiral_length) + spiral_length = 0 } -# spiral defined with spiral_length instead of # of turns -function spiral_by_length(xcen ,ycen, radius, inradius, spiral_length, deg_offset) -{ - -} - function drawpoly(xcen,ycen, sides, side_length, circumradius,rot_angle) # side_length, rot_deg, apothem, circumradius) { - # setups pi = 3.141592654 segment_angle = 2*3.14159264/sides message("segment angle is: " segment_angle ) @@ -135,7 +80,9 @@ x = xn y = yn } - if ( xcen - (xsum/sides) < 1 ){ + if ( xcen - circumradius < 1 || ycen - circumradius < 1 ){ + message("xcen: " xcen) + message("xsum/sides: " xsum/sides) return 0 } for (i in xvert){ @@ -157,7 +104,6 @@ BEGIN { fgw_func_reg("rules") - fgw_func_reg("spiral_by_turns") - fgw_func_reg("spiral_by_length") + fgw_func_reg("a_spiral") fgw_func_reg("drawpoly") }