1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
package
{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.events.Event;
public class Graphique extends MovieClip
{
private var t:Number = 0;
private var Periode:Number = (stage.stageWidth-10)/5;
private var omega : Number = 2*Math.PI / Periode;
private var container:Sprite = new Sprite();
private var sinus:Sprite = new Sprite();
private var cosinus:Sprite = new Sprite();
public function Graphique():void
{
stage.frameRate = 30;
with (container.graphics)
{
lineStyle(2, 0x000000, 0.75);
//axe horizontal
moveTo(10,stage.stageHeight / 2);
lineTo(stage.stageWidth, stage.stageHeight / 2);
beginFill(0);
moveTo(stage.stageWidth-15,stage.stageHeight / 2-7);
lineTo(stage.stageWidth - 15, stage.stageHeight / 2 + 7 );
lineTo(stage.stageWidth, stage.stageHeight / 2 );
lineTo(stage.stageWidth - 15, stage.stageHeight / 2 - 7);
endFill();
//axe vertical
moveTo(10,stage.stageHeight / 2 -200);
lineTo(10, stage.stageHeight / 2 +200 );
beginFill(0);
moveTo(3,stage.stageHeight / 2-185);
lineTo(17, stage.stageHeight / 2 -185 );
lineTo(10, stage.stageHeight / 2-200 );
lineTo(3, stage.stageHeight / 2 - 185);
endFill();
}
addChild(container);
sinus.x = 10;
cosinus.x = 10;
sinus.graphics.moveTo(t, -150 * Math.sin(omega * t) + stage.stageHeight / 2);
cosinus.graphics.moveTo(t, -150 * Math.cos(omega * t) + stage.stageHeight / 2);
container.addChildAt(sinus,0);
container.addChild(cosinus);
addEventListener(Event.ENTER_FRAME, doTrace);
}
function doTrace(event:Event):void
{
t+= 5;
sinus.graphics.lineStyle(3, 0x0000FF, 0.75);
sinus.graphics.lineTo(t, -150 * Math.sin(omega * t )+ stage.stageHeight / 2);
cosinus.graphics.lineStyle(3, 0xff0000, 0.75);
cosinus.graphics.lineTo(t , -150 * Math.cos(omega * t) + stage.stageHeight / 2);
if (t > stage.stageWidth)
{
sinus.graphics.clear();
cosinus.graphics.clear();
t = 0;
sinus.graphics.moveTo(t, -150 * Math.sin(omega * t) + stage.stageHeight / 2);
cosinus.graphics.moveTo(t, -150 * Math.cos(omega * t) + stage.stageHeight / 2);
}
}
}
} |
Partager