package { import frocessing.display.*; [SWF(width="465", height="465", backgroundColor="0xffffff", frameRate="30")] public class FrocessingLesson extends F5MovieClip2DBmp{ private var xpos: Number; // ボディの中心のx座標 private var ypos: Number; // ボディの中心のy座標 private var speed: Number = 1.0; //進む速さ private const BODY: uint = 60; // ボディの高さ、幅の基準 private const TIRE: uint = 30; // 車輪の直径の基準 public function setup():void { xpos = -BODY; ypos = height / 2; } public function draw():void { background(255); // 画面をリセットする drawBus(xpos, ypos); // バスを描く xpos = xpos + speed; // 1ずつ進む if(xpos > width + BODY){ xpos = -BODY; // バスが右端まで行ったら左端に戻る } } public function drawBus(xpos: Number, ypos: Number):void { rectMode(CENTER); rect(xpos, ypos, BODY*2, BODY); // ボディ ellipse(xpos - 35 , ypos + 30 , TIRE, TIRE); // 後輪・外側 ellipse(xpos +35, ypos + 30 , TIRE, TIRE); // 前輪・外側 ellipse(xpos -35, ypos + 30, TIRE - 10, TIRE - 10); // 後輪・内側 ellipse(xpos +35, ypos + 30, TIRE - 10, TIRE - 10); // 前輪・内側 rectMode(CORNER); rect(xpos + 45, ypos - 20, BODY / 4, BODY / 3); // 窓・前 rect(xpos - 5, ypos - 20, BODY / 2, BODY / 3); // 窓・中 rect(xpos - 50, ypos - 20, BODY / 2 , BODY / 3); // 窓・後 } } } バスを走らせる