Для школы я создал игру, которая научит вас обращаться с параболами. Единственная проблема; Я не знаю, как создать параболу в Adobe flash cs6 ActionScript 2. Мне нужно иметь возможность вставить параболическую формулу «в игре», которая должна появиться при полной вставке.
Парабола в Adobe Flash CS6 ActionScript 2
Ответы (2)
Я справился с этим с помощью функции curveTo, она рисует квадратную кривую Безье. Итак, вот парабола Безье:
function drawLineOrCurve(mc_where,from,to,props,controlPoint){
(props[2]==null)?props[2]=100:null;//bugsquash!
mc_where.lineStyle(props[0],props[1],props[2]);
mc_where.moveTo(from[0],from[1]);
(controlPoint==null)?
mc_where.lineTo(to[0],to[1]):
mc_where.curveTo(controlPoint[0],controlPoint[1],to[0],to[1]);
return [from[0],from[1],to[0],to[1],controlPoint[0],controlPoint[1]];
}
this.createEmptyMovieClip("tool",100);
function parabolaSlope(x,a,b,c){
//https://en.wikipedia.org/wiki/Parabola
return a*x*x+x*b+c;
}
props=[2,0xff00ff]; //linestyle
a = 1;
b = 6;
c = 0;
x = 10; //max x value
from=[-x,parabolaSlope(x,a,b,c)];
to=[x,parabolaSlope(x,a,b,c)];
controlPoint=[0,-parabolaSlope(x,a,b,c)]; //[this is why control point is negative here][2]
//
drawLineOrCurve(tool,from,to,props,controlPoint); //draw it
trace("(x,y)from "+tool._x+":"+tool._y+" to "+x+":"+parabolaSlope(x,a,b,c));
tool._x=Stage.width/2; //center movieclip
tool._y=Stage.width/2;
tool._rotation = 180; //flash has inverted Y axis
scaleFactor = Stage.height/parabolaSlope(x,a,b,c)*100;
tool._yscale = tool._xscale = scaleFactor;
вот почему контрольная точка здесь отрицательная
person
animaacija
schedule
21.11.2014
Вам нужно поле для ввода уравнения.. соедините его с кодом, который я дал ранее, для ПОЛНОСТЬЮ отвеченного вопроса.
tool._yscale = tool._xscale = 100//scaleFactor;
/////////////////////////////////////
//GUI
_root.createEmptyMovieClip("texte",102);
texte.createTextField("formula",103,5,5,100,20);
texte.formula.text = "-2x^2+4x+8"//"place math here";//
texte.formula.type = "input";
texte.formula.border = true;
texte.formula.restrict = "0-9\\+\\x\\-\\^";
//mediate
var _a:Number = 0; //parsed coeficients
var _b:Number = 0; //will be stored
var _c:Number = 0; //here as numbers
//housekeeping
function forMe(i,from,to){return Number(ar[i].substring(from,to))}
//user gave us input
function parseInput(str){
//prepare values
arr = str.split("-");
ar = new Array();//temp
if(arr.length>1){
for(i=0;i<arr.length;i++){
((arr[i]!="")&&(i!=0))?ar[i]="-"+arr[i]:ar[i] ="+"+arr[i]}}
else{ar=arr}
for(i=0;i<ar.length;i++){
arr[i] = ar[i].split("+")} //trace(arr.join());
ar = arr.join().split(",");
for(i=0;i<ar.length;i++){
(ar[i]=="")?ar[i]="+":null;}
//assign values
for(i=0;i<ar.length;i++){
hasX = ar[i].indexOf("x");//shorthands
hasL = ar[i].indexOf("^");
isNeg = ar[i].indexOf("-");
if(hasX!=-1){
if(hasL!=-1){
if(isNeg!=-1){
a=-forMe(i,0,hasX);}
else{
a=forMe(i,0,hasX);}}
else{
(isNeg!=-1)?b=-forMe(i,0,hasX):b=forMe(i,0,hasX);}}
else{
(isNeg!=-1)?c=-ar[i]:c=ar[i];}}
//these need to be reassigned..
from=[-x,parabolaSlope(x,a,b,c)];
to=[x,parabolaSlope(x,a,b,c)];
controlPoint=[0,-parabolaSlope(x,a,b,c)];
}
//event, might be a propper button, your choise!
onMouseUp=function(){
parseInput(texte.formula.text);
tool.clear();
drawLineOrCurve(tool,from,to,props,controlPoint);
}
В as2 нет RexEx и я думаю Scale_factor здесь тоже не нужен.
person
animaacija
schedule
22.11.2014