Difference between revisions of "Autograph"
m (→The code) |
(if you don't want anyone to use it, don't put it on the wiki) |
||
Line 1: | Line 1: | ||
− | { | + | {{Asymptote}} |
− | + | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
==Autograph== | ==Autograph== | ||
<asy> | <asy> | ||
Line 25: | Line 19: | ||
dot((0,-1.5),red); | dot((0,-1.5),red); | ||
dot((-1.5,0),red);</asy> | dot((-1.5,0),red);</asy> | ||
− | Autograph is a piece of code written in [[Asymptote]] that | + | Autograph is a piece of code written in [[Asymptote]] that graphs functions. The user must only set the function, and optionally |
* the x and y maximums and minimums | * the x and y maximums and minimums | ||
* the color of the graph line | * the color of the graph line | ||
Line 34: | Line 28: | ||
* the width of the line | * the width of the line | ||
It is targeted to beginners in asymptote who don't want to learn all of it, but still want to make nice graphs. | It is targeted to beginners in asymptote who don't want to learn all of it, but still want to make nice graphs. | ||
− | |||
==Examples== | ==Examples== | ||
Some pretty graphs: | Some pretty graphs: | ||
Line 251: | Line 244: | ||
{dot((temp,f(temp)),graph_color+linewidth(line_width*4));}}} | {dot((temp,f(temp)),graph_color+linewidth(line_width*4));}}} | ||
dot((0,0)); | dot((0,0)); | ||
− | |||
</asy> | </asy> | ||
== The code== | == The code== | ||
Line 312: | Line 304: | ||
} | } | ||
dot((0,0)); | dot((0,0)); | ||
− | |||
</nowiki></pre> | </nowiki></pre> | ||
Revision as of 07:18, 25 July 2011
Autograph
Autograph is a piece of code written in Asymptote that graphs functions. The user must only set the function, and optionally
- the x and y maximums and minimums
- the color of the graph line
- the density of the ticks
- whether to show the grid or not
- wether to mark lattice points or not
- the ratio of x to y
- the width of the line
It is targeted to beginners in asymptote who don't want to learn all of it, but still want to make nice graphs.
Examples
Some pretty graphs:
The code
The code is:
/* AUTO-GRAPH V-4 beta by PythonNut*/ /* Customizations: feel free to edit */ import math; import graph; /* x maximum and minimum */ int X_max = 10; int X_min =-10; /* y maximum and minimum */ int Y_max = 10; int Y_min = -10; /* linewidth */ real line_width = 0.75; /* graph color */ pen graph_color = heavygreen; /* special */ bool mark_lattice = false; bool show_grid = true; real X_tick_density = 1; real Y_tick_density = 1; real ratio = 1; real resolution = 0.0001; int size = 300; /* graph function */ real f(real x) { return 2x^3-6x^2+3x-1; /* type function to be graphed here */ } /* The Code. Do not disturb unless you know what you are doing */ bool ib(real t){ return (Y_min <= f(t) && f(t) <= Y_max); } size(size);unitsize(size*ratio,size);Label l;l.p=fontsize(6); xaxis("$x$",X_min,X_max,Ticks(l,X_tick_density,(X_tick_density/2),NoZero),Arrows); yaxis("$y$",Y_min,Y_max,Ticks(l,Y_tick_density,(Y_tick_density/2),NoZero),Arrows);// if (show_grid){add(shift(X_min,Y_min)*grid(X_max-X_min,Y_max-Y_min));} real t, T1, T2; for (T1 = X_min ; T1 <= X_max ; T1 += resolution){ while (! ib(T1) && T1 <= X_max){T1 += resolution;} if(T1 > X_max){break;} T2 = T1; while ( ib(T1) && T1 <= X_max){T1 += resolution;} T1 -= resolution; draw(graph(f,T2,T1,n=2400),graph_color+linewidth(line_width),Arrows); } if (mark_lattice){ for (t = X_min; t <= X_max; ++t){ if (f(t)%1==0 && ib(t)){ dot((t,f(t)),graph_color+linewidth(line_width*4)); } } } dot((0,0));
Autograph Micro
Autograph micro is a version of autograph made to fit in the AoPS classroom character limit.
[asy]int X=10,x=-10,Y=10,y=-10; real f(real x){return 11*sin(x);} size(300); Label l;l.p=fontsize(6);dot((0,0)); xaxis(x,X,Ticks(l,1.0,0.5));yaxis(y,Y,Ticks(l,1.0,0.5)); add(shift(x,y)*grid(X-x,Y-y)); draw(graph(f,x,X,n=2400),heavygreen+linewidth(1),Arrows); clip((x,y)--(x,Y)--(X,Y)--(X,y)--cycle);[/asy]
Autograph implicit
Autograph implicit Is a version of Autograph used to graph implicit functions such as The code is
[asy] /* AUTO-GRAPH implict by PythonNut*/ /* Customizations: feel free to edit */ import math; import graph; import contour; /* x maximum and minimum */ int X_max = 10; int X_min =-10; /* y maximum and minimum */ int Y_max = 10; int Y_min = -10; /* graph color */ pen graph_line = heavygreen+linewidth(0.75); /* special */ bool show_grid = true; real X_tick_density = 1; real Y_tick_density = 1; real ratio = 1; int size = 300; real value = 2.5; /* value to set to */ /* graph function */ real f(real x, real y) { return x^13+5*x^5*y^3+x*y^5+y^5; /* type function to be graphed here */ } /* The Code. Do not disturb unless you know what you are doing */ size(size);unitsize(size*ratio,size);Label l;l.p=fontsize(6); xaxis("$x$",X_min,X_max,Ticks(l,X_tick_density,(X_tick_density/2),NoZero),Arrows); yaxis("$y$",Y_min,Y_max,Ticks(l,Y_tick_density,(Y_tick_density/2),NoZero),Arrows);// if (show_grid){add(shift(X_min,Y_min)*grid(X_max-X_min,Y_max-Y_min));} draw(contour(f,(X_min,Y_min),(X_max,Y_max), new real[] {value}),graph_line);[/asy]