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.

6.9 <strong>Programming</strong> with Color • 283> points := seq( evalf([ [i/n, 0], [i/n, 1],> [(i+1)/n, 1], [(i+1)/n, 0] ]),> i=0..n-1):> flatten := a -> op( map(op, a) );> grays := COLOUR(RGB, flatten(> [ seq( evalf([ F(i/n), F(i/n), F(i/n) ]),> i=1.. n)]));> PLOT( POLYGONS(points, grays),> AXESTICKS(DEFAULT, 0) );> end proc:The identity function, x ↦→ x, yields the basic gray scale.> colormapGraylevel( x->x, 20);0.2 0.4 0.6 0.8 1Adding Color Information to PlotsYou can add color information to an existing plot data structure.Example The procedure addCurvecolor colors each curve in a CURVESfunction via the scaled y coordinates.> addCurvecolor := proc(curve)> local i, j, N, n , M, m, curves, curveopts, p, q;>> # Get existing point information.> curves := select( type, [ op(curve) ],> list(list(numeric)) );> # Get all options but color options.> curveopts := remove( type, [ op(curve) ],> { list(list(numeric)),> specfunc(anything, COLOR),> specfunc(anything, COLOUR) } );>> # Determine the scaling.> # M and m are the max and min of the y-coords.> n := nops( curves );> N := map( nops, curves );> M := [ seq( max( seq( curves[j][i][2],> i=1..N[j] ) ), j=1..n ) ];> m := [ seq( min( seq( curves[j][i][2],

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

Saved successfully!

Ooh no, something went wrong!