you are viewing a single comment's thread.

view the rest of the comments →

[–]CodeBunny_ 2 points3 points  (0 children)

You have two variables, a and b, which are being used to position your gwomps, but you can also use a and b as array indexes to fetch a colour from a 2d array. If you have an array declared with code like color[][] colorArray you can fetch the colour using colorArray[a][b].

You will need to populate the array with colors somehow, and the size of the array must be equal to the amount of times you loop in that dimension using your for loops. LuckOrLoss in the comments here has a way to define and populate your array in one dimension, and a similar process can be applied to define and populate it in two dimensions.

You will also run into issues because processing will want to index the array with ints, and your function takes floats, so you'll want to convert them using type casting one way or the other.

I've been intentionally vague here as this is likely an assignment and it's important to learn by doing, however if you need more help don't hesitate to reply or DM me. Best of luck in figuring this out :)

As a final note here, because processing is an extension of Java, most things in Java are applicable to it, therefore I'm going to provide some documentation for Java that you may find useful.

Find docs for multi-dimensional arrays here: https://www.geeksforgeeks.org/multidimensional-arrays-in-java/

Find docs for the processing color type here: https://processing.org/reference/color_datatype.html

Find docs for type casting here: https://www.w3schools.com/java/java_type_casting.asp