11.07.2015 Views

Advanced Programming Guide

Advanced Programming Guide

Advanced Programming Guide

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

6.5 <strong>Programming</strong> with the plottools Package • 249Example 1 You can tile the plane with a and b type rectangles. Thefollowing procedure creates a m×n tiling using a function, g, to determinewhen to use an a-tile and when to use a b-tile. The function g returnseither 0, to use an a-tile, or 1, to use a b-tile.> tiling := proc(g, m, n)> local i, j, r, h, boundary, tiles;>> # define an a-tile> r[0] := plottools[arc]( [0,0], 0.5, 0..Pi/2 ),> plottools[arc]( [1,1], 0.5, Pi..3*Pi/2 );> # define a b-tile> r[1] := plottools[arc]( [0,1], 0.5, -Pi/2..0 ),> plottools[arc]( [1,0], 0.5, Pi/2..Pi );> boundary := plottools[curve]( [ [0,0], [0,n],> [m,n], [m,0], [0,0]] );> tiles := seq( seq( seq( plottools[translate](h, i, j),> h=r[g(i, j)] ), i=0..m-1 ), j=0..n-1 );> plots[display]( tiles, boundary, args[4..nargs] );> end proc:Define the following procedure, which randomly returns ei-Example 2ther 0 or 1.> oddeven := proc() rand() mod 2 end proc:Create a 20 × 10 tiling (called a Truchet tiling) with no axes andconstrained scaling.> tiling( oddeven, 20, 10, scaling=constrained, axes=none);When you use the same procedure again, the random tiling is different.> tiling( oddeven, 20, 10, scaling=constrained, axes=none);

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!