Java draw a Curve instance code (two pages special Effects phttp://www.111cn.net/Web page special effects p.html target=_blank >jsp Tutorial Draw curve instance)
/*
Description of parameter names
To draw a pattern required; The parameter value can be the following constants: 6912, #点, the drawn polygon is displayed as a point, 6913, #线, the drawn polygon is displayed as a segment;
Required for the beginning of a curve, integral type. The value of the parameter should be between 0 and the "U to equal fraction" in the "Set curve points" command.
Required for the end of a curve, integral type. The value of the parameter should be between 0 and "point to equal points" in the "Set Curve" command.
*/
public class Test {
public static void Main (string[] args) {
Trifunc tri = new Trifunc ();
Generate a 25x100 canvas
Canvas canvas = new Canvas (25, 120);
Draw the sin curve, with a period of 2
Tri.drawsin (canvas, 2.0);
Canvas.printcanvas ();
System.out.println ();
Canvas.reset ();
Draw the Cos curve, with a period of 2
Tri.drawcos (canvas, 2.0);
Canvas.printcanvas ();
}
}
Class Trifunc {
/**
* Draw Sin Curve
* @param canvas Canvas
* @param period Curve cycle
*/
public void Drawsin (canvas canvas, double period) {
char[][] chars = Canvas.getcanvas ();
Ratio of x axis
Double Xratio = (2 * period * Math.PI)/(Canvas.getwidth ()-1);
Magnification of y-axis
int ymulti = (Canvas.getheight ()-1)/2;
for (int i = 0; i < canvas.getwidth (); i++) {
Mapping an array index to a horizontal axis value
Double k = (I-canvas.getwidth ()/2) * xratio;
To map a sin value to an array index
int h = ymulti-(int) Math.Round (Math.sin (k) * ymulti);
Chars[h][i] = Canvas.fill_char;
}
}
/**
* Draw Cos Curve
* @param canvas Canvas
* @param period Curve cycle
*/
public void Drawcos (canvas canvas, double period) {
char[][] chars = Canvas.getcanvas ();
Double Xratio = (2 * period * Math.PI)/(Canvas.getwidth ()-1);
int ymulti = (Canvas.getheight ()-1)/2;
for (int i = 0; i < canvas.getwidth (); i++) {
Double k = (I-canvas.getwidth ()/2) * xratio;
int h = ymulti-(int) Math.Round (Math.Cos (k) * ymulti);
Chars[h][i] = Canvas.fill_char;
}
}
}