Index: work/scripts/graphics.awk =================================================================== --- work/scripts/graphics.awk (nonexistent) +++ work/scripts/graphics.awk (revision 20085) @@ -0,0 +1,163 @@ +# draw ruled graphs, spirals, and regular conv polygons for pcb-rnd + +function rules(xcoord,ycoord,size, lines) +{ + # take the list of values.... get the interval from size/lines + x = xcoord + y = ycoord + for (i=0; i < size+0; i++){ + ddraft("line from " x "," y " to " x "," y + size ) + ddraft("line from " x "," y " to " x+size "," y ) + ddraft("line from " x "," y + size " to " x + size "," y + size) + ddraft("line from " x "," y + size - i " to " x + size - i "," y + size) + ddraft("line from " x + size "," y + size - i " to " x + size - i "," y) + } +} + +# spiral from x,y pos, and inradius does nothing +function a_spiral(xcen ,ycen, radius, inradius, turns, deg_offset) +{ + 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 + } +} + +# 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){ + ddraft("line from " x "," y " to " xn "," yn ) + spiral_length += sqrt((xn-x)^2 + (yn-y)^2) + } + x = xn + y = yn + } + message("spiral length is: " spiral_length) +} + +# 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 ) + x = 0 + y = 0 + xsum = x + ysum = y + angle = deg_to_rad(rot_angle) + #validation checks: min. sides, draw location checks, input checks (apo or circum, etc) + if (sides+0 <= 2) { + message ("number of sides must be greater than 2") + return 0 + } + # check if too many inputs exist, make sure the others don't + if (circumradius != ""){ + if (side_length != 0 ){ + message ("give one input total for inputs side_length and circumradius") + return 0 + } + radius = circumradius + message ("radius from circumradius: " radius) + } + else if (side_length != ""){ + radius = side_length / (2*sin(3.141592654/ ( 2 * sides) ) ) + message ("radius from side_length: " radius) + } + for (i = 0 ; i < sides+0 ; i++){ + angle += segment_angle + xn = x + cos(angle)*radius + yn = y + sin(angle)*radius + xsum = xsum + x + ysum = ysum + y + xvert[i] = x + yvert[i] = y + x = xn + y = yn + } + if ( xcen - (xsum/sides) < 1 ){ + return 0 + } + for (i in xvert){ + ddraft("line from " xcen + xvert[i] - (xsum/sides) "," ycen + yvert[i] - (ysum/sides) " to " xcen + xvert[i+1] - (xsum/sides) "," ycen + yvert[i+1] - (ysum/sides) ) + } + delete xvert + delete yvert +} + +# other funcition ideas -- oval (coefficients for x or y) +# square with curved corners (can we draw arcs yet?) +# line spirals (square spirals) + +function deg_to_rad(angle){ + rad = ( angle * 2 * 3.14159264 ) / 360 + return rad + } + + +BEGIN { + fgw_func_reg("rules") + fgw_func_reg("spiral_by_turns") + fgw_func_reg("spiral_by_length") + fgw_func_reg("drawpoly") +}