QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 2437|回复: 1

利用ming库来写PHP的flash动画

[复制链接]
发表于 2008-11-16 08:46:40 | 显示全部楼层 |阅读模式
http://ftp.magiclinux.org.cn/hau ... astcgi_1mgc.src.rpm
http://ftp.magiclinux.org.cn/hau ... -0.4.2-1mgc.src.rpm
  1. <?
  2.   Ming_setScale(20.0);
  3.   srand(time());
  4.   $nb_stars = (!$nb_stars)?40:$nb_stars;
  5.   $rate = (!$rate)?24:$rate;

  6.   // Creates the star model and text shapes
  7.   $s = new SWFShape();
  8.   $s->setRightFill(rand()%64, rand()%64, rand()%64, rand()%64);
  9.   $s->movePenTo(-70, 35);
  10.   $s->drawLineTo(0, -70);
  11.   $s->drawLineTo(70, 35);
  12.   $s->drawLineTo(-70, 35);
  13.   $s->movePenTo(-70, -35);
  14.   $s->drawLineTo(70, -35);
  15.   $s->drawLineTo(0, 70);
  16.   $s->drawLineTo(-70, -35);
  17.   $f = new SWFFont('/usr/share/fonts/ttf/zh_CN/wqy-zenhei.ttf');
  18.   $t = new SWFShape();
  19.   $t->setRightFill(rand()%64, rand()%64, rand()%64, rand()%64);
  20.   $t->movePenTo(-($f->getWidth('MING')/2),-(($f->getAscent()+$f->getDescent())/2));
  21.   for($c=0;$c<strlen('MING');$c++){
  22.     $t->drawGlyph($f, substr('MING',$c,1));
  23.     $t->movePen($f->getWidth(substr('MING',$c,1)),0);
  24.   }
  25.   $tt = new SWFShape();
  26.   $tt->setRightFill(rand()%64, rand()%64, rand()%64, rand()%64);
  27.   $tt->movePenTo(-($f->getWidth('PHP')/2),-(($f->getAscent()+$f->getDescent())/2));
  28.   for($c=0;$c<strlen('PHP');$c++){
  29.     $tt->drawGlyph($f, substr('PHP',$c,1));
  30.     $tt->movePen($f->getWidth(substr('PHP',$c,1)),0);
  31.   }
  32.   $ttt = new SWFShape();
  33.   $ttt->setRightFill(rand()%64, rand()%64, rand()%64, rand()%64);
  34.   $ttt->movePenTo(-($f->getWidth('SWF')/2),-(($f->getAscent()+$f->getDescent())/2));
  35.   for($c=0;$c<strlen('SWF');$c++){
  36.     $ttt->drawGlyph($f, substr('SWF',$c,1));
  37.     $ttt->movePen($f->getWidth(substr('SWF',$c,1)),0);
  38.   }


  39.   // Creates sprites
  40.   $spriteCounter=0;
  41.   for($c=0; $c<$nb_stars; $c++) {
  42.     eval("\$p$c = new SWFSprite();");
  43.     if($spriteCounter==0){eval("\$i$c = \$p$c"."->add(\$s);");$spriteCounter++;}else{
  44.     if($spriteCounter==1){eval("\$i$c = \$p$c"."->add(\$t);");$spriteCounter++;}else{
  45.     if($spriteCounter==2){eval("\$i$c = \$p$c"."->add(\$tt);");$spriteCounter++;}else{
  46.     if($spriteCounter==3){eval("\$i$c = \$p$c"."->add(\$ttt);");$spriteCounter=0;}}}}
  47.     eval("\$i$c"."->setName('triangle$c');");
  48.     eval("\$p$c"."->nextFrame();");
  49.   }

  50.   // Creates the movie and the main sprite
  51.   $m = new SWFMovie();
  52.   $m->setRate($rate);
  53.   $m->setBackground(0, 0, 0);
  54.   $m->setDimension(640,480);
  55.   $mp = new SWFSprite();

  56.   // Adds each sprite to the main one
  57.   for($c=0; $c<$nb_stars; $c++) {
  58.     $sc=0.1+(rand()%85)/100;
  59.     $rot=rand()%10+1;
  60.     eval("\$i$c=\$mp"."->add(\$p$c);");
  61.     eval("\$i$c"."->addColor(rand()%256, rand()%256, rand()%256, rand()%192);");
  62.     eval("\$i$c"."->moveTo(-320+rand()%620, -240+rand()%460);");
  63.     eval("\$i$c"."->scaleTo($sc, $sc);");

  64.     // When a sprite is loaded, creates the actionscript code needed to make it
  65.     eval("\$i$c"."->addAction(new SWFAction('
  66.       o=0;
  67.       sc=$sc*100;
  68.       sensX=(Math.random()*2-1)*7;
  69.       sensY=(Math.random()*2-1)*7;

  70.       function doXform$c() {
  71.         o+=$rot;
  72.         triangle$c._xscale=$sc*100*Math.cos(o*Math.PI/180);
  73.         triangle$c._rotation=o;
  74.         if (triangle$c._x>320) {sensX=-sensX;};
  75.         if (triangle$c._x<-320) {sensX=-sensX;};
  76.         triangle$c._x+=sensX;
  77.         if (triangle$c._y>320) {sensY=-sensY;};
  78.         if (triangle$c._y<-320) {sensY=-sensY;};
  79.         triangle$c._y+=sensY;
  80.       }
  81.     '), SWFACTION_ONLOAD);");

  82.     // When one sprite is entered then call the doXform function
  83.     eval("\$i$c"."->addAction(new SWFAction('doXform$c();'), SWFACTION_ENTERFRAME);");
  84.   }

  85.   // Adds the main sprite to the movie
  86.   $i = $m->add($mp);
  87.   $i->setName("MainClip");
  88.   $i->moveTo(320, 240);

  89.   // Create the link button
  90.   $s = new SWFShape();
  91.   $s->setRightFill(0,0,0,1);
  92.   $s->drawLine(640,0);
  93.   $s->drawLine(0,480);
  94.   $s->drawLine(-640,0);
  95.   $s->drawLine(0,-480);
  96.   $b = new SWFButton();
  97.   $b->addShape($s,SWFBUTTON_OVER | SWFBUTTON_DOWN | SWFBUTTON_OUT | SWFBUTTON_HIT);
  98.   $b->setAction(new SWFAction("getURL('skewing-source.php','_top');"));
  99.   $i=$m->add($b);

  100.   // Creates the actionscript code to make the main sprite rotate
  101.   $i->addAction(new SWFAction('o=0; function DoRotation() {o+=0.5;_root.MainClip._rotation=o;}'), SWFACTION_ONLOAD);
  102.   $i->addAction(new SWFAction('DoRotation();'), SWFACTION_ENTERFRAME);
  103.   $mp->nextFrame();

  104. $m->nextFrame();
  105. $m->save("skewing.swf");

  106. $revitalizer=rand();
  107. print "<OBJECT classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://active.macromedia.com/flash2/cabs/swflash.cab#version=4,0,0,0" ID=objects WIDTH=640 HEIGHT=480>
  108. <PARAM NAME=movie VALUE="skewing.swf?$revitalizer">
  109. <EMBED src="skewing.swf?$revitalizer" WIDTH=640 HEIGHT=480 TYPE="application/x-shockwave-flash" PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash">
  110. </OBJECT>
  111. ";
  112. ?>
复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册

×
发表于 2008-11-19 15:43:23 | 显示全部楼层
不知道为什么,我的没有出来
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-3-29 07:50 , Processed in 0.083197 second(s), 16 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表