Skip to main content
Participating Frequently
April 1, 2008
Question

Simple but frustrating problem, please help

  • April 1, 2008
  • 7 replies
  • 635 views
Hi,

I've been reading through a ton of resources and even worked through the "Flash CS3 Profession" book and finally started working on a project.

Basically I need to create a circle with 12 evenly spaced points on it. (360/12 = a point every 30 degrees on the circle).

Then depending on which point the user clicks I want to connect that point to two other ones via line segments to create a triangle inside the circle.

I'm really stuck about the best way to go about this, and am in over my head with the graphics / geometry class here.

Please help or point me in the right direction.
This topic has been closed for replies.

7 replies

kglad
Community Expert
Community Expert
April 1, 2008
that's not going to work. assign centerX and centerY to be 0 and 0 and you'll see what you're really doing.

with centerX and centerY greater than r, you're not doing anthing by using Math.abs().

i'd use a variable to indicate if sharps or flats are to be displayed. then use an if-statement to assign text to the notes.
Dean071Author
Participating Frequently
April 1, 2008
Hey, not sure if you're still checking this (since I marked it answered), but here goes...

I wanted to modify it so the points start at the top of the circle and go clockwise right. After working through your code and re-acquainting myself with some of this trig stuff, I came up with this:

pt.x = Math.abs(r*Math.sin(i*Math.PI/180)+centerX);
pt.y = Math.abs(r*Math.cos(i*Math.PI/180)-centerY);

Do you see any problems doing it that way? It worked on the preview, I just have to modify the text label positioning.

Also, since this is for musical notes (i.e. C, C#, D, E#) I wanted to put a button on the stage that lets the user choose whether they see sharps or flats on the labeling -- so C, C# vs. C, Db.

Would it be best to take the textual label part of the code and put it into it's own function that handles the event of whether the "Sharps/Flats" button is pushed?

Could I just make an array with the note names...one for sharps and one for flats, and then apply one or the other depending on the stage button?

Dean071Author
Participating Frequently
April 1, 2008
Hey, thank you so much for all the help.

One last thing...when adding the labels, how do I attach them to the points? I was looking for a function of "pt" like ".addLabel" but didn't see anything.

I'm guessing I have to use another type of object for it but I'm a little confused.

Thanks again, I'll be marking your previous post as the answer later today.
kglad
Community Expert
Community Expert
April 1, 2008
i don't know what kind of labels you want to use. you could create a movieclip with textfield or just create a textfield dynamically:



Dean071Author
Participating Frequently
April 1, 2008
Oh wow, that's pretty handy. I've got the code printed out and will be working through it just to understand the logic.

Thank you immensely. I'd probably be banging my head against a wall trying a million things without your help.
kglad
Community Expert
Community Expert
April 1, 2008
and you can make that for-loop a little more efficient by using:

for (var i:int=0; i<360; i+=30) {
// comment out the if(i%30)
// and there's no need to define ivar. just use i instead of ivar.
Dean071Author
Participating Frequently
April 1, 2008
Hey that code you sent looks pretty cool. It's not exactly what I need but it's a huge help as far as understanding it goes. I'm gonna pore over it for a little bit.

The one thing I need to change-- clearing the former triangles when a new point is clicked (should just be a call to "clear" I'm thinking). The program is actually for explaining a certain piece of music theory if you're interested.

It's an animated version of this:
http://web.mac.com/noshufuru/iWeb/Master%20Class/Page%203_files/droppedImage_1.png

I guess I don't really need the outside circle. What would be the best way to "attach" the note names to the created points?

Thanks again, you saved me a lot more frustration.
kglad
Community Expert
Community Expert
April 1, 2008
here's without the outside circle and clearing previous triangles. there's a comment where you would add your label:

kglad
Community Expert
Community Expert
April 1, 2008
here's one way to do it if you want to pick random (except for the clicked point) pts to form the triangle:

kglad
Community Expert
Community Expert
April 1, 2008
how do you determine the two other points to use in forming your inscribed triangle?
Dean071Author
Participating Frequently
April 1, 2008
Edit: Just saw your second post, the following applies to your original query. I'll take a look at the code you posted in the meantime.

It will always form an equilateral triangle. So if the first point is the top of the circle (point 1), it would draw the following line segments to make the triangle (assuming clockwise numbering and evenly spaced point from 1 - 12)

Segment from point 1 to point 5
Segment from point 5 to point 9
Segment from point 9 back to point 1

If they used point to as the starting point the triangle would essentially just "rotate" one point to the right because the shape is always equilateral.
kglad
Community Expert
Community Expert
April 1, 2008
here are equilateral triangles: