Hello,
My name is miss laura, i saw your profile and it drew my attention to write to you. I would like you to communicate me through my e-mail address
(sgt.lauraralph2@gmail.com)
laura
Embed
/**
* Copyright J.J ( http://wonderfl.net/user/J.J )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/Okpy
*/
package {
import flash.display.MovieClip;
import flash.events.Event;
import flash.display.Graphics;
import flash.geom.Point;
import flash.events.MouseEvent;
import flash.text.TextField;
import flash.display.Sprite;
import com.bit101.components.Label;
import com.bit101.components.PushButton;
import com.bit101.components.HSlider;
import com.bit101.components.Component;
import com.bit101.components.CheckBox;
import flash.geom.ColorTransform;
public class Taylor extends MovieClip {
//taylor series
public var g:Graphics;
public var h:int;
public var w:int;
public var m:Point;
public var mo:Point;
public var cm:Point;
public var sf:Number=6;
public var O:Point;
public var isDown:Boolean=false;
public var n:int=2;
public var Htxs:Vector.<Label>;
public var Vtxs:Vector.<Label>;
public var zoomIn:PushButton;
public var zoomOut:PushButton;
public var hslider:HSlider;
public var checkBox:CheckBox;
public var colors:Array=[0xfffc00,0x2a00ff,0x00f6ff,0xff0000,0x00ff00];
public function Taylor() {
Htxs=new Vector.<Label>();
Vtxs=new Vector.<Label>();
g=this.graphics;
h=stage.stageHeight;
w=stage.stageWidth;
m=new Point();
mo=new Point();
cm=new Point();
O=new Point(w/2,h/2);
for(var i:int;i<6;i++){
var tx:Label=new Label(this)
tx.text="0";
tx.x=i*(w/6);
tx.y=O.y;
Htxs.push(tx);
}
for(i=0;i<6;i++){
tx=new Label(this);
tx.y=i*(w/6);
tx.x=O.x;
Vtxs.push(tx);
}
zoomIn=new PushButton(this,0,0,"+");
zoomIn.width=25;
zoomOut=new PushButton(this,0,zoomIn.height,"-");
zoomOut.width=25;
var labl:Label=new Label(this);
labl.x=35;
labl.text="n=";
hslider=new HSlider(this,50,5);
hslider.width=hslider.width/2;
hslider.setSliderParams(1,5,1);
var lbl:Label=new Label(this,hslider.x+hslider.width+2);
lbl.text="1";
hslider.addEventListener(Event.CHANGE,function (e:Event){
isDown=false;
n=Math.round(hslider.value)+1;
lbl.text=(n-1)+"";
});
checkBox=new CheckBox(this);
checkBox.x=hslider.x;
checkBox.y=hslider.y+checkBox.height+checkBox.height/2;
var chlabel:Label=new Label(this,checkBox.x+checkBox.width/1.5,checkBox.y-checkBox.height/2.5,"Show All");
zoomIn.addEventListener(MouseEvent.CLICK,onZoomIn);
zoomOut.addEventListener(MouseEvent.CLICK,onZoomOut);
var mc:Sprite=new Sprite();
this.addChild(mc);
this.graphics.beginFill(0x101010);
this.graphics.drawRect(0,0,w,h);
g=mc.graphics;
stage.addEventListener(MouseEvent.MOUSE_DOWN,onMD);
stage.addEventListener(MouseEvent.MOUSE_UP,onMU);
this.addEventListener(Event.ENTER_FRAME,loop);
}
public function onZoomIn(e:MouseEvent){
if(sf<0) sf+=.5;
sf-=.5;
}
public function onZoomOut(e:MouseEvent){
sf+=.5;
}
public function onMD(e:MouseEvent){
isDown=true;
m.setTo(stage.mouseX,stage.mouseY);
}
public function onMU(e:MouseEvent){
isDown=false;
O=O.add(mo);
mo.setTo(0,0);
}
public function loop(e:Event):void{
g.clear();
if(isDown){
cm.setTo(stage.mouseX,stage.mouseY);
mo.setTo(cm.x-m.x,cm.y-m.y);
O=O.add(mo);
g.moveTo(m.x,m.y);
g.lineTo(cm.x,cm.y);
}
draw();
for(var i:int;i<6;i++){
var tx:Label=Htxs[i];
tx.y=O.y;
tx.y=Math.max(tx.y,0);
tx.y=Math.min(tx.y,h-15)
var xt:Number = (i / 6) *sf-(O.x/w)*sf;
tx.text=xt.toFixed(2)+"";
var tx2:Label=Vtxs[i];
tx2.x=O.x;
tx2.x=Math.max(tx2.x,0)
tx2.x=Math.min(tx2.x,w-15)
xt = (i / 6) *sf-(O.y/h)*sf;
xt*=-1;
tx2.text=xt.toFixed(2)+"";
}
O=O.subtract(mo);
}
public function draw(){
g.lineStyle(1,0xffffff);
g.moveTo(0, O.y);
g.lineTo(w, O.y);
g.moveTo(O.x, 0);
g.lineTo(O.x, h);
var u :Number= stage.mouseX;
var xt:Number = (u / w) * sf - (O.x / w) * sf;
var _y :Number= -Math.exp(xt) * (h / 2) / (sf / 2) + O.y;
var fa:Number = Math.exp(xt);
function fxx(x:Number) {
var yt:Number = 0;
for (var i:int;i<n;i++) {
yt += fa/fact(i) * Math.pow(x - xt, i);
}
return yt;
//(ft + ft * (x - xt));
}
g.lineStyle(2,0x11aaff
);
drawFunc(Math.exp);
var tmp:int=n;
if(checkBox.selected){
for(var i:int;i<tmp-2;i++){
n--;
g.lineStyle(1,colors[i]);
drawFunc(fxx);
}
}
n=tmp;
g.lineStyle(2,0x00e500)
drawFunc(fxx);
g.lineStyle(0,0,0);
g.beginFill(0xff0000);
g.drawCircle(u, _y, 5);
}
public function drawFunc(fx:Function) {
g.moveTo(0,-fx((0 / w) *sf-(O.x/w)*sf)*(h/2)/(sf/2) + O.y);
for (var i:int=1;i<w;i++) {
var _x:Number = i;
var xt:Number = (i / w) *sf-(O.x/w)*sf;
var _y:Number = -fx(xt) * (h / 2) / (sf / 2) + O.y;
g.lineTo(_x , _y);
}
}
public function fact(n:int) {
var q:Number = 1;
for (var i:int=1;i<n+1;i++) q *= i;
return q;
}
}
}