how i display the coordinates of a random triangle in a graph which ranges from -10 to +10 in XY axis with the points like A(2,1) etc with arcs in each corner, in actionscript 2.0
相关问题
- Should I wait for Flash Player 10.1 or go with Fla
- Unity - Get Random Color at Spawning
- How to load flex swf from flash?
- How to determine +/- sign when calculating diagona
- How to generate a random number, then display it o
相关文章
- Mercurial Commit Charts / Graphs [closed]
- why 48 bit seed in util Random class?
- Algorithm for partially filling a polygonal mesh
- Robust polygon normal calculation
- Algorithm for maximizing coverage of rectangular a
- Need help generating discrete random numbers from
- Get random records with Doctrine
- SVG circle starting point
OK, so far we've done triangles with arcs, triangles on a grid, and triangles with coordinates. Now it's time to combine all these into one piece of code. You've asked for a grid size of -10 to +10, but it's only a little bit more work to make it work for any size grid (well, within limits).
We need to deal with converting between your chosen range (-10 to +10) and the size of your stage (in pixels). The trick to this is to create a movieClip ('myGraph') to hold our -10 to +10 grid, and then scale it up to fit the size of the stage (we'll leave a 20 pixel margin around the edge); we'll calculate a rectangle ('displayRect') to represent the maximum size we'd like myGraph to be. We also want to position myGraph so it's origin is in the right place, and flip it vertically so the Y-axis increases as you move upward on the screen.
Once we've done all that, we can draw inside myGraph using our desired units (-10 to +10) with no further need to convert into pixels - the scaling of myGraph takes care of that for us automatically.
Next, we make a 'grid' clip inside myGraph, and draw a grid in it using the drawGrid() function.
Then we make an 'arcTriangle' clip inside myGraph, and draw our triangle inside it. We use the same technique as previously, by drawing our triangle, drawing a red circle at each corner, then using a copy of the triangle as a mask to reveal only the internal arcs of the circles. Then we make a textField at each corner to display the coordinates of each point (note that these need to be scaled back up to normal size, otherwise the text is too small to read!).
Lastly, we add an onRelease function to myGraph, which draws a new random arcTriangle when clicked.
alt text http://roi.webfactional.com/img/so/arctriangles.jpg
Here's the code...
Remember: you can accept a favourite answer to each of your questions by clicking the big tick-mark (tick http://roi.webfactional.com/img/so/so_tick.png) on the left-hand side. Thank you.