Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>First of all let me tell you I created an account to answer this question because the current project I'm working on does the same thing you define. For a demo you can check my <a href="http://www.captionmash.com/" rel="nofollow noreferrer">application</a> page.</p> <p>Here's how my bubble algorithm works basically:</p> <p><strong>1- Bubble drawing:</strong> For a circular or rectangular bubble, default actionscript drawRoundRect and drawEllipse methods are used. For scream (spikey) and thought bubbles I used 2 ellipses. For scream bubble outer ellipse has the start and end points whereas inner ellipse has control points for cubic bezier curve. For thought bubble outer ellipse has control points and inner ellipse has start and end points. I found the cubic bezier drawing class from cartogrammar [dot] com/blog, if it's not still there, I can send you the class, just drop me a message.</p> <p><strong>2- Tail drawing:</strong> This is the tricky part, to create a sleek comic bubble tail effect I used an isosceles triangle, whose equal edges can be also bent. The middle point of the base of the triangle is also the middle of the bubble. </p> <p>When you click and drag the endpoint of the bubble tail around, the base of the triangle faces the mouse pointer coordinates using arctangent function, then the endpoints of the base of the triangle are set to precalculated points. </p> <p><strong>Arctangent function:</strong></p> <pre><code> //p1= center of circle //p2= target point //find angle between point 1, point 2 and y=0 line and returns degree value private function findAngle(p1:Point,p2:Point):Number{ var rad:Number = 0; var angle:Number = 0; if(p2.x - p1.x == 0 || p1.x - p2.x == 0){ angle = -90 }else{ rad = Math.atan((p2.y-p1.y)/(p2.x-p1.x)); angle = Math.floor((rad * (180/Math.PI))); } return angle; } </code></pre> <p><strong>Here's how I calculated the potential endpoints for the triangle base:</strong></p> <pre><code> //calculates circle points for drawing tail triangle private function calculateCircle():void{ var steps:uint = 360; var rad:Number = CENTER_RADIUS; //delete array this.circleArray.splice(0); for(var i:int = 0; i &lt; 360; i+= 360/steps){ var alpha:Number = i * (Math.PI /180); var sinAlpha:Number = Math.sin(alpha); var cosAlpha:Number = Math.cos(alpha); var circX:Number = circleCenter.x + (rad * cosAlpha); var circY:Number = circleCenter.y + (rad * sinAlpha); var p:Point = new Point(circX,circY); this.circleArray.push(p); } } </code></pre> <p>My last problem was handling outlines and inside of the bubble graphics. Normally when you draw tail above the bubble the two sides of the triangle (tail) goes right into the center of the bubble. If you put the bubble on top, then the bubble outline cuts the tail. I'm an Actionscript newbie so it didn't come to me quick but adding graphic layers with the order BubbleTailOutline, Bubble,BubbleTailInside solved the problem. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload