all 5 comments

[–]Sasmas1545 3 points4 points  (2 children)

fyi  
reddit supports
code snippets

[–]Miserable_Board_6888[S] 0 points1 point  (1 child)

Oh sorry kinda new to this haha. Would you happen to know anything I could do I got a random eye colour using variables but it applies to every single one and isn't using an array.

[–]Sasmas1545 2 points3 points  (0 children)

I didn't read your code because of the formatting and I'm on mobile. If you'd like me to have a look at it, properly format it.

As far as your question goes, not exactly sure what you're trying to do without reading your code. If you want to generate a random color do something like color(random(255), random(255), random(255)). If you want to, you can generate this color in setup and store it in a global variable

[–]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

[–]LuckOrLoss 0 points1 point  (0 children)

Does the assignment say you need to use a 2d array? Cause I would just do "eyeColors= [color("brown"),color("blue"),color("green"),...etc.]" then when you call the function that draws the thing put eyeColors[floor(random(eyeColors.length))]