sample #15
masking and clipping
  1. <?php
  2. include("sample_utils.php"); // provides some utils and using mk
  3.  
  4. $swfFN = "test_clipdepth01.swf"; // will output with this file name
  5.  
  6. $ds1 = new MKshape_container(); // let's begin to draw
  7. $ds1->add_fillStyle_solid("#FF9966"); // create new color to fill
  8. $ds1->add_rect(0, 0, 148, 74); // draw a rectangle
  9.  
  10. $svgFN = "o.svg"; // we use an svg file
  11. $ssr = new MKsimple_svg_reader($svgFN); // open it and read data,
  12. // now we are dealing to an mk_shape_container
  13. // object instance
  14. $ssr->set_shapeID(2); // assign item id
  15. $ssr->set_mask(4); // use is as mask
  16.  
  17. $ds2 = new MKshape_container("", 3); // another shape
  18.  
  19. for($i = 0; $i < 80; $i++){ // ...
  20. $ds2->add_fillStyle_solid(get_random_color()); // draw 80 random ...
  21. $r = rand(5, 30); // circles
  22. $x = rand(-100, 100); // ...
  23. $y = rand(-100, 100); // ...
  24. $ds2->add_circle($r, $x, $y); // ...
  25. }
  26. $ds2->move(100, 100); // move to final position
  27.  
  28. $swf = new MKswf($swfFN); // create new swf
  29. $swf->set_swfDir(SERVER_MKTMP); // set working directory
  30. $swf->set_stageWidth(148); // assign canvas width
  31. $swf->set_stageHeight(148); // ... and height
  32.  
  33. $t1 = $ds1->update_tagData(); // get binary data
  34. $t2 = $ds1->update_place_tagData(); // placing settings data
  35. $t3 = $ssr->sc->update_tagData(); // ...
  36. $t4 = $ssr->sc->update_place_tagData(); // ...
  37. $t5 = $ds2->update_tagData(); // ...
  38. $t6 = $ds2->update_place_tagData(); // ...
  39.  
  40. $swf->add_tagData($t1); // populate swf
  41. $swf->add_tagData($t2); // ...
  42. $swf->add_tagData($t3); // ...
  43. $swf->add_tagData($t4); // ...
  44. $swf->add_tagData($t5); // ...
  45. $swf->add_tagData($t6); // ...
  46. $swf->swf_output(); // save to disk
  47.  
  48. $swfHeader = $swf->fetch_assoc(); // prepare to publish
  49.  
  50. $str = render_swf_box($swfHeader, $imgDir, false);
  51. $str .= "<br/><strong>" .$swfFN ." created in :<br />" .SERVER_MKTMP ."</strong>";
  52. echo show_content($str, basename(__FILE__));
  53. ?>

masking is a technique for drawing shape or rendering image clipping in another shape. The way to mask is very similar to use drawing api as seen in sample #03, it differs by using set_mask and take care to the queue used to populate swf with tags. Object that will "mask" has item ID lower than the masked objects, but it must set a number of z-depth (the argument passed to set_mask) higher to the subsequents items id.

 

mikrokosmos