sample #10
overlapping shapes
  1. <?php
  2. include("sample_utils.php"); // provides some utils and using mk
  3.  
  4. function draw_many_stars($nmbStars){
  5.  
  6. global $imgDir;
  7.  
  8. $sc = new MKshape_container(); // the shape
  9. $rStr = "0123456789ABCDEF";
  10.  
  11. for($i = 0; $i < $nmbStars; $i++){
  12. $x = 14 * $i;
  13. $y = cos(deg2rad($x)) * 60 + 150;
  14. $rCol = $rStr[rand(6, 15)];
  15. $rCol .= $rCol ."0000";
  16.  
  17. $sc->add_fillStyle_solid("#" .$rCol); // fill color, max red value
  18. $sc->add_star($x, $y, 20, "auto", 5, $i * 10); // a circle with radius, x,y
  19. $sc->increase_shapeDepth();
  20. }
  21.  
  22. $sd = $sc->update_tagData(); // get shape tag
  23. $po = $sc->update_place_tagData(); // get placing data
  24.  
  25. $swf = new MKswf("test_draw03.swf"); // start a fresh swf
  26. $swf->set_swfDir(SERVER_MKTMP); // change default working dir
  27. $swf->add_tagData($sd); // populate with shape
  28. $swf->add_tagData($po); // place on stage
  29. $swf->swf_output(); // save to disk
  30.  
  31. $swfHeader = $swf->fetch_assoc();
  32.  
  33. $str = render_swf_box($swfHeader, $imgDir, false);
  34. $str .= "<br/><strong>test_draw03.swf created in" .SERVER_MKTMP ."</strong>";
  35.  
  36. return $str;
  37. }
  38.  
  39. $str = draw_many_stars(200);
  40. echo show_content($str, basename(__FILE__));
  41. ?>
We draw 200 overlapping stars using random colors, so we have some issue to care. Flash has various way to draw overlapping figures, one is using an explicit depth stored in swf (e.g. when use placeObject2 tag), another is when you are dealing with actionscript. Specific shape management (via defineShape tag) has an internal z-depth governated by styleChange record.
increase_shapeDepth() establishes a new z-depth in shape container, so new shapes can overlap. I you draw overlapped shapes on the "same plane" you will get (odd/even fill style. That's reasonable if it is desidered rendering result, take care if you have plenty shape drawn in this way you may cause flash player to crash.
Note that if you increase_shapeDepth you must care to assign fill/line styles, because you are in a new z-depth and start a fresh style set.

mikrokosmos