So at school we are learning to program now using processing, and one of the homework assignments is to draw several ellipses using a preformatted piece of code:
int[][] circles = { {10, 15}, {100, 130}, {77, 43}, {30, 145}, {185, 17}, {99, 76} };
final int DIAMETER = 20;
final int YELLOW = #FFFF00;
final int RED = #FF0000;
void setup() {
size(200, 200);
ellipseMode(CORNER);
}
void draw() {
background(#000000);
drawCircles(circles);
}
We are not allowed to change anything in it but we need to draw all the ellipses by writing a drawCircles() function. Now I have tried to get mine to work for days and asked my fellow students for help as well but the solution eludes meā¦ hereās what I have so far:
void drawCircles(int[][] array) {
for (int i =0; i <= array.length; i++) {
for (int j =0; j <= array.length; j++) {
fill(YELLOW);
float[] x = float(array[i]);
float[] y = float(array[j]);
ellipse( x, y, (float)DIAMETER, (float)DIAMETER);
}
}
}
Whatever I try it keeps giving me errors; mostly about not entering floats into the ellipse() function therefore I have been trying to convert them using many different methodsā¦ Could someone perhaps point me in the right direction?
Just taking a fast look, it seems that you are passing an array, not a float
x is a float array, same with y
If you want to give the coordinates x y from the array, you donāt need the second for:
void drawCircles(int[][] array) {
for (int i =0; i < array.length; i++) {
fill(YELLOW);
float x = float(array[i][0]);
float y = float(array[i][1]);
ellipse( x, y, (float)DIAMETER, (float)DIAMETER);
}
}
With float(array[i]) you are acceding to { {x, y},.......}, not the x value or the y, so the ellipse method is receiving something like this ellipse( {10,15}, {100,130} ,(float)DIAMETER,(float)DIAMETER); , instead of ellipse(10, 15 ,(float)DIAMETER,(float)DIAMETER);
Wowā¦thanks GoTo! This concept is still a bit hard to grasp for me but I think Iām beginning to understand what you are talking about here. Iāll have to study it some more before Iāll know for sure though, but a definite āthank youā for taking the time to address this!