I want to change the color of the sides every time I rotate.

Asked 1 years ago, Updated 1 years ago, 239 views

The following program is a hexagon writing program, but by adding it to it
I'd like to create a program that changes the color of each side and writes hexagonal shapes with six colors.
I didn't know what to do.

First of all, how do you show the program?

public class SolidOrDot{

    public static void main(String args[]){
    US>Turtle;

    if(args.length>0&args[0].equals("dot")}
        DotTurtle = new DotTurtle();
        dt.setLength(5);
        t = dt;
    }
    else{
        t = new Turtle(); 
    }
    
    t.move(100,200);
    t.penDown();
    t.go(100);
    t.rotate(60);
        t.go(100);
    t.rotate(60);
        t.go(100);
    t.rotate(60);
    t.go(100);
    t.rotate(60);
    t.go(100);
    t.rotate(60);
        t.go(100);
    }
}

By the way, the coloring method is

public void setColor(java.awt.Colorc){
      This.t.setColor(c);
    }

given in the .

java

2022-09-30 21:56

1 Answers

I don't know what the problem is (for example, "I don't know where and how to write the method", "setColor, but when I run it, I get a black hexagon" or "compile error") so I'll include my guess in my answer.

t.go(100); // 100 forward dots = Draw a line segment
t.rotate(60); // 60 degree rotation

If you don't know where and how to write the method, you can write the setColor method before or after the above method with arguments (java.awt.Color) and pass it to six different colors.
For method definitions and syntax, see the Answer your own questions
setColorThe specific usage of the method may be Questions that change the color of the sides of the rectangle every time you rotate

If t.setColor(java.awt.Color.RED); does not change the color after adding code, or if fails to compile with an error similar to the one below, update the questionnaire.

 C:\test\java\SolidOrDot.java:6: Error: Cannot find symbol
        This.t.setColor(c);
            ^
  symbols:variable t
US>Error
ERROR: Compilation failed

As an old woman, Java's code has meaning in each line and does something, so checking what happens while erasing or increasing the code will help you understand the textbook.
I'm not afraid of changing the code if I have a proper backup.Good luck.


2022-09-30 21:56

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.