This page was shamelessly copied (with permission) from Robert Fant's PmWiki Help so I could find the directions.
ALERT! ALERT! In ASCIIsvg.js I changed:
- Line 58 to: var gridstroke = "LightGrey"; (makes grid lighter color)
- Line 860 to: fontsize = Math.min(dx/2,dy/2,10); //alert(fontsize) (16 is now 10 and labels on grids are uniform.)
Credits: Peter Jipsen (the creator and designer of ASCIIsvg graphs) and Robert Fant (for pmwiki documentation).
| Brief descriptions of the ASCIIsvg commands and some examples follow below. Optional arguments are enclosed in braces, { }. |
|
Start here - This example demonstrates and explains the very basic, default graph and its coding. |
| Graph Example | Code Example |
|
|
{gg width=300; height=300; xmin=-5; xmax=5; xscl=1; axes(); showbutton(); plot("(1/2)x+1"); gg}
In edit mode, clicking on the ASCIIsvg-graph button Attach:KSMath/ASCIIsvg.gif Δ, will produce this default code, all of which can be modified to fit your particular needs.
|
|
Plotting Points - This example demonstrates plotting points, using color, open or closed dots. |
| Graph Example | Code Example |
|
|
{gg width=300; height=300; xmin=-6; xmax=6; xscl=1; axes(); stroke="red"; dot([-3,-3],"open"); dot([-2,-2],"closed"); stroke="green"; dot([0,0],"closed"); stroke="blue"; dot([2,2],"closed"); dot([3,3],"open"); gg} dot([x-coor, y-coor], "open or closed")
Click on the "Show / Hide" button, to try it your self. |
|
A Number Line - This example demonstrates the creation of a number line. |
| Graph Example | Code Example |
|
|
{gg width=300; height=50; gridstroke="white"; xmin=-1.5; xmax=10.5; xscl=1; yscl=4; showbutton(); axes(); strokewidth="2"; endpoints="<-o"; a=[-1,0]; b=[7,0]; line(a,b); gg} dot([x-coor, y-coor], "open or closed")
Click on the "Show / Hide" button, to try it your self. |
|
Draw a Ray or a Line - This example demonstrates drawing a ray or a line (with arrows on the end points). |
| Graph Example | Code Example |
|
|
{gg width=300; height=300; xmin=-6; xmax=6; xscl=1; axes(); stroke="green"; endpoints="<-o"; line([-4,-3],[3,4]); stroke="red"; strokedasharray="1,3"; endpoints="<- "; line([-2,-2],[1,1]); stroke="blue"; strokedasharray="5,5"; endpoints="*->"; line([4,-2],[-5,4]); gg}
line([ x_1 , y_1 ], [ x_2 , y_2 ])
Click on the "Show / Hide" button, to try it your self. |
|
Draw a Circle - This example demonstrates drawing a circle. |
| Graph Example | Code Example |
|
|
{gg width=300; height=300; xmin=-6; xmax=6; xscl=1; axes(); stroke="green"; circle([-2,0],2); stroke="blue"; strokewidth=5; circle([-2,0],3); stroke="red"; strokewidth=3; fill="yellow"; circle([2,2],2); gg}
circle([x-coor, y-coor], radius)
The circle command requires the coordinate of the center point and a radius length.
Notice, if the circles overlap, the last one drawn is the one that gets placed on top.
Click on the "Show / Hide" button, to try it your self. |
|
Draw an Ellipse - This example demonstrates drawing an ellipse. |
| Graph Example | Code Example |
|
|
{gg width=300; height=300; xmin=-6; xmax=6; xscl=1; axes(); stroke="blue"; strokewidth=5; ellipse([-3.5,0],2,4); stroke="red"; strokewidth=3; fill="green"; ellipse([1,4],4,0.5); gg}
ellipse([x-coor, y-coor], r_x , r_y )
The ellipse command requires the coordinate of the center point, a horizontal radius ( r_x ), and a vertical radius ( r_y ).
Click on the "Show / Hide" button, to try it your self. |
|
Draw a Rectangle - This example demonstrates drawing a rectangle with the rect() command. |
| Graph Example | Code Example |
|
|
{gg width=300; height=300; xmin=-6; xmax=6; xscl=1; axes(); stroke="blue"; strokewidth=3; fill="red"; rect([-4,-4],[-2,4]); stroke="red"; strokewidth=1; fill="green"; rect([-5,-1],[5,1]); gg}
rect([ x_1 , y_1 ], [ x_2 , y_2 ])
The rect (rectangle) command requires the coordinates of the bottom left corner and then the top right corner.
If a rotated rectangle is needed, it must be drawn with the path command. This will be shown next.
Click on the "Show / Hide" button, to try it your self. |
|
Draw a Polygon - This example demonstrates drawing a rectangle (any polygon), using the path() command. |
| Graph Example | Code Example |
|
|
{gg width=300; height=300; xmin=-6; xmax=6; xscl=1; axes(); a=[-2,-4]; b=[-4,-2]; c=[0,0]; d=[2,-2]; e=[-4,2]; f=[0,4]; g=[3,3]; stroke="blue"; strokewidth=3; fill="red"; path([a,b,c,d,a]); gg}
path([ P_1 , P_2 , P_3 . . . P_n ])
The path command requires points to draw between.
If the figure is to be a closed figure, then the starting point and ending point must be the same.
Note 1: Points may be declared (created), before they are used in the path command or the coordinates may be entered directly in the command itself.
Note 2: If a point is to be used in more than one figure, it is more efficient to declare them independently as shown here.
Click on the "Show / Hide" button, to try it your self. |
|
Axis, Grids & Labels - This example demonstrates working with the axes() command to change the grid lines and labels. |
| Graph Example | Code Example |
|
|
{gg width=300; height=300; xmin=-6; xmax=6; axes(2, 3, "labels", 2, 3); stroke="red"; strokewidth=2; plot("0.2x^4-x^3+3x-3",-2.2,4.7,null,null,"<->"); gg}
axes( n_1 , n_2 , "labels", n_3 , n_4 )
The axes command can be used to adjust the label spacing and the gridlines.
n_1 - adjusts the labels of the x-axis.
n_2 - adjusts the labels of the y-axis.
n_3 - adjusts gridlines perpendicular to the x-axis.
n_4 - adjusts gridlines perpendicular to the y-axis.
Click on the "Show / Hide" button, changing these values to see how they work. |
|
Arcs & Sectors - This example demonstrates drawing arcs and circle sectors. |
| Graph Example | Code Example |
|
|
{gg width=300; height=300; xmin=-6; xmax=6; xscl=1; axes(); stroke="green"; strokewidth=2; arc([0,3],[-3,0],3); stroke="blue"; strokewidth=3; arc([-4,0],[4,0],4); stroke="red"; strokewidth=0; fill="yellow"; a=[0,0]; b=[5,0]; c=[0,5]; path([a,b,c,a]); strokewidth=3; arc([5,0],[0,5],5); gg}
arc([ x_1 , y_1 ], [ x_2 , y_2 ], radius)
The arc command draws counter-clockwise from the two points, ( x_1, y_1 ) and ( x_2, y_2 ) , along the circle of the given radius.
As of this writing, there is no sector command. A filled sector must be built with a triangle (path command), and an arc.
Click on the "Show / Hide" button, to try it your self. |
|
Text - This example demonstrates the placement of text throughout the graph area. |
| Graph Example | Code Example |
|
|
{gg width=300; height=300; xmin=-6; xmax=6; axes(7, 7, "labels", 6, 6); fontfill="#990000"; stroke="red"; strokewidth=2; fill="lightgreen"; ellipse([0,0],5,3); text([0,1], "ASCIIsvg is the coolest thing"); fontfill="none"; text([0,-1], "since peanut butter!"); fontfill="#000099"; text([4,5], "Quadrant I"); text([-4,5], "Quadrant II"); text([-4,-5], "Quadrant III"); text([4,-5], "Quadrant V"); gg} Variables for text: fontfill (is the fontcolor), fontsize, fontweight, fontstyle, fontfamily, fontstroke MUST COME AFTER AXES.text([ x , y ], "Your text") The text command only requires a coordinate (of the center), and the text (label). Click on the "Show / Hide" button, to see how they work. |
|
3D Rectangular Prism - This example demonstrates the creation of a (psuedo) 3D rectangular prism. |
| Graph Example | Code Example |
|
|
(:graph width=300; height=300; xmin=0; xmax=10; xscl=1; ymin=-1; ymax=10; noaxes(); stroke="blue"; strokewidth=2; a=[2,1]; b=[5,0]; c=[5,4]; d=[2,5]; e=[9,3]; f=[9,7]; g=[6,8]; h=[6,4]; fillopacity=0.5; fill="yellow"; path([a,d,g,h,a]); path([h,e,f,g,h]); path([a,b,c,d,a]); fill="orange"; path([b,c,f,e,b]); text([8,8],"w"); text([9.5,4.5], "h"); text([4,7.5],"l") :)
I actually drew this out on paper first, labeling and naming my points there. It is important to be very organized when doing something like this.
In the script, notice I created my points first, then used them in the path command. One path command per each side of the prism. The side that appears to be closest to you is created last so that it gets drawn on the top layer.
|
+++++++++++++++++++++
|
All Commands - See all available commands (not examples), though presented in a slightly more technical fashion. |
List of ASCIIsvg commands
Optional arguments are enclosed in braces {...}. Points are specified by coordinates, e.g.
Basic commands
Further commands
Additional settings and commands
Variables that can be changed before individual commands, together with their default values
Global variables used for all pictures, and their default values
Less often used commands and to do list
|
Up one level
|

