行進 駆け足追加
つい最近papervision3dの存在を知り、ここ数週間、関連サイトやこのサイトのプログラムを見て勉強してました。
それで、気がついたのが、papervision3dでpalneやcubeなどを変形できる、ということでした。
この変形を利用して何かできないかと考えた末「planeを行進させようと」思いつきこのプログラム作ってみました。
もし、うまくいったら、自分のサイトに組み込むつもりでしたが、結果は失敗。
見てもらえればわかるが、なんだか、不気味。・・・。
今はまだ自由自在に形を変形させることは出来ないが、今後、もっと技術を磨き、複雑な変形に挑戦していきたい。
「追加機能」
後ろに並んでいるplaneをクリックしてください。planeが駆け足を始めます。
/**
* Copyright hankuro ( http://wonderfl.net/user/hankuro )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/m7kF
*/
package
{
import flash.display.Bitmap;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
import flash.system.LoaderContext;
[SWF(width = "500", height = "500", backgroundColor = "0" )]
/**
* つい最近papervision3dの存在を知り、ここ数週間、関連サイトやこのサイトのプログラムを見て勉強してました。
* それで、気がついたのが、papervision3dでpalneやcubeなどを変形できる、ということでした。
* この変形を利用して何かできないかと考えた末「planeを行進させようと」思いつきこのプログラム作ってみました。
* もし、うまくいったら、自分のサイトに組み込むつもりでしたが、結果は失敗。
* 見てもらえればわかるが、なんだか、不気味。・・・。
* 今はまだ自由自在に形を変形させることは出来ないが、今後、もっと技術を磨き、複雑な変形に挑戦していきたい。
*
* 「追加機能」
* 後ろに並んでいるplaneをクリックしてください。planeが駆け足を始めます。
*/
public class Main extends Sprite
{
public var obj_num:Number = 5;
public var image_num:Number = 5;
public var no1_url:URLRequest = new URLRequest("http://assets.wonderfl.net/images/related_images/f/fc/fcd3/fcd3c61e14abd84b69f77c34d421cc8e56ed9b11m");
public var no2_url:URLRequest = new URLRequest("http://assets.wonderfl.net/images/related_images/b/be/be30/be30c0a3994981588f27f247e654b591466befcdm");
public var no3_url:URLRequest = new URLRequest("http://assets.wonderfl.net/images/related_images/9/97/9748/9748dcd0e847a8274efeecd4e84f1a7e2e03e879m");
public var no4_url:URLRequest = new URLRequest("http://assets.wonderfl.net/images/related_images/4/40/40c9/40c96b0c404cd8a761c318cd4c3eb98a70031d76m");
public var no5_url:URLRequest = new URLRequest("http://assets.wonderfl.net/images/related_images/5/5f/5f89/5f89a46a0b2e679fdf5cb791fc00d8929aeb71ddm");
public var no1:Loader = new Loader();
public var no2:Loader = new Loader();
public var no3:Loader = new Loader();
public var no4:Loader = new Loader();
public var no5:Loader = new Loader();
public var images:Array = new Array(5);
public function Main()
{
var context : LoaderContext = new LoaderContext(true);
no1.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
no2.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
no3.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
no4.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
no5.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoaded);
no1.load(no1_url,context);
no2.load(no2_url,context);
no3.load(no3_url,context);
no4.load(no4_url,context);
no5.load(no5_url,context);
}
public function onImageLoaded(event:Event):void {
image_num--;
if (image_num != 0) return;
images[0] = new Bitmap();
images[0] = Bitmap(no1.content);
images[1] = new Bitmap();
images[1] = Bitmap(no2.content);
images[2] = new Bitmap();
images[2] = Bitmap(no3.content);
images[3] = new Bitmap();
images[3] = Bitmap(no4.content);
images[4] = new Bitmap();
images[4] = Bitmap(no5.content);
control.m_obj = this;
for (var i:Number = 0; i < obj_num;i++){
addChildAt(new work(images[i]),0);
}
control.init_march();
addEventListener(Event.ENTER_FRAME, onRun , false, 0, true);
}
public function set_index(p:work):void {
setChildIndex(p, 0);
}
private function onRun(evt:Event):void {
}
}
}
import flash.display.Bitmap;
import flash.display.BitmapData;
import flash.display.Shape;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.events.TimerEvent;
import flash.geom.Point;
import flash.ui.Mouse;
import flash.utils.Timer;
import org.papervision3d.core.geom.Lines3D;
import org.papervision3d.core.geom.renderables.Line3D;
import org.papervision3d.core.geom.renderables.Vertex3D;
import org.papervision3d.core.math.Number3D;
import org.papervision3d.materials.BitmapMaterial;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.MovieMaterial;
import org.papervision3d.materials.shadematerials.GouraudMaterial;
import org.papervision3d.materials.special.LineMaterial;
import org.papervision3d.materials.WireframeMaterial;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.view.BasicView;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.core.effects.view.ReflectionView;
class work extends ReflectionView
{
public var plane:Plane;
public var lines:Lines3D;
public var obj3D:DisplayObject3D
public var action:Number = 0;
public var r:Number = 0;
public var save_v:Array;
public var timer:Timer;
public var status:Number = 0;
public var save_status:Number;
public var rotation_end:Number;
public var wait_num:Number;
public var l_sw:Boolean = false;
public var r_sw:Boolean = false;
public var bmp_data:BitmapData;
public var material:BitmapMaterial;
public var rr:Number = 0;
public var speed_up_sw:Boolean = false;
public var speed_up_on_sw:Boolean = false;
public function work(p:Bitmap)
{
bmp_data = new BitmapData(p.width, p.height);
bmp_data.draw(p);
material = new BitmapMaterial( bmp_data );
super(500, 500, false, false);
camera.z = -500;
surfaceHeight = -150;
var wire:WireframeMaterial = new WireframeMaterial(Math.random() * 0xFFFFFF, 1);
var color_m:ColorMaterial = new ColorMaterial(Math.random() * 0xFFFFFF);
plane = new Plane(color_m, 100, 150, 4, 2);
control.set_obj(this);
scene.addChild(plane);
plane.x = 400;
plane.rotationY = -60;
save_v = new Array(plane.geometry.vertices.length);
// for (var i:Number = 0; i < plane.geometry.vertices.length; i++) {
// trace (i+" "+plane.geometry.vertices[i].x+" "+plane.geometry.vertices[i].y+" "+plane.geometry.vertices[i].z)
// }
plane.geometry.vertices[3].y += 10;
plane.geometry.vertices[6].y += 13;
plane.geometry.vertices[9].y += 10;
addEventListener(Event.ENTER_FRAME, onRun , false, 0, true);
timer = new Timer(control.speed_down_num);
timer.addEventListener(TimerEvent.TIMER, onTimer);
timer.start();
addEventListener(MouseEvent.CLICK, onClick);
addEventListener("on_timer_up", on_timer_up);
addEventListener("on_timer_down", on_timer_down);
buttonMode = true;
}
private function onRun(evt:Event):void {
}
public function onClick(evt:Event):void {
if (status != 0) return;
if (speed_up_on_sw) return;
plane.geometry.vertices[14].y += 20;
wait_num = 2;
save_status = status;
status = 6;
speed_up_sw = true;
}
public function onTimer(evt:TimerEvent):void {
switch(status) {
case 0:
if (plane.x < 0){
march();
}else {
plane.x = 0;
if (l_sw) {
plane.geometry.vertices[0].x -= 20;
l_sw = false;
}
if (r_sw) {
plane.geometry.vertices[12].x -= 20;
r_sw = false;
}
status = 1;
action = 0;
plane.x = plane.y = 0;
plane.z = 0;
plane.geometry.vertices[0].x = -50;
plane.geometry.vertices[12].x = 50;
control.stop_sw = true;
}
break;
case 1:
if (plane.rotationY < 0 ) {
curve(0);
}else {
if (l_sw) {
plane.geometry.vertices[0].y += 5;
l_sw = false;
}
if (r_sw) {
plane.geometry.vertices[12].y -= 5;
r_sw = false;
}
plane.geometry.vertices[0].x = -50;
plane.geometry.vertices[12].x = 50;
plane.geometry.vertices[0].y = -75;
plane.geometry.vertices[12].y = -75;
plane.geometry.vertices[3].y -= 10;
plane.geometry.vertices[6].y -= 13;
plane.geometry.vertices[9].y -= 10;
plane.rotationY = 0;
plane.x = plane.y = 0;
plane.z = 0;
status = 2;
action = 0;
}
break;
case 2:
if (speed_up_sw) {
plane.geometry.vertices[14].y -= 20;
control.speed_down();
speed_up_sw = false;
}
if (plane.z > -300) {
forward();
}else {
status = 3;
action = 0;
wait_num = 5;
plane.x = plane.y = 0;
plane.z = -300;
plane.rotationY = 0;
}
break;
case 3:
wait_num--;
if (wait_num == 0) {
status = 4;
rotation_end = 60;
control.stop_sw = false;
}
break;
case 4:
if (rotation_end != 0) {
curve(1);
}else {
status = 5;
action = 0;
r = 0;
}
break;
case 5:
march(true);
if (plane.x > 200) {
status = 0;
scene.removeChild(plane);
var color_m:ColorMaterial = new ColorMaterial(Math.random() * 0xFFFFFF);
if (rr == 0) plane = new Plane(material, 100, 150, 4, 2);
else plane = new Plane(color_m, 100, 150, 4, 2);
rr = 1 - rr;
scene.addChild(plane);
plane.geometry.vertices[3].y += 10;
plane.geometry.vertices[6].y += 13;
plane.geometry.vertices[9].y += 10;
plane.rotationY = -60;
control.reset_obj(this);
}
break;
case 6:
wait_num--;
if (wait_num == 0) {
control.speed_up();
status = save_status;
}
}
singleRender();
}
public function march(p:Boolean = false):void {
if (control.stop_sw) if(!p) return;
switch(action) {
case 0:
plane.geometry.vertices[12].x = 50 + 20;
r_sw = true;
action = 2;
break;
case 1:
plane.geometry.vertices[0].x = -50 + 20;
l_sw = true;
action = 2;
break;
case 2:
if(r ==0){
plane.geometry.vertices[12].x = 50;
r_sw = false;
}else {
plane.geometry.vertices[0].x = -50;
l_sw = false;
}
plane.x += 15;
if (r == 0) action = 1;
else action = 0;
r = 1 - r;
break;
}
}
public function forward():void {
switch(action) {
case 0:
plane.geometry.vertices[12].x = 50 + 10;
plane.geometry.vertices[12].z = 10;
action = 2;
break;
case 1:
plane.geometry.vertices[0].x = -50 - 10;
plane.geometry.vertices[0].z = 10;
action = 2;
break;
case 2:
if(r ==0){
plane.geometry.vertices[12].x = 50;
plane.geometry.vertices[12].z = 0;
}else {
plane.geometry.vertices[0].x = -50;
plane.geometry.vertices[0].z = 0;
}
if (r == 0) action = 1;
else action = 0;
r = 1 - r;
break;
}
plane.z -= 10;
}
public function curve(p:Number):void{
switch(action) {
case 0:
plane.geometry.vertices[12].y += 5;
r_sw = true;
action = 2;
break;
case 1:
plane.geometry.vertices[0].y += 5;
l_sw = true;
action = 2;
break;
case 2:
if(r ==0){
plane.geometry.vertices[12].y -= 5;
r_sw = false;
}else {
plane.geometry.vertices[0].y -= 5;
l_sw = false;
}
if (r == 0) action = 1;
else action = 0;
r = 1 - r;
break;
}
if (p == 0) plane.rotationY += 5;
else {
plane.rotationY -= 10;
rotation_end -= 10;
}
}
public function on_timer_up(evt:Event):void {
speed_up_on_sw = true;
timer.removeEventListener(TimerEvent.TIMER, onTimer);
timer = new Timer(control.speed_up_num);
timer.addEventListener(TimerEvent.TIMER, onTimer);
timer.start();
}
public function on_timer_down(evt:Event):void {
speed_up_on_sw = false;
timer.removeEventListener(TimerEvent.TIMER, onTimer);
timer = new Timer(control.speed_down_num);
timer.addEventListener(TimerEvent.TIMER, onTimer);
timer.start();
}
}
import flash.utils.Timer;
import flash.events.Event;
class control
{
public static var obj_array:Array = new Array();
public static var stop_sw:Boolean = false;
public static var m_obj:Main;
public static const speed_up_num:Number = 20;
public static const speed_down_num:Number = 500;
public static function march_control():void
{
}
public static function init_march():void {
obj_array[0].plane.x = -200;
for (var i:Number = 1; i < obj_array.length; i++) {
obj_array[i].plane.x = obj_array[i - 1].plane.x - 100;
}
}
public static function set_obj(p:work):void {
obj_array.push(p);
}
public static function reset_obj(p:work):void {
for (var i:Number=0; i < obj_array.length; i++) {
if (obj_array[i] == p) break;
}
if (i == 0) {
obj_array[0].plane.x = obj_array[obj_array.length - 1].plane.x - 200;
obj_array[0].r = obj_array[obj_array.length - 1].r;
}else {
obj_array[i].plane.x = obj_array[i - 1].plane.x - 100;
obj_array[i].r = obj_array[i - 1].r;
}
m_obj.set_index(p);
}
public static function speed_up():void {
for (var i:Number = 0; i < obj_array.length; i++) {
obj_array[i].dispatchEvent(new Event("on_timer_up"));
}
}
public static function speed_down():void {
for (var i:Number=0; i < obj_array.length; i++) {
obj_array[i].dispatchEvent(new Event("on_timer_down"));
}
}
}