sample #09
"holed" figures and fillstyles
  1. <?php
  2. include("sample_utils.php"); // provides some utils and using mk
  3.  
  4. $sc = new MKshape_container(); // the shape
  5.  
  6. $maxIteration = 30;
  7.  
  8. for($i = 0; $i < $maxIteration; $i++){
  9. $x = $i * 20;
  10. $y = cos(deg2rad($x)) * 80 + 100;
  11. trace_var($y, "Y");
  12. $sc->clear_fillStyle(); // prepare to draw
  13. $sc->add_fillStyle_solid("#FF9900"); // fill color, orange
  14. $sc->add_circle(9, $x, $y); // a circle with radius, x,y
  15. $sc->select_fill(LEFT_FILL); // prepare to draw hole
  16. $sc->add_circle(3, $x, $y); // a circle with radius, x,y
  17. }
  18.  
  19. $sd = $sc->update_tagData(); // get shape tag
  20. $po = $sc->update_place_tagData(); // get placing data
  21.  
  22. $swf = new MKswf("test_draw02.swf"); // start a fresh swf
  23. $swf->set_swfDir(SERVER_MKTMP); // change default working dir
  24. $swf->add_tagData($sd); // populate with shape
  25. $swf->add_tagData($po); // place on stage
  26. $swf->swf_output(); // save to disk
  27.  
  28. $swfHeader = $swf->fetch_assoc(); // get swf header info
  29.  
  30. $str = render_swf_box($swfHeader, $imgDir, false);
  31. $str .= "<br/><strong>test_draw02.swf created in" .SERVER_MKTMP ."</strong>";
  32. echo show_content($str, basename(__FILE__));
  33. ?>
flash use proprietary attributes to fill shapes: "right" and "left" fills. In real vector drawing shapes often contain several nodes/coordinates an they can be combined in holed figures. Flash creators (future splash in origin) thought this way to ease computations: depending on what is "drawing direction" it is convenient to choose right or left fill.

E.g. let's say we have a circle, flash usually needs 8 curves to draw it with accuracy. Drawing circle requires a call to moveTo and 8 curveTo, the end point of a curveto is implicit coincident to the start point in the next curveto. So you get a direction that will be considered clockwise or counter-clockwise.
Mk tries to handle properly drawing "sense" when e.g. importing data from svg, but it's up to you choose the correct attribute when dealing with mk drawing api.
All shapes in mk draw in clockwise direction so if you have to draw an outbound shape you have automatically right fill selected, for draw holes you must select left fill (LEFT_FILL flag). An exception to this rule is when using MKshape_container->add_mixed_poly(), you must care what is drawing direction since a fundamental parameter is an array of coords that can be freely computed cw o ccw.
So in may cases if we draw a closed shape in clockwise direction, we have to select RIGHT_FILL, and that is selected by default, no explicit call is needed.
When draw an holed figures you have to select LEFT_FILL because to that side you have the fill of the larger shape drawn before. RIGHT_FILL will be an empty fillstyle, that will result a combined holed shape.

Pay attention when drawing holed figures, if you don't use LEFT_FILL flash probably will render correctly, but it is also probabile to get errors if you try to import in flash IDE, for many shapes flash will probably result in crashes.

Drawing overlapping shape is like to draw odd/even fill style, overlapping area will be like an hole, in some case clear_fillStyle()is useful to prepare next drawing shape.
If you don't know how draw correctly you can choose a very convenient method: increase_shapeDepth, you will see in action in sample #10.
mikrokosmos