Not using Classes or Translate

Hey all!

I’ve got code here but we’ve not been allowed to use classes or transformations such as rotate, translate, scale etc. I really need help making this code work with these rules. Not sure where to even start, any help would be heavily appreciated.

code here:

class Star {
  float x;
  float y;
  float z;
  
  Star() {
    x = random(-width, width);
    y = random(-height, height);
    z = random(width);
  } 
  
void update() {
  z = z - 1;
  if (z < 1) {
    z = width;
    x = random(-width, width);
    y = random(-height, height);
  }
} 

void show() {
  fill(255);
  noStroke();
  
  float sx = map(x / z, 0, 1, 0, width);
  float sy = map(y / z, 0, 1, 0, height);
  
  float r = map(z, 0, width, 16, 0);
  circle (sx, sy, r);
}
}

Star[] stars = new Star[1000];

void setup() {
  size(500, 500); //set screen size
  background(0);
  for (int i = 0; i < stars.length; i++) {
    stars[i] = new Star();
  }
}

void draw() {
    background(0);
   
      translate(width, height/2);
      for (int i = 0; i < stars.length; i++) {
      stars[i].update();
      stars[i].show();   
 }
}```

Hi @UnsureNeedHelp,

Welcome to the forum! :wink:

If this post is for a homework, please tag it so.

When you post on a forum, it’s always necessary to explain what is your goal and what you are trying to do. In this case you have constraints but ultimately what is the desired output?

1 Like

Hello,

There are lots of resources here:

:)

1 Like