facebook twitter hatena line email

Php/flash mingお絵かき

提供: 初心者エンジニアの簡易メモ
移動: 案内検索

mingを使ったお絵かき再生サンプル

中央に丸、端に赤丸が4つでます。

ini_set("memory_limit", "128M");  // メモリサイズ変更
$logic = new SwfMakeLogic;
$logic->execLogic();
exit;
// swf作成
class SwfMakeLogic
{
  public function execLogic($json = "", $swfname = "test")
  {
    if (!$json) {
      $json = '{"header":{"ver":2,"bgcolor":"ffffff"},"logs":[{"format":{"points":[{"x":"343","y":"131"},{"x":"346","y":"135"},{"x":"347","y":"137"},{"x":"347","y":"140"},{"x":"346","y":"143"},{"x":"343","y":"147"},{"x":"341","y":"151"},{"x":"335","y":"157"},{"x":"328","y":"165"},{"x":"319","y":"173"},{"x":"310","y":"181"},{"x":"301","y":"190"},{"x":"290","y":"198"},{"x":"281","y":"205"},{"x":"270","y":"209"},{"x":"260","y":"209"},{"x":"249","y":"209"},{"x":"237","y":"204"},{"x":"222","y":"194"},{"x":"209","y":"181"},{"x":"199","y":"171"},{"x":"190","y":"163"},{"x":"182","y":"155"},{"x":"179","y":"147"},{"x":"178","y":"139"},{"x":"177","y":"134"},{"x":"180","y":"127"},{"x":"183","y":"122"},{"x":"189","y":"118"},{"x":"200","y":"117"},{"x":"209","y":"117"},{"x":"221","y":"117"},{"x":"232","y":"118"},{"x":"242","y":"122"},{"x":"249","y":"127"},{"x":"254","y":"132"},{"x":"256","y":"138"},{"x":"257","y":"143"},{"x":"255","y":"152"},{"x":"253","y":"159"},{"x":"246","y":"166"},{"x":"240","y":"174"},{"x":"231","y":"180"},{"x":"220","y":"186"},{"x":"208","y":"188"},{"x":"194","y":"189"},{"x":"180","y":"187"},{"x":"165","y":"185"},{"x":"146","y":"181"},{"x":"122","y":"175"},{"x":"102","y":"168"}],"blendMode":"normal","alpha":"100","thickness":"5","color":"000000"},"mode":"pen"},{"format":{"points":[{"x":"208","y":"247"},{"x":"213","y":"251"},{"x":"215","y":"255"},{"x":"216","y":"258"},{"x":"217","y":"263"},{"x":"217","y":"266"},{"x":"216","y":"269"},{"x":"213","y":"273"},{"x":"209","y":"278"},{"x":"203","y":"283"},{"x":"197","y":"288"},{"x":"192","y":"291"},{"x":"184","y":"295"},{"x":"176","y":"297"},{"x":"166","y":"298"},{"x":"153","y":"298"},{"x":"141","y":"296"},{"x":"129","y":"294"},{"x":"116","y":"290"},{"x":"107","y":"285"},{"x":"99","y":"280"},{"x":"94","y":"275"},{"x":"91","y":"270"},{"x":"89","y":"266"},{"x":"89","y":"263"},{"x":"89","y":"260"},{"x":"92","y":"256"},{"x":"97","y":"253"},{"x":"103","y":"249"},{"x":"110","y":"243"},{"x":"118","y":"240"},{"x":"129","y":"238"},{"x":"142","y":"235"},{"x":"155","y":"234"},{"x":"167","y":"233"},{"x":"180","y":"234"},{"x":"191","y":"235"},{"x":"199","y":"239"},{"x":"206","y":"244"},{"x":"210","y":"251"},{"x":"211","y":"258"},{"x":"211","y":"265"},{"x":"211","y":"273"},{"x":"208","y":"279"},{"x":"204","y":"284"},{"x":"198","y":"288"},{"x":"193","y":"289"},{"x":"188","y":"290"},{"x":"181","y":"290"},{"x":"172","y":"290"},{"x":"162","y":"288"},{"x":"150","y":"287"},{"x":"138","y":"286"},{"x":"129","y":"285"},{"x":"120","y":"283"},{"x":"117","y":"282"},{"x":"115","y":"282"},{"x":"114","y":"280"},{"x":"114","y":"279"},{"x":"114","y":"278"},{"x":"116","y":"276"},{"x":"119","y":"275"},{"x":"125","y":"273"},{"x":"132","y":"273"},{"x":"139","y":"273"},{"x":"143","y":"273"},{"x":"145","y":"276"},{"x":"150","y":"280"},{"x":"152","y":"282"},{"x":"152","y":"284"},{"x":"152","y":"285"},{"x":"152","y":"286"},{"x":"151","y":"287"},{"x":"150","y":"287"},{"x":"149","y":"287"},{"x":"148","y":"287"},{"x":"145","y":"287"},{"x":"143","y":"287"},{"x":"140","y":"286"},{"x":"135","y":"284"},{"x":"130","y":"281"},{"x":"125","y":"278"},{"x":"117","y":"275"},{"x":"113","y":"271"}],"blendMode":"normal","alpha":"100","thickness":"5","color":"ff3b21"},"mode":"pen"},{"format":{"points":[{"x":"111","y":"103"},{"x":"109","y":"105"},{"x":"105","y":"105"},{"x":"100","y":"106"},{"x":"94","y":"107"},{"x":"88","y":"109"},{"x":"83","y":"109"},{"x":"75","y":"109"},{"x":"68","y":"106"},{"x":"59","y":"104"},{"x":"51","y":"99"},{"x":"43","y":"92"},{"x":"36","y":"85"},{"x":"30","y":"80"},{"x":"24","y":"74"},{"x":"22","y":"68"},{"x":"20","y":"62"},{"x":"20","y":"58"},{"x":"21","y":"55"},{"x":"24","y":"50"},{"x":"29","y":"46"},{"x":"36","y":"43"},{"x":"48","y":"41"},{"x":"63","y":"40"},{"x":"77","y":"40"},{"x":"89","y":"40"},{"x":"99","y":"44"},{"x":"104","y":"48"},{"x":"106","y":"51"},{"x":"106","y":"54"},{"x":"106","y":"58"},{"x":"105","y":"61"},{"x":"103","y":"65"},{"x":"98","y":"67"},{"x":"95","y":"69"},{"x":"91","y":"70"},{"x":"83","y":"71"},{"x":"76","y":"71"},{"x":"68","y":"71"},{"x":"60","y":"71"},{"x":"54","y":"71"},{"x":"50","y":"71"},{"x":"52","y":"71"},{"x":"56","y":"71"},{"x":"62","y":"70"},{"x":"68","y":"70"},{"x":"76","y":"70"},{"x":"84","y":"71"},{"x":"90","y":"71"},{"x":"94","y":"74"},{"x":"94","y":"75"},{"x":"95","y":"77"},{"x":"95","y":"79"},{"x":"94","y":"79"},{"x":"93","y":"81"},{"x":"91","y":"81"},{"x":"89","y":"83"},{"x":"86","y":"84"},{"x":"84","y":"85"},{"x":"82","y":"86"},{"x":"80","y":"86"},{"x":"81","y":"86"}],"blendMode":"normal","alpha":"100","thickness":"5","color":"ff3b21"},"mode":"pen"},{"format":{"points":[{"x":"307","y":"75"},{"x":"306","y":"76"},{"x":"304","y":"78"},{"x":"303","y":"78"},{"x":"302","y":"78"},{"x":"300","y":"78"},{"x":"297","y":"77"},{"x":"292","y":"73"},{"x":"287","y":"69"},{"x":"284","y":"66"},{"x":"284","y":"63"},{"x":"284","y":"60"},{"x":"284","y":"57"},{"x":"284","y":"53"},{"x":"284","y":"49"},{"x":"287","y":"46"},{"x":"292","y":"42"},{"x":"298","y":"38"},{"x":"308","y":"36"},{"x":"317","y":"35"},{"x":"330","y":"35"},{"x":"341","y":"35"},{"x":"350","y":"36"},{"x":"358","y":"41"},{"x":"364","y":"47"},{"x":"368","y":"53"},{"x":"369","y":"60"},{"x":"369","y":"65"},{"x":"369","y":"71"},{"x":"366","y":"75"},{"x":"363","y":"78"},{"x":"360","y":"79"},{"x":"356","y":"81"},{"x":"350","y":"82"},{"x":"343","y":"82"},{"x":"337","y":"82"},{"x":"328","y":"82"},{"x":"323","y":"82"},{"x":"319","y":"82"},{"x":"318","y":"82"},{"x":"318","y":"81"},{"x":"318","y":"79"},{"x":"320","y":"77"},{"x":"323","y":"74"},{"x":"329","y":"70"},{"x":"335","y":"69"},{"x":"342","y":"68"},{"x":"349","y":"68"},{"x":"352","y":"68"},{"x":"353","y":"69"},{"x":"353","y":"70"},{"x":"353","y":"72"},{"x":"353","y":"73"},{"x":"352","y":"74"},{"x":"350","y":"75"},{"x":"349","y":"76"},{"x":"347","y":"77"},{"x":"344","y":"78"},{"x":"339","y":"79"},{"x":"336","y":"79"},{"x":"333","y":"79"},{"x":"332","y":"79"},{"x":"331","y":"79"},{"x":"330","y":"79"}],"blendMode":"normal","alpha":"100","thickness":"5","color":"ff3b21"},"mode":"pen"},{"format":{"points":[{"x":"325","y":"308"},{"x":"322","y":"308"},{"x":"319","y":"308"},{"x":"317","y":"307"},{"x":"315","y":"307"},{"x":"313","y":"305"},{"x":"311","y":"304"},{"x":"310","y":"302"},{"x":"308","y":"301"},{"x":"308","y":"298"},{"x":"308","y":"295"},{"x":"308","y":"292"},{"x":"308","y":"289"},{"x":"308","y":"285"},{"x":"308","y":"281"},{"x":"310","y":"277"},{"x":"312","y":"272"}],"blendMode":"normal","alpha":"100","thickness":"5","color":"ff3b21"},"mode":"pen"},{"format":{"points":[{"x":"343","y":"259"},{"x":"352","y":"259"},{"x":"360","y":"259"},{"x":"366","y":"260"},{"x":"369","y":"262"},{"x":"371","y":"264"},{"x":"371","y":"267"},{"x":"371","y":"269"},{"x":"371","y":"271"},{"x":"370","y":"272"},{"x":"368","y":"274"},{"x":"365","y":"278"},{"x":"363","y":"279"},{"x":"360","y":"279"},{"x":"355","y":"281"},{"x":"351","y":"282"},{"x":"348","y":"282"},{"x":"346","y":"282"},{"x":"344","y":"282"},{"x":"344","y":"283"},{"x":"344","y":"284"},{"x":"344","y":"285"},{"x":"343","y":"285"},{"x":"342","y":"285"},{"x":"340","y":"285"},{"x":"336","y":"283"},{"x":"329","y":"282"},{"x":"323","y":"280"}],"blendMode":"normal","alpha":"100","thickness":"5","color":"ff3b21"},"mode":"pen"},{"format":{"points":[{"x":"200","y":"248"},{"x":"190","y":"245"},{"x":"179","y":"241"},{"x":"167","y":"235"},{"x":"154","y":"228"},{"x":"144","y":"221"},{"x":"134","y":"214"},{"x":"124","y":"207"},{"x":"118","y":"202"},{"x":"113","y":"196"},{"x":"109","y":"191"},{"x":"106","y":"185"},{"x":"105","y":"176"},{"x":"103","y":"165"},{"x":"102","y":"153"},{"x":"102","y":"140"},{"x":"102","y":"128"},{"x":"102","y":"117"},{"x":"102","y":"111"},{"x":"162","y":"55"},{"x":"172","y":"52"},{"x":"179","y":"50"},{"x":"188","y":"49"},{"x":"198","y":"48"},{"x":"209","y":"48"},{"x":"219","y":"46"},{"x":"231","y":"46"},{"x":"246","y":"46"},{"x":"259","y":"46"},{"x":"271","y":"46"},{"x":"282","y":"48"},{"x":"291","y":"51"},{"x":"298","y":"54"},{"x":"307","y":"58"},{"x":"314","y":"63"},{"x":"321","y":"70"},{"x":"327","y":"75"},{"x":"331","y":"81"},{"x":"334","y":"87"},{"x":"336","y":"95"},{"x":"336","y":"103"},{"x":"337","y":"112"},{"x":"338","y":"126"},{"x":"338","y":"139"},{"x":"339","y":"152"},{"x":"340","y":"167"},{"x":"340","y":"180"},{"x":"341","y":"191"},{"x":"341","y":"200"},{"x":"338","y":"207"},{"x":"337","y":"213"},{"x":"332","y":"220"},{"x":"329","y":"225"},{"x":"322","y":"231"},{"x":"315","y":"239"},{"x":"307","y":"246"},{"x":"297","y":"254"},{"x":"288","y":"260"},{"x":"276","y":"264"},{"x":"264","y":"265"},{"x":"251","y":"265"},{"x":"238","y":"265"},{"x":"223","y":"265"},{"x":"210","y":"263"},{"x":"197","y":"261"},{"x":"186","y":"261"}],"blendMode":"normal","alpha":"100","thickness":"5","color":"313bcd"},"mode":"pen"}]}';
    }
    
    $obj = json_decode($json, false);
    $logs = $obj->logs;
    ming_useswfversion(6);
    $m = new SWFMovie();
    $m->setDimension(400, 400);
   // 速度
    $m->setRate(1);
    foreach ($logs as $num => $log) {
      $mode = $log->mode;
      // if ($mode == "pen") {
        $format = $log->format;
        $points = $format->points;
        $color = substr("000000" . $format->color, -6, 6);
        if ($mode == "erase") {
          $color = "ffffff";
        }
        foreach ($points as $pnum => $point) {
          // 最後のログは実行しない
          if ($pnum == count($points) - 1) {
            break;
          }
          if ($pnum == 0) {
            $s = new SWFShape();
            $s->setLine($format->thickness, floor("0x" . substr($color, 0, 2)), floor("0x" . substr($color, 2, 2)), floor("0x" . substr($color, 4, 2)), floor($format->alpha / 100 * 255));
            $s->movePenTo($point->x, $point->y);
            $i = $m->add($s);
          }
          $s->drawLineTo($points[$pnum + 1]->x, $points[$pnum + 1]->y);
        }
      // }
      // ログの最後はnextframeしない
      if ($num < count($logs) - 1) {
        $m->nextframe();
      } else {
        // 最後で停止
        $m->add(new SWFAction("stop();"));
        $as = "gotoFrame(" . (count($logs) - 1) .");";
        $m->add(new SWFAction($as));
      }
    }
    $m->save($swfname . '.swf');
  }
}