11.07.2015 Views

Advanced Programming Guide

Advanced Programming Guide

Advanced Programming Guide

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

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

236 • Chapter 6: <strong>Programming</strong> with Maple Graphicsthe sum plot example from section 6.3 by adding local information to theobjects. This section provides examples that describe how to program atthis lower level.Writing Graphic PrimitivesYou can write procedures that allow you to work with plot objects ata more fundamental level. For example, the line and disk commandsin the plottools package provide a model for programming primitivessuch as points, lines, curves, circles, rectangles, and arbitrary polygons inboth two and three dimensions. In all cases, you can specify options, suchas line or patch style and color, in the same format as in other plottingprocedures in Maple.Example 1 Inside the following procedure, nargs is the number ofarguments and args is the actual argument sequence. Thus, in line,args[3..nargs] is the sequence of arguments that follow x and y.> line := proc(x::list, y::list)> # x and y represent points in either 2-D or 3-D> local opts;> opts := [ args[3..nargs] ];> opts := convert( opts, PLOToptions );> CURVES( evalf( [x, y] ), op(opts) );> end proc:The convert(..., PLOToptions) command converts user-level optionsto the format that PLOT requires.> convert( [axes=boxed, color=red], PLOToptions );[AXESSTYLE(BOX ), COLOUR(RGB, 1.00000000, 0., 0.)]Example 2 The disk procedure is similar to the previous line procedureexcept that you can specify the number of points that disk usesto generate the disk. Therefore disk must handle the option, numpoints,separately. The hasoption command determines whether a certain optionis present.> disk := proc(x::list, r::algebraic)> # draw a disk of radius r centered at x in 2-D.> local i, n, opts, vertices;> opts := [ args[3..nargs] ] ;> if not hasoption( opts, numpoints, n, ’opts’ )> then n := 50;> end if;> opts := convert(opts, PLOToptions);

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

Saved successfully!

Ooh no, something went wrong!