Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Drawing multiple circles in a panel



Hi,
yes this is for a school project, but i am not trying to get a fast answer for homework. My project is creating a Cellular Automata style music machine where the computer makes a melody that evolves over time by the addition of other melodies that are created based on the first one. This part is just an addition so that it looks nice.
What I am trying to do is create a circle which is constructed by creating arc fills which represent the notes in the melody currently playing (color coordinated). The purpose is to add a new colored circle(or bunch of arc fills) in the panel to represent the addition of a new melody. In the program, each of the previous melodies gets quieter as more new melodies get added. I am trying to shrink the size of the previous circles to represent this.
Originally i was able to draw to the panel a circle and then draw another smaller circle on top with the code I gave. Then when I tried to create an array to hold all of my circles so that it could remember what colors were chosen for its construction, all that happens now is the most recent circle is drawn and that is all.


I don't know if this helps you understand what I am doing.
Thanks for the reply though,
Jay

On 10-Apr-05, at 1:40 PM, Greg Guerin wrote:

Jason Smalridge wrote:

I am trying to draw multiple circles (actually arcs to make one circle) on
top of one another in a panel.

Are the circles filled or stroked (outlined) or both? I don't have a
precise mental picture of what "draw" means here. I have even less of a
picture of how the arcs and concentric circles or arcs work.


Are you trying to emulate an animation of some kind?  If so, what?

Exactly what is the context for your question? It looks to me like a
homework problem for a programming course, but I'm just guessing.
Personally, I'm reluctant to give you complete homework answers, but I'm
happy to point you to resources or offer suggestions.


What is your Java experience level? If you haven't worked a lot with Swing
components, you should at least browse the Swing tutorial:
<http://java.sun.com/docs/books/tutorial/uiswing/TOC.html>



What I want is to draw one circle (c1) in a panel, then after some time
erase the panel and redraw c1 a little smaller and draw a second circle(c2)
on top at the original size of c1. This will continue as more circles are
drawn on top of the previous circle which decrease in size each time
creating a sort of tunnel(each circle a low alpha so you can see what is
behind it.

Another algorithm that produces the same results (concentric circles) is to
not change the size of any circle once it's drawn, just add a new circle
that's smaller than its predecessor. (How that fits in with the arcs you
mentioned, I don't know. I don't get a mental picture from your
description or your code, so I don't understand what you're trying to do
with arcs.)


To draw concentric circles:
Draw C1 with diameter D. Draw C2 with diameter D-K, where K is the
"shrinkage" amount at each time-step. At each iteration, reduce the
diameter further, so C3 is D-2K, etc. The diameter is D-(i*K), where i is
the index (or position in time or array) of that circle.



First I can't seem to get the circles to draw on top of each other. Each
time I draw another circle it erases the first circle so that the newest
circle is the only one that shows.

I suggest a different strategy than the one you've adopted. Instead of a
JComponent per circle, which are then added to a JPanel, define a single
class that handles all the circles and circle-drawing. You can simply
subclass JComponent to do this, and there's only one instance per "tunnel"
drawn.


If you insist on a JComponent per circle, you'll have to set each component
to non-opaque, and make sure it works correctly when it completely overlaps
other components. In general, components are mostly intended to be
non-overlapping, so that strategy goes against the grain of JComponent,
JPanel, etc.


Also, if all your JComponents are at the same location in the parent
JPanel, the panel itself needs an appropriate layout manager, appropriate
Z-layer management, and so on. Do you really want to learn all that just
to draw concentric circles, when a single JComponent would work as well?



Second, I created an array of my circle object that holds the circles as
they are created. What I need to do is to push back the first circle to the
second position in the array when a second one is created and on and on
like that.

See java.lang.System.arraycopy(): <http://java.sun.com/j2se/1.4.2/docs/api/java/lang/System.html>

Or walk the array of circles backwards. You add new ones at the end of the
array, and draw them from highest index to lowest, which will be newest to
oldest.


Or if you want to draw largest to smallest, and no circle's diameter ever
changes (per above), add to the end of the array and draw from index 0
upwards. Or to draw smallest to largest, add to end of array and draw from
highest valid index downwards.


  -- GG


_______________________________________________ Do not post admin requests to the list. They will be ignored. Java-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden

_______________________________________________ Do not post admin requests to the list. They will be ignored. Java-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden
References: 
 >Re: Drawing multiple circles in a panel (From: Greg Guerin <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.