## plplot-cvs

 [Plplot-cvs] SF.net SVN: plplot:[11600] trunk/examples/lua/x27.lua From: - 2011-03-06 00:26:07 ```Revision: 11600 http://plplot.svn.sourceforge.net/plplot/?rev=11600&view=rev Author: airwin Date: 2011-03-06 00:26:01 +0000 (Sun, 06 Mar 2011) Log Message: ----------- Add fill pages to the 27th lua example to make the results consistent with the corresponding C example. Modified Paths: -------------- trunk/examples/lua/x27.lua Modified: trunk/examples/lua/x27.lua =================================================================== --- trunk/examples/lua/x27.lua 2011-03-05 20:42:22 UTC (rev 11599) +++ trunk/examples/lua/x27.lua 2011-03-06 00:26:01 UTC (rev 11600) @@ -25,52 +25,70 @@ dofile("plplot_examples.lua") +-------------------------------------------------------------------------- +-- Calculate greatest common divisor following pseudo-code for the +-- Euclidian algorithm at http://en.wikipedia.org/wiki/Euclidean_algorithm + +function gcd (a, b) + a = math.floor(math.abs(a)) + b = math.floor(math.abs(b)) + while b~=0 do + t = b + b = math.mod(a,b) + a = t + end + return a +end + function cycloid() -- TODO end -function spiro( params ) - NPNT = 20000 +function spiro( params, fill ) + NPNT = 2000 xcoord = {} ycoord = {} -- Fill the coordinates - windings = params[4] + -- Proper termination of the angle loop very near the beginning + -- point, see + -- http://mathforum.org/mathimages/index.php/Hypotrochoid. + windings = math.floor(math.abs(params[2])/gcd(params[1], params[2])) steps = math.floor(NPNT/windings) - dphi = 8*math.acos(-1)/steps + dphi = 2*math.pi/steps - xmin = 0 -- This initialisation is safe! - xmax = 0 - ymin = 0 - ymax = 0 - for i = 1, windings*steps+1 do phi = (i-1) * dphi phiw = (params[1]-params[2])/params[2]*phi xcoord[i] = (params[1]-params[2])*math.cos(phi) + params[3]*math.cos(phiw) ycoord[i] = (params[1]-params[2])*math.sin(phi) - params[3]*math.sin(phiw) + if i == 1 then + xmin = xcoord[i] + xmax = xcoord[i] + ymin = ycoord[i] + ymax = ycoord[i] + end if xmin>xcoord[i] then xmin = xcoord[i] end if xmaxycoord[i] then ymin = ycoord[i] end if ymax(ymax-ymin) then - scale = xmax - xmin - else - scale = ymax - ymin - end - xmin = -0.65*scale - xmax = 0.65*scale - ymin = -0.65*scale - ymax = 0.65*scale + xmin = xmin - 0.15*(xmax-xmin) + xmax = xmax + 0.15*(xmax-xmin) + ymin = ymin - 0.15*(ymax-ymin) + ymax = ymax + 0.15*(ymax-ymin) pl.wind(xmin, xmax, ymin, ymax) pl.col0(1) - pl.line(xcoord, ycoord) + if fill == 1 then + pl.fill(xcoord, ycoord) + else + pl.line(xcoord, ycoord) + end end @@ -83,6 +101,11 @@ ---------------------------------------------------------------------------- -- R, r, p, N +-- R and r should be integers to give correct termination of the +-- angle loop using gcd. +-- N.B. N is just a place holder since it is no longer used +-- (because we now have proper termination of the angle loop). + params = { { 21, 7, 7, 3 }, -- Deltoid { 21, 7, 10, 3 }, @@ -110,10 +133,11 @@ pl.ssub(3, 3) -- Three by three window +fill = 0 for i = 1, 9 do pl.adv(0) pl.vpor(0, 1, 0, 1) - spiro(params[i]) + spiro(params[i], fill) end pl.adv(0) @@ -122,8 +146,18 @@ for i = 1, 9 do pl.adv(0) pl.vpor(0, 1, 0, 1) - spiro(params[i]) + spiro(params[i], fill) end --- Don't forget to call plend() to finish off! +-- fill the curves. +fill = 1 +pl.adv(0) +pl.ssub(1, 1) -- One window per curve + +for i = 1, 9 do + pl.adv(0) + pl.vpor(0, 1, 0, 1) + spiro(params[i], fill) +end + pl.plend() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```
 [Plplot-cvs] SF.net SVN: plplot:[11858] trunk/examples/lua/x27.lua From: - 2011-08-05 07:45:41 ```Revision: 11858 http://plplot.svn.sourceforge.net/plplot/?rev=11858&view=rev Author: andrewross Date: 2011-08-05 07:45:34 +0000 (Fri, 05 Aug 2011) Log Message: ----------- Update lua version of example 27 to include plarc demo. Modified Paths: -------------- trunk/examples/lua/x27.lua Modified: trunk/examples/lua/x27.lua =================================================================== --- trunk/examples/lua/x27.lua 2011-08-04 23:34:19 UTC (rev 11857) +++ trunk/examples/lua/x27.lua 2011-08-05 07:45:34 UTC (rev 11858) @@ -94,6 +94,34 @@ end +function arcs() + NSEG = 8 + + theta = 0.0 + dtheta = 360.0 / NSEG + pl.env( -10.0, 10.0, -10.0, 10.0, 1, 0 ) + + -- Plot segments of circle in different colors + for i = 0, NSEG-1 do + pl.col0( i%2 + 1 ) + pl.arc(0.0, 0.0, 8.0, 8.0, theta, theta + dtheta, 0.0, 0) + theta = theta + dtheta + end + + -- Draw several filled ellipses inside the circle at different + -- angles. + a = 3.0 + b = a * math.tan( (dtheta/180.0*math.pi)/2.0 ) + theta = dtheta/2.0 + for i = 0, NSEG-1 do + pl.col0( 2 - i%2 ) + pl.arc( a*math.cos(theta/180.0*math.pi), a*math.sin(theta/180.0*math.pi), a, b, 0.0, 360.0, theta, 1) + theta = theta + dtheta + end + +end + + ---------------------------------------------------------------------------- -- main -- @@ -162,4 +190,6 @@ spiro(params[i], fill) end +arcs() + pl.plend() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ```