ergetgetagt

Page 156

Chapter 8: Base modules

151

real f(real x, real y) {return x^2-y^2;} int n=10; real[] c=new real[n]; for(int i=0; i < n; ++i) c[i]=(i-n/2)/n; pen[] p=sequence(new pen(int i) { return (c[i] >= 0 ? solid : dashed)+fontsize(6pt); },c.length); Label[] Labels=sequence(new Label(int i) { return Label(c[i] != 0 ? (string) c[i] : UnFill(1bp)); },c.length);

"",Relative(unitrand()),(0,0),

draw(Labels,contour(f,(-1,-1),(1,1),c),p); -0.5

-0.1

-0.3 -0.2 -0.4 0.2 0.3

0.1

0.4 0.4

0.3

0.1 0.2 -0.4 -0.2 -0.3 -0.5

-0.1

The next example illustrates how contour lines can be drawn on color density images: import graph; import palette; import contour; size(10cm,10cm,IgnoreAspect); pair a=(0,0); pair b=(2pi,2pi); real f(real x, real y) {return cos(x)*sin(y);} int N=200; int Divs=10; int divs=2;


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.