I'm working on some exercises and I've been stuck on this for some hours now (quite new to Java).
Anyhow, this is what I'm supposed to do:
When I run the program I will have a square in the middle of the screen and when I then click somewhere within that screen another square will be drawn at the place where I clicked and in-between these two points there are supposed to be 10 squares. So wherever I click there should always be 10 squares drawn between.
However, I can't make it to function properly.
This is what I've managed to do so far:
import se.lth.cs.ptdc.window.SimpleWindow;
import se.lth.cs.ptdc.square.Square;
public class PrintSquares2 {
public static void main(String[] args) {
SimpleWindow w = new SimpleWindow(600, 600, "PrintSquares2");
int posX = 300;
int posY = 300;
int loop = 0;
System.out.println("Skriv rotation");
Square sq1 = new Square(posX,posY,200);
sq1.draw(w);
w.waitForMouseClick();
int destX = w.getMouseX();
int destY = w.getMouseY();
System.out.println("Dest X: " + destX + " Dest Y: " + destY);
System.out.println("Pos X: " + posX + " Pos Y: " + posY);
SimpleWindow.delay(10);
//sq1.erase(w);
int jumpX = (destX - posX) / 10;
int jumpY = (destY - posY) / 10;
System.out.println(jumpX);
while (posX < destX)
{
posX = posX+10;
SimpleWindow.delay(100);
loop++;
System.out.println("Loop: " + loop);
System.out.println("Dest X: " + destX + " Dest Y: " + destY);
System.out.println("Pos X: " + posX + " Pos Y: " + posY);
Square sq2 = new Square(posX,posY,200);
sq2.draw(w);
}
while (posX > destX)
{
posX = posX-10;
SimpleWindow.delay(100);
loop++;
System.out.println("Loop: " + loop);
System.out.println("Dest X: " + destX + " Dest Y: " + destY);
System.out.println("Pos X: " + posX + " Pos Y: " + posY);
sq1.draw(w);
Square sq2 = new Square(posX,posY,200);
sq2.draw(w);
}
while (posY < destY)
{
posY = posY+10;
SimpleWindow.delay(100);
loop++;
System.out.println("Loop: " + loop);
System.out.println("Dest X: " + destX + " Dest Y: " + destY);
System.out.println("Pos X: " + posX + " Pos Y: " + posY);
sq1.draw(w);
Square sq2 = new Square(posX,posY,200);
sq2.draw(w);
}
while (posY > destY)
{
posY = posY-10;
SimpleWindow.delay(100);
loop++;
System.out.println("Loop: " + loop);
System.out.println("Dest X: " + destX + " Dest Y: " + destY);
System.out.println("Pos X: " + posX + " Pos Y: " + posY);
sq1.draw(w);
Square sq2 = new Square(posX,posY,200);
sq2.draw(w);
}
SimpleWindow.delay(10);
sq1.draw(w);
//SimpleWindow.clear(w);
}
}
I'm pretty sure that I overcomplicated everything since this should be pretty basic.
The end result is supposed to look like this:
End result
This is the way I'd have solved it:
I didn't quite understand the documentation on se.lth.cs.ptdc.square.Square but I'll assume it draws a square given the coordinates of its top-left corner and a side size.
So you have the coodinates of your first square's left-top corner and the coordinates of the last square's center. Having that it's not difficult to get the coords of the last square's top-left corner:
lastX = centerX - side/2
lastY = centerY - side/2
After you have that you find the difference between the starting and ending points:
diffX = posX - lastX
diffY = posY - lastY
and after that just draw 9 more squares:
for (int i=1; i<10; i++){
squareX = posX + (diffX/10)*i;
squareY = posY + (diffY/10)*i;
Square square = new Square(squareX,squareY,200);
square.draw(w);
}
Actually you did the first part right, just messed up with those unnecessary checks. Hope it helps.
--
Regards, svz.
Update both X and Y at the SAME time :
int jumpX = (destX - posX) / 10;
int jumpY = (destY - posY) / 10;
if (posX > destX) {
int temp = destX;
destX = posX;
posX = temp;
}
while (posX <= destX)
{
SimpleWindow.delay(100);
loop++;
System.out.println("Loop: " + loop);
System.out.println("Dest X: " + destX + " Dest Y: " + destY);
System.out.println("Pos X: " + posX + " Pos Y: " + posY);
Square sq2 = new Square(posX,posY,200);
sq2.draw(w);
posX = posX+jumpX;
posY = posY+jumpY;
}
SimpleWindow.delay(10);
sq1.draw(w);
Here's how you move in two directions at once (on a diagonal).
static final int Steps = 10;
private void test() {
int x1 = 100;
int y1 = 100;
int x2 = 300;
int y2 = 500;
double dx = (double)(x2 - x1) / (double) Steps;
double dy = (double)(y2 - y1) / (double) Steps;
double x = x1;
double y = x2;
for ( int i = 0; i < Steps; i++) {
// Simulate the drawing of the square.
System.out.println("("+x+","+y+")");
x += dx;
y += dy;
}
}
Related
I made a method in my Java code which translates a 3 coordinate vector into another 3 coordinate system basing my method on the rotation matrix which OpenGL used to have, here is the full method:
public static float[] rotateVector3 (float x, float y, float z, double rX, double rY, double rZ){
float[] ret = {x,y,z};
while(rX < 0){rX += Math.PI*2;}
while(rY < 0){rY += Math.PI*2;}
while(rZ < 0){rZ += Math.PI*2;}
while(rX >= Math.PI*2){rX -= Math.PI*2;}
while(rY >= Math.PI*2){rY -= Math.PI*2;}
while(rZ >= Math.PI*2){rZ -= Math.PI*2;}
//ret[0] *= 1;
ret[1] *= Math.cos(rX) - Math.sin(rX);
ret[2] *= Math.sin(rX) + Math.cos(rX);
ret[0] *= Math.cos(rY) + Math.sin(rY);
//ret[1] *= 1;
ret[2] *= - Math.sin(rY) + Math.cos(rY);
ret[0] *= Math.cos(rZ) - Math.sin(rZ);
ret[1] *= Math.sin(rZ) + Math.cos(rZ);
//ret[2] *= 1;
System.out.println("(" + x + " " + y + " " + z +") -> (" + rX + "º " + rY + "º " + rZ + "º) = (" + ret[0] + " " + ret[1] + " " + ret[2] + ")");
return ret;
}
However this method for some reason does not work well with the Z axis.
Let's assume for instance that i have 4 arrays representing vectors, each with 3 coordinates (XYZ respectively):
vecA = {50,50,1}, vecB = {50,-50,1}, vecC = {-50f,-50f,1}, vecD = {-50f,50f,1}
When I input those values in their respective order in the method, with each value of the rotation being {0,2,0} radians respectively, I get the following output:
(50.0 50.0 1.0) -> (0.0º 2.0º 0.0º) = (24.65753 50.0 -1.3254442)
(50.0 -50.0 1.0) -> (0.0º 2.0º 0.0º) = (24.65753 -50.0 -1.3254442)
(-50.0 -50.0 1.0) -> (0.0º 2.0º 0.0º) = (-24.65753 -50.0 -1.3254442)
(-50.0 50.0 1.0) -> (0.0º 2.0º 0.0º) = (-24.65753 50.0 -1.3254442)
Which does not make sense. As I am rotating in the Y axis, the vectors with the Y coordinates above zero should be farther that those with the negative Y coordinates, yet it always returns the same Z values regardless and I'm not entirely sure why, is there any correction that I am missing?
Figured it out, the correct way to do this is
public static float[] rotateVector3 (float x, float y, float z, double rX, double rY, double rZ, float aX, float aY, float aZ){
float[] ret = new float[3];
while(rX < 0){rX += Math.PI*2;}
while(rY < 0){rY += Math.PI*2;}
while(rZ < 0){rZ += Math.PI*2;}
while(rX >= Math.PI*2){rX -= Math.PI*2;}
while(rY >= Math.PI*2){rY -= Math.PI*2;}
while(rZ >= Math.PI*2){rZ -= Math.PI*2;}
double cosX = Math.cos(rX);
double cosY = Math.cos(rY);
double cosZ = Math.cos(rZ);
double sinX = Math.sin(rX);
double sinY = Math.sin(rY);
double sinZ = Math.sin(rZ);
double Axx = cosX*cosY;
double Axy = cosX*sinY*sinZ - sinX*cosZ;
double Axz = cosX*sinY*cosZ + sinX*sinZ;
double Ayx = sinX*cosY;
double Ayy = sinX*sinY*sinZ + cosX*cosZ;
double Ayz = sinX*sinY*cosZ - cosX*sinZ;
double Azx = -sinY;
double Azy = cosY*sinZ;
double Azz = cosY*cosZ;
x-=aX;
y-=aY;
z-=aZ;
ret[0] = (float) (Axx*x + Axy*y + Axz*z);
ret[1] = (float) (Ayx*x + Ayy*y + Ayz*z);
ret[2] = (float) (Azx*x + Azy*y + Azz*z);
System.out.println("(" + x + " " + y + " " + z +") -> (" + rX + "º " + rY + "º " + rZ + "º) = (" + ret[0] + " " + ret[1] + " " + ret[2] + ")");
return ret;
}
I'd explain how this works but that would imply that I actually know what I'm doing
I was working on an animation on processing. Then, I have a question about the loop. Normally, my code is more long. However, I made a simple code which can usefull also for the beginners.
My sample code:
void setup(){
println("Line between points " + curr + " and " + (curr+1));
println("initial X: " + initialX + " initial Y: " + initialY );
println("final X: " + finalX + " final Y: " + finalY );
counter = 0; // reset counter;
}
void draw() {
point(initialX, initialY);
println(initialX, initialY, p);
}
So, like you see I used "Bresenhams Algorithm" for drawing the lines. However when I draw the lines it doesn't draw the lines between points. It's just drawing a little bit. Normally my text file is so long. How to I draw lines that can follow from first x and y coordinates to last x and y coordinates without disconnection?
This is implementation of a version of Bresenham's algorithm using balancing the positive and negative error between the x and y coordinates:
/*
String[] coordinates = { // Creating an array for my text file.
"117 191",
"96 223",
"85 251",
"77 291",
"78 323",
"84 351",
"97 378",
"116 404",
"141 430"
};
*/
int[][] points;
int deltaX, deltaY;
int initialX, initialY; // Initial point of first coodinate
int finalX, finalY; // Final point of first coodinate
int counter = 0;
int curr = 0;
int sx, sy, err;
void setup() {
size(500, 500);
strokeWeight(4);
frameRate(25);
coordinates = loadStrings("coordinates.txt");
beginShape(); // It combines the all of vertexes
points = new int[coordinates.length][2];
int row = 0;
for (String line : coordinates) {
String[] pair = line.split(" ");
points[row] = new int[] { Integer.parseInt(pair[0]), Integer.parseInt(pair[1])};
println(points[row][0]); // print x
println(points[row][1]); // print y
row++;
}
fixLines();
endShape(CLOSE);
}
void fixLines() {
int ix = curr % points.length;
int jx = (curr + 1) % points.length;
initialX = points[ix][0];
initialY = points[ix][1];
finalX = points[jx][0];
finalY = points[jx][1];
deltaX = abs(finalX - initialX);
sx = initialX < finalX ? 1: -1;
deltaY = -abs(finalY - initialY);
sy = initialY < finalY ? 1: -1;
err = deltaX + deltaY;
println("Line between points " + curr + " and " + (curr+1));
println("[" + initialX + ", " + initialY + "] - [" + finalX + ", " + finalY + "]");
println("deltaX=" + deltaX);
}
void draw() {
point(initialX, initialY);
if (initialX == finalX && initialY == finalY) {
curr++;
if (curr == points.length) {
noLoop();
} else {
fixLines();
}
} else {
int e2 = 2 * err;
if (e2 >= deltaY) {
err += deltaY;
initialX += sx;
}
if (e2 <= deltaX) {
err += deltaX;
initialY += sy;
}
}
}
The output is very close to linear implementation:
I try updating method draw to update deltaY and continue drawing until deltaY != 0 but result does not look good. Most likely you need to review your implementation of the algorithm and related calculations.
void draw()
{
point(initialX, initialY);
println(initialX, initialY, p);
if (finalX > initialX )
initialX++;
else
initialX--;
if (p < 0) {
p = p + 2 * deltaY;
} else {
if (initialY > finalY)
initialY--;
else
initialY++;
p = p + 2 * deltaY - 2 * deltaX;
}
deltaY = abs(finalY - initialY); // update deltaY
counter++;
if (counter > deltaX) {
if (deltaY > 0) {
counter--;
} else {
curr++;
if (curr == points.length) {
noLoop(); // possibly you should break out of the main loop here
} else {
fixLines();
}
}
}
}
Implementation with line(initialX, initialY, finalX, finalY); looks much better.
void draw()
{
point(initialX, initialY);
println(initialX, initialY, p);
line(initialX, initialY, finalX, finalY);
curr++;
if (curr == points.length) {
noLoop();
} else {
fixLines();
}
}
In an STL format this is what my current landscape looks like. And this is what the landscape is suppossed to look like. I think I know what the problem is, but I have no clue how to solve it.
I think I need to set the Z coordinate relative to other points around it so the whole landscape's Z coordinate isn't between 0 and 1 but they rather "add up".
Don't want a solution, just a hint in the right direction.
import java.io.*;
import java.util.Random;
class Point3D {
double x, y, z;
Point3D(double dx, double dy, double dz) {
x = dx;
y = dy;
z = dz;
}
Point3D middlePoint(Point3D p) {
Point3D m = new Point3D(0.0, 0.0, 0.0);
m.x = (this.x + p.x) / 2.0;
m.y = (this.y + p.y) / 2.0;
m.z = (this.z + p.z) / 2.0;
return m;
}
}
public class Aufgabe3 {
public static void recursion(Point3D p1, Point3D p2, Point3D p3, int n) {
if (n > 0) {
if (n == 1) {
System.out.println(" facet normal 0.0 0.0 0.0");
System.out.println(" outer loop");
System.out.println(" vertex " + p1.x + " " + p1.y + " " + p1.z);
System.out.println(" vertex " + p2.x + " " + p2.y + " " + p2.z);
System.out.println(" vertex " + p3.x + " " + p3.y + " " + p3.z);
System.out.println(" endloop");
System.out.println(" endfacet");
}
Random r = new Random();
Point3D a = p1.middlePoint(p2);
Point3D b = p3.middlePoint(p1);
Point3D c = p2.middlePoint(p3);
long seedA = (long) ((p1.x + p1.y + p1.z + p2.x + p2.y + p2.z) * 1000000);
r.setSeed(seedA);
a.z = r.nextDouble() / 10;
long seedB = (long) ((p3.x + p3.y + p3.z + p1.x + p1.y + p1.z) * 1000000);
r.setSeed(seedB);
b.z = r.nextDouble() / 10;
long seedC = (long) ((p2.x + p2.y + p2.z + p3.x + p3.y + p3.z) * 1000000);
r.setSeed(seedC);
c.z = r.nextDouble() / 10;
recursion(p1, a, b, n-1);
recursion(a, p2, c, n-1);
recursion(b, c, p3, n-1);
recursion(a, b, c, n-1);
}
}
public static void main(String args[]) throws FileNotFoundException {
int n;
try {
n = Integer.parseInt(args[0]);
}
catch (Exception e) {
n = 7;
}
System.out.println("Aufgabe 3: Landschaftsgenerator");
System.out.println("n = " + n);
Random r = new Random();
Point3D p1 = new Point3D(0.8, -1.2, 0.0);
Point3D p2 = new Point3D(1.0, 1.3, 0.0);
Point3D p3 = new Point3D(-1.0, 0.0, 0.0);
System.setOut(new PrintStream(new FileOutputStream("Aufgabe3.stl")));
System.out.println("solid Aufgabe3");
recursion(p1, p2, p3, n);
System.out.println("endsolid");
}
}
The problem is the frequency distribution of the displacements you're adding. Displacements to a fractal landscape have to follow a 1/(f^b) distribution, otherwise you get random noise.
In this case, no matter what the scale of subdivision, you're adding the same vertical displacement, which is going to result in a landscape dominated by the highest frequency. Formally, a fractal surface is one that has a 'fractional' or 'fractal' geometric dimension, higher than the topological dimension of the surface, but lower than that of the embedding space. For instance, for a 2D surface being displaced in the 3rd dimension, the fractal dimension should be between 2 and 3.
For subdivision and displacement, the fractal dimension is related to beta as follows:
Dim = (7 - b)/2
With fractal behaviour therefore occurring between b = 1 and b = 3, and the random displacements follow this profile:
displacement = k * rand / (f^b)
This means that if you divide your triangle in half each time, you have to at least halve the displacement, or you'll end up with a noise surface rather than a fractal one. The best choice for a landscape is typically somewhere around b = 2.
Reference: https://fractal-landscapes.co.uk/maths.html
I'm trying to find the smallest bounding rectangle of a number of circles given the x and y co-ordinates of their centre and the magnitude of the radii.
The test input is:
(1, 1, 2), (2, 2, 0.5), (-1, -3, 2), (5, 2, 1)
Here's my code:
package com.CocoMac.main;
import java.util.ArrayList;
import java.util.Scanner;
public class Challenge330Easy {
static double maxx;
static double maxy;
static double minx;
static double miny;
static ArrayList <double[]> circles = new ArrayList<double[]>();
static String in = "1,1,2\n2,2,0.5\n-1,-3,2\n5,2,1";
static String s;
static Scanner inScan = new Scanner(in);
public static void main(String[] args) {
for(int i = 0; inScan.hasNextLine(); i++) {
s = inScan.nextLine();
circles.add(i, toDouble(s.split(",")));
}
for(int i = 0; i < circles.size(); i++) {
if(maxx < circles.get(i)[0] + circles.get(i)[2]);
maxx = circles.get(i)[0] + circles.get(i)[2];
if(minx > circles.get(i)[0] - circles.get(i)[2]);
minx = circles.get(i)[0] - circles.get(i)[2];
if(maxy < circles.get(i)[1] + circles.get(i)[2]);
maxy = circles.get(i)[1] + circles.get(i)[2];
if(miny > circles.get(i)[1] - circles.get(i)[2]);
miny = circles.get(i)[1] - circles.get(i)[2];
}
System.out.print("(" + minx + ", " + miny + ")" + ",");
System.out.print("(" + minx + ", " + maxy + ")" + ",");
System.out.print("(" + maxx + ", " + maxy + ")" + ",");
System.out.print("(" + maxx + ", " + miny + ")");
}
public static double[] toDouble(String[] input) {
double[] output = new double[input.length];
for(int i = 0; i < input.length; i++) {
output[i] = Double.parseDouble(input[i]);
}
return output;
}
}
The expected output is:
(-3.000, -5.000), (-3.000, 3.000), (6.000, 3.000), (6.000, -5.000)
But instead, the output is:
(4.0, 1.0),(4.0, 3.0),(6.0, 3.0),(6.0, 1.0)
I've tried everything I can think of. For whatever reason, the final input is the maximum values found from the last circle iterated through (5,2,1) instead of the largest possible from all circles, which makes me think the conditional statements used when I'm setting the maximum and minimum values of x and y may be always evaluating to true, but I have no idea how.
If you could, clue me in on what I'm missing here or point me in the direction of what I need to learn. Any help is appreciated!
One obvious problem:
if(maxx < circles.get(i)[0] + circles.get(i)[2]);
maxx = circles.get(i)[0] + circles.get(i)[2];
You put a semicolon after the if condition. That terminates the statement. This translates to ...
if(maxx < circles.get(i)[0] + circles.get(i)[2])
; // Do nothing
maxx = circles.get(i)[0] + circles.get(i)[2];
I have completed some of the code for a color wheel, but I'm confused on how to complete it? I've also commented the code to help understand. So far, it prints red, orange and yellow gradients. How do I complete this?
import java.awt.*;
public class ColorDrawing2 {
public static final int CENTER = 256;
public static final int RADIUS = 120;
public static final int SHAPES = 32;
public static final int SIZE = 40;
public static void main(String[] args) {
DrawingPanel panel = new DrawingPanel(512,512); // create a drawing panel
panel.setBackground(new Color(0,0,0)); // set background color (orange)
Graphics g = panel.getGraphics(); // get graphics toolkit
for (int i = 0; i <= SHAPES; i++) {
// System.out.println("i = " + i);
double angle = (i)*(360/SHAPES)*(Math.PI/180); // angle
// System.out.println("Angle = " + angle);
double x = CENTER - (SIZE/2) + RADIUS*Math.cos(angle); // x-cooordinate
double y = CENTER - (SIZE/2) + RADIUS*Math.sin(angle); // y-coordinate
int red = (int) (199 + 56/SHAPES*i); // 199 < red < 255
// System.out.println("Red = " + red);
int grn = (int) (7.97*i); // 0 < grn < 255
// System.out.println("Green = " + grn);
int blu = 0;
g.setColor(new Color((int) red, grn, blu));
g.fillOval((int)x, (int)y, SIZE, SIZE);
panel.sleep(200); // pause 200 msec
}
}
}
Yes, seems like 6 for loops should be enough. Maybe the colors should go up to 255?
for the 6 for loops:
for (int i = 0; i <= SHAPES; i++) {
// System.out.println("i = " + i);
double angle = ((i)*(60/SHAPES) +65)*(Math.PI/180); // angle
// System.out.println("Angle = " + angle);
double x = CENTER - (SIZE/2) + RADIUS*Math.cos(angle); // x-cooordinate
double y = CENTER - (SIZE/2) + RADIUS*Math.sin(angle); // y-coordinate
int red = (int) (255); // 199 < red < 255
// System.out.println("Red = " + red);
int grn = (int) (7.97*i); // 0 < grn < 255
// System.out.println("Green = " + grn);
int blu = 0;
g.setColor(new Color((int) red, grn, blu));
g.fillOval((int)x, (int)y, SIZE, SIZE);
panel.sleep(0); // pause 200 msec
}
for (int i = 0; i <= SHAPES; i++) {
// System.out.println("i = " + i);
double angle = ((i)*(60/SHAPES) + 130)*(Math.PI/180); // angle
// System.out.println("Angle = " + angle);
double x = CENTER - (SIZE/2) + RADIUS*Math.cos(angle); // x-cooordinate
double y = CENTER - (SIZE/2) + RADIUS*Math.sin(angle); // y-coordinate
int red = (int) (255 - (255/SHAPES*i)); // 199 < red < 255
// System.out.println("Red = " + red);
int grn = (int) (255); // 0 < grn < 255
// System.out.println("Green = " + grn);
int blu = 0;
g.setColor(new Color((int) red, grn, blu));
g.fillOval((int)x, (int)y, SIZE, SIZE);
panel.sleep(0); // pause 200 msec
}
for (int i = 0; i <= SHAPES; i++) {
// System.out.println("i = " + i);
double angle = ((i)*(60/SHAPES) + 185)*(Math.PI/180); // angle
// System.out.println("Angle = " + angle);
double x = CENTER - (SIZE/2) + RADIUS*Math.cos(angle); // x-cooordinate
double y = CENTER - (SIZE/2) + RADIUS*Math.sin(angle); // y-coordinate
int red = (int) (0); // 199 < red < 255
// System.out.println("Red = " + red);
int grn = (int) (255); // 0 < grn < 255
// System.out.println("Green = " + grn);
int blu = (int) (7.97*i);
g.setColor(new Color((int) red, grn, blu));
g.fillOval((int)x, (int)y, SIZE, SIZE);
panel.sleep(0); // pause 200 msec
}
for (int i = 0; i <= SHAPES; i++) {
// System.out.println("i = " + i);
double angle = ((i)*(60/SHAPES) + 250)*(Math.PI/180); // angle
// System.out.println("Angle = " + angle);
double x = CENTER - (SIZE/2) + RADIUS*Math.cos(angle); // x-cooordinate
double y = CENTER - (SIZE/2) + RADIUS*Math.sin(angle); // y-coordinate
int red = (int) (0); // 199 < red < 255
// System.out.println("Red = " + red);
int grn = (int) (255 - (255/SHAPES*i)); // 0 < grn < 255
// System.out.println("Green = " + grn);
int blu = (int) (255);
g.setColor(new Color((int) red, grn, blu));
g.fillOval((int)x, (int)y, SIZE, SIZE);
panel.sleep(0); // pause 200 msec
}
for (int i = 0; i <= SHAPES; i++) {
// System.out.println("i = " + i);
double angle = ((i)*(60/SHAPES) + 315)*(Math.PI/180); // angle
// System.out.println("Angle = " + angle);
double x = CENTER - (SIZE/2) + RADIUS*Math.cos(angle); // x-cooordinate
double y = CENTER - (SIZE/2) + RADIUS*Math.sin(angle); // y-coordinate
int red = (int) (7.97*i); // 199 < red < 255
// System.out.println("Red = " + red);
int grn = (int) (0); // 0 < grn < 255
// System.out.println("Green = " + grn);
int blu = (int) (255);
g.setColor(new Color((int) red, grn, blu));
g.fillOval((int)x, (int)y, SIZE, SIZE);
panel.sleep(0); // pause 200 msec
}
for (int i = 0; i <= SHAPES; i++) {
// System.out.println("i = " + i);
double angle = ((i)*(60/SHAPES) +370)*(Math.PI/180); // angle
// System.out.println("Angle = " + angle);
double x = CENTER - (SIZE/2) + RADIUS*Math.cos(angle); // x-cooordinate
double y = CENTER - (SIZE/2) + RADIUS*Math.sin(angle); // y-coordinate
int red = (int) (7.97*i); // 199 < red < 255
// System.out.println("Red = " + red);
int grn = (int) (0); // 0 < grn < 255
// System.out.println("Green = " + grn);
int blu = (int) (0);
g.setColor(new Color((int) red, grn, blu));
g.fillOval((int)x, (int)y, SIZE, SIZE);
panel.sleep(0); // pause 200 msec
}