Jump to content

How to draw a circle with different colours. PLEASE HELP

- - - - -

  • Please log in to reply
1 reply to this topic

#1
ramin

ramin

    Newbie

  • Members
  • Pip
  • 9 posts
Hello

I need help with this exercise. I hope someone can help me.

I need to create a program that draws circles in the middle of a DrawingPanel and draw them in different colors from red to blue via green. The program will ask the user how many circles to be drawn out and then plot them. Part of the program should be a method drawColoredCircles that draws circles, another part asks the user how many people will be drawn out. The circles should be drawn up from the inside out, they should be completely symmetrical circles and not ovals, and they should be drawn up for each other delays. Each circle should be larger than the previous one and the circles color codes will vary so that the transitions between the three primary colors are as soft as possible.
Use it properly documented version of DrawingPanel.java for this task.

I allready have this code but I don't know how to continue from it.

public static void main(String[] args) {
DrawingPanel panel = new DrawingPanel(500, 400);
Graphics2D g = panel.getGraphics();
int distance = 10;
int max = 16;
for (int i = 0; i < max; i++) {
g.setColor(new Color(255 - i, 0, i));
g.setStroke(new BasicStroke(2));
int width = 10 + i * distance;
g.drawOval(0, 0, width, width);
}
}

These are the steps i need to do after:
Step 2 I need to extend the code so it just don't make circles that goes from red to blue but it goes also from red to blue via green. "Use a for loop and an if statement in the loop to determine if one is to mix red and green or green and blue."

Step 3 I need a delay between each circle so that i can see when they are drawn up. And the program should also ask the user how many circles to be plotted

This is how it is supposed to look like after all is done.

Posted Image

thanks in advance.

#2
gregwarner

gregwarner

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 853 posts
  • Location:Arkansas
To blend from blue to green and then to red, you'll need to know when you're halfway through the loop, as well as whether you're in the first half or the 2nd half. By dividing max by 2, you can find the midpoint--that is, the point at which the blending should be 100% green. Whether i is less than, equal to, or greater than this midpoint will tell you which blending formula to use. (Blend blue to green, use 100% green, blend green to red, respectively.)

To make a process delay, use this statement:

try { Thread.sleep(1000); } catch (InterruptedException ex) { }


The parameter of the sleep() method is simply the number of milliseconds you wish to pause. 1000 is 1 second. Adjust for your needs.
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.

– Douglas Hofstadter, Gödel, Escher, Bach: An Eternal Golden Braid





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users