Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Drawing arcs in Swing  RSS feed

 
Kaspersky Ukshini
Ranch Hand
Posts: 122
C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello guys, I know the concept of how Threads work, and learning to play around with them won't be a problem I believe. I first need help to draw this exact shape, which later I will have to make it move anti-clockwise, but for now, I need some ideas on how to draw this thing:



First thing I can think of is drawArc, but not so sure...
 
Kaspersky Ukshini
Ranch Hand
Posts: 122
C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anyone please? This is really important for me, I need it for a school assignment ..
 
Henry Wong
author
Sheriff
Posts: 23275
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Question 1. What does threads have to do with this? It sounds like you are thinking about animation, and that somehow needs threads. Before you can animate, you need to draw on frame, and before you can draw one frame, you need to draw one circle, and before ... etc. You need draw one dot first.

Question 2. How much of your high school geometry do you remember?

A. Given two points, how do you calculate the distance between them?
B. Given one point and distance, can you calculate the other point? Or is it multiple point?

Try to figure out the math for this first. After that you can apply the math to get to what is needed to draw a circle.

Henry
 
Henry Wong
author
Sheriff
Posts: 23275
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kaspersky Ukshini wrote:
First thing I can think of is drawArc, but not so sure...


Oh yea, I completely forgot that Java did all the work of drawing a circle for you. So, yes, you can skip all the calculations and let the drawArc() method draw the circle for you.

So... what is it that you are not sure of?

Henry
 
Kaspersky Ukshini
Ranch Hand
Posts: 122
C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Henry Wong wrote:
Kaspersky Ukshini wrote:
First thing I can think of is drawArc, but not so sure...


Oh yea, I completely forgot that Java did all the work of drawing a circle for you. So, yes, you can skip all the calculations and let the drawArc() method draw the circle for you.

So... what is it that you are not sure of?

Henry


I need to make it look the one in the picture, I guess I need a critcle within a circle, or if possible a circle with bolded border, so I can fill it with colors then.
What I've no idea how to do is fill if with collors like it's done in the picture.

The thing about the threads is that it's not up to me how to solve it, they're asking specificaly to solve it with threads, because the colors need to move anticlockwise every X milliseconds, to make it look like an animation, that's the main point.
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So you've got two things to do:

1. Draw those arcs

2. Make them move with threads

Since you haven't figured out how to do #1 yet, there's no point in bringing #2 into the picture. You're just muddying the waters and confusing things.
 
Kaspersky Ukshini
Ranch Hand
Posts: 122
C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know how to draw the arcs, I need help filling them with colors like in the picture..
 
Piet Souris
Rancher
Posts: 1943
66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, easiest that I can think of:

1) create a BufferedImage, type int_argb;
2) make sure the image is fully transparant
3) draw the arcs in this BI, using a sufficient strokewidth
4) then, in a loop, draw this BI, each passage rotated slightly more than it's predecessor.

Greetz,
Piet
 
Paul Clapham
Sheriff
Posts: 22374
42
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Once you've created the arcs, then make a (closed) path out of them and fill the area inside that path with some colour. Am I right in assuming that you used Arc2D objects to draw the arcs? (I have to guess because there's no code to discuss.) Then use other classes in the same package to do the rest.
 
Campbell Ritchie
Sheriff
Posts: 55334
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doesn't Graphics have a fillArc method? You can use it 6× and then fill a circle on top of them.
 
Kaspersky Ukshini
Ranch Hand
Posts: 122
C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Done it guys!
Thanks a lot to all of you! You are helping a lot, really
 
Campbell Ritchie
Sheriff
Posts: 55334
157
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!