mercredi 23 octobre 2019

How to write a conditional statement that chooses between three colors to produce a specific image

I'm doing a lab for a Computer Science course I am taking in university. The problem states, "Have each return an int representation of a Color. Also have each accept four int parameters: a column index, a row index, an image width, and an image height. Eventually you will use these parameters to arbitrate between colors."

Specifically for the method I cannot figure out, the question is, "In method boxColor, write a conditional statement that chooses between three colors to produce this image".

This is the image: Image


Just so it's clear what my professor is expecting here is a quick example of another problem that was assigned.

The question states, "In method stripesColor, write a conditional statement that chooses between three colors to produce this image:"

The image: Image

And here is the code I wrote to complete the task:

  public static int stripesColor(int column, int row, int imWidth, int imHeight) {
      if (column < (imHeight / 3)) {
         return Color.red.getRGB();
      } else if ((column < 2 * (imHeight / 3))) {
         return Color.pink.getRGB();
      } else {
         return Color.orange.getRGB();
    }
  }

I should also mention just so it's clear, the professor provided us with a class that will use the methods we write to produce the images, we're only responsible to do the calculations in order to achieve the pictures he provides.

I have tried finding the diagonal of the entire square (512px x 512px) and making the smaller square on the inside 1/5 of the total size but I'm not sure if what I'm doing is just wrong or if there is another way to go about doing this.

Any help is appreciated, thank you.

Aucun commentaire:

Enregistrer un commentaire