主要应用:
lineStyle(MovieClip.lineStyle 方法);
lineTo(MovieClip.lineTo 方法);
moveTo(MovieClip.moveTo方法);
基本思路:
先获取开始绘图的起点的坐标,这里所说的起点即为二次函数顶点坐标再向左移一定距离后得到的对应点的坐标.因为我们要作的是一个完整的二次函数图象,而不是一半(如果以顶点坐标为绘图起点开始的话,只能得到一半的图象).
当然有一个很关键的问题,就是你所求的坐标是相对于舞台上的"原点",而flash绘图时则以最左上角的一个点作为原点,所以还需要换算坐标.
现在就是最关键的环节了,建立个一用于绘图的函数,基本思路是从"起点"开始,每一次循环就把坐标加1,然后求得对应的y坐标,换算后用lineTo连线.大功告成!
代码:
//
/draw_btn为舞台上一个按钮,First ,Second ,Third 是三个系数对应的输入文本的变量,一下为写在第一帧的代码
var oPointx:Number = Stage.width / 2 ;
var oPointy:Number = Stage.height / 2 ;
var xPosition:Number = 0 ;
var yPosition:Number = 0 ;
var drawx:Number = 0 ;
var drawy:Number = 0 ;
var First:Number = 0 ;
var Second:Number = 0 ;
var Third:Number = 0 ;
var Start:Number = 0 ;
_root.draw_btn.onPress = function () ... {
if(First != 0 && Second != 0 && Third != 0)...{
_root.clear();
Start = int((Second/First/2)*-1)-100;
xPosition = Start;
drawx = 275+Start;
yPosition = xPosition*xPosition*First+xPosition*Second+Third;
drawy = 200-yPosition;
_root.moveTo(drawx, drawy);
_root.lineStyle(1, 0xFF0000, 100);
for (var i:Number = 1; i<301; i++) ...{
xPosition += 5;
drawx = xPosition+275;
yPosition = xPosition*xPosition*First+xPosition*Second+Third;
drawy = 200-yPosition;
_root.lineTo(drawx, drawy);
updateAfterEvent();
}}
} ;
var oPointx:Number = Stage.width / 2 ;
var oPointy:Number = Stage.height / 2 ;
var xPosition:Number = 0 ;
var yPosition:Number = 0 ;
var drawx:Number = 0 ;
var drawy:Number = 0 ;
var First:Number = 0 ;
var Second:Number = 0 ;
var Third:Number = 0 ;
var Start:Number = 0 ;
_root.draw_btn.onPress = function () ... {
if(First != 0 && Second != 0 && Third != 0)...{
_root.clear();
Start = int((Second/First/2)*-1)-100;
xPosition = Start;
drawx = 275+Start;
yPosition = xPosition*xPosition*First+xPosition*Second+Third;
drawy = 200-yPosition;
_root.moveTo(drawx, drawy);
_root.lineStyle(1, 0xFF0000, 100);
for (var i:Number = 1; i<301; i++) ...{
xPosition += 5;
drawx = xPosition+275;
yPosition = xPosition*xPosition*First+xPosition*Second+Third;
drawy = 200-yPosition;
_root.lineTo(drawx, drawy);
updateAfterEvent();
}}
} ;