TwelvestoneFlash

Creating polygons


Sign in

  • Waiting for Godot ( 720 k posts )
    Just conversation.
  • Thunder Dome ( 23 k posts )
    Photoshop Tennis and Collabs.
  • Photography ( 4.8 k posts )
    For all you shutterbugs, sh...
  • Flash ( 18 k posts )
    ActionScripting to tweens, ...
  • Front End ( 5.8 k posts )
    general front end design an...
  • Back End ( 9.6 k posts )
    serverside scripting, progr...
  • Projects and Theory ( 12 k posts )
    This forum is for discussio...
  • FAQ ( 269 posts )
    All those nagging questions...
  • Design ( 17 k posts )
    graphics & all aspects of g...
  • Purgatory ( 3.6 k posts )
    12stone Jail, feel free to ...
Napalm
 
2003-02-04

I want to create a polygon in flash, with the cornerpoints draggable. Then I want a button/MC attached to the "path" created by the polygon and have that draggable as well, with it stopping when the button is clicked. Is this possible?

garyalfred
 
2003-02-04

probably k

bit-101
 
2003-02-04

no. i just asked my friend. he said it's impossible.

ok, seriously folks. just make a few movie clips assign on press and on release functions to start and stop drag, then an onEnterFrame function that moveTo's the first one's coordinates, then loops through the rest of them with lineTo.

Napalm
 
2003-02-04

I found this:http://www.jurjans.lv/flash/poly.html but all the maths makes my head hurt.

sakri
 
2003-02-04

I had a few minutes to spare so I took on the challenge...

if you paste this script into MX and test movie, you'll get the polygon with draggable corners... it updates the drawing as soon as you release a corner...

I ran out of playtime so you'll need to complete it yourself... but I'm sure this will get you started :

//creates a draggable centered //transparent square of "drag_size" size. //updates polygon on release MovieClip.prototype.make_drag=function(){ var drag_size=8; var p=drag_size/2; this.lineStyle(0,0xFFFFFF,0); this.beginFill(0xFFFFFF,0); this.moveTo(_x-p,_y-p); this.lineTo(_x-p,_y-p); this.lineTo(_x+p,_y-p); this.lineTo(_x+p,_y+p); this.lineTo(_x-p,_y+p); this.lineTo(_x-p,_y-p); this.endFill(); this.onPress=function(){ this.startDrag(); } this.onRelease=function(){ stopDrag(); this.parent.draw(); } }

//constructor for "draggable polygon" object D_polygon=function(points,radius,x,y){ this.points=points; this.radius=radius; this.x=x; this.y=y; this.init(); }

//creates a circle with "points" amount of //draggable movieclips D_polygon.prototype.init=function(){ this.base=_root.createEmptyMovieClip("base",1); var space=360/this.points;//degrees between each point this.clips=new Array(); var a=0; while(a<this.points){ this.clips[a]=this.base.createEmptyMovieClip("c"+a,a); this.clips[a].parent=this; this.clips[a]._x=this.x+this.radius*Math.sin((a*space)*Math.PI/180); this.clips[a]._y=this.y+this.radius*Math.cos((a*space)*Math.PI/180); this.clips[a].make_drag(); a++; } this.draw(); }

//draws the polygon depending on x //and y positions of clips cotained in clips[] D_polygon.prototype.draw=function(){ this.base.clear(); this.base.lineStyle(1,0x000000,100); this.base.beginFill(0xFFFFFF,0); var a=0; this.base.moveTo(this.clips[a]._x,this.clips[a]._y); while(a<this.points){ this.base.lineTo(this.clips[a]._x,this.clips[a]._y); a++; } this.base.endFill(); }

shape=new D_polygon(10,100,200,200);

if you have any questions, don't hesitate to ask!

k

Phantom
 
2003-02-04

Why does Bit's seem like is a piece of piss, when that last example is like 963 lines of code long??

Bit, I have ultimate faith in your mastery - don't suppose you have a little example of the code you would use??

P.

jimmyn
 
2003-02-04

nice code sakri!

this reminds me of an expermient i made quite awhile back in flash 5.

http://www.musicfuel.net/gallery/polybuild.html

polygons aren't too difficult to make, just need a basic equation to plot the points. really they are nothing more than a low quality circle...so in essence a circle is a polygon with infinite points. to create a polygon, you just draw a circle with a finite number of points. to do so, divide 360 (or 2 * Math.PI) by your number of points to give a degree/radian distance between them. once you have that you can use a little trigonometry with our friend the unit circle and place the points in coordinate space.function getPolygonPoints(intSides, dblRadius) { // Calculate the degree shift between points in radians var rad = (2 * Math.PI) / intSides;

// Create a new array to hold the points
var points = new Array();

// Run a loop to build a point list in the array
for (var i=0; i < intSides; i++)
{
    // Store the point as an object with x and y properties
    points[i] = {
                x: dblRadius * Math.sin(rad * i),
                y: dblRadius * Math.cos(rad * i)
                }
}

// Return the populated array
return points;

}

// EXAMPLE: Creates an octagon with a radius of 100 // then draws the points using movieclips at an origin of 200,200 p = getPolygonPoints(8, 100); for(i=0; i<p.length; i++) { this.attachMovie("ball", "b" + i, i); this["b" + i]._x = p[i].x + 200; this["b" + i]._y = p[i].y + 200; }once you have the points for the polygon you can do whatever you want with them.

hope this helps!

Napalm
 
2003-02-05

Thanks a lot guys for all the help. Really appreciate it. k

Sorry, you must be a member to post to a conversation. Either log in or sign up to get involved.
TwelvestoneFlash

Creating polygons