Passing color as argument when using StdDraw in java

2.2k Views Asked by At

Having some trouble passing color argument if at all possible when using StdDraw in Java.

What I would like to do is passing a color variable f.e. "RED", "GREEN", "BLUE" to set the pen color of the drawing function to get different color each time I run through for loop.

Here is the code for more details of what I am trying to accomplish.

static void DrawCircleSizeColor()
    {
    String[] myColorArray = {"RED","GREEN","BLUE"};
    double x = 20;
    double y = 20;
    double r = 20;
    int c = 0;

    for (int i = 0; i <= 3.0; i++)
    {

        StdDraw.setPenColor(Color.getColor(myColorArray[c]));
        StdDraw.circle(x, y, r);
        c++;
        r--;
    }

Hope you understand my where I am going with this

Thanks -EE

1

There are 1 best solutions below

0
On
import java.awt.Color;

declare your array as:

Color[] myColorArray = {Color.RED,Color.GREEN,Color.BLUE};

and use them

StdDraw.setPenColor(myColorArray[c));

Class java.awt.Color has static variables with some standard colors predefined