Re: Meggy Jr. Programming Syntax Question

Home Evil Mad Scientist Forums LED Matrix Kits Meggy Jr. Programming Syntax Question Re: Meggy Jr. Programming Syntax Question

#21004
dkiang
Participant

Thanks. I was writing the code from my faulty memory. You are right. When I checked the code that I wrote that worked, it looked like this:

struct Point
{
  int x;
  int y;
};

Point s1 = {3,4};
Point s2 = {4,4};
Point s3 = {5,4};
Point s4 = {6,4};
Point myArray[64] = {s1,s2,s3,s4};  //Shape coordinates

void drawShape()
{
  for (int i = 0; i < 4; i++)
  {
    DrawPx(myArray.x,myArray.y,Red);
  }
}

..so, that does work. I next want to declare a few shapes that each consist of about sixteen separate Point objects. I am reluctant to declare them as individual variables (Point s1 = {3,4}, Point s2 = (4,4}, etc.) just for the purposes of adding them to the array.

Is there a way to add Point objects to the array directly without taking the intermediary step of creating them as separate Point objects, each with their own variable name?

In Java, I would have to create a class with a constructor that takes parameters:

public class Point{
int myX;
int myY;
public Point (int x, int y){
 myX = x;
 myY = y;
}
}

but then I could initialize an array and add Points like this:

Point[] myArray = {new Point(3,4), new Point(4,4), new Point(5,4), new Point(6,4)};

Does Processing support anything similar?

Thanks,

–Doug.