The function transform(PVector) does not exist

class StarField {  
  final int STAR_COUNT = width / 2;  
  final int MAX_SPEED = 11, MIN_SPEED = 1;  
  final int SPEED_STEP = 1;  
  ArrayList<Star> stars;  
  PVector endpoint;  
  int speed;  
  StarField() {  
    endpoint = new PVector(mouseX, mouseY);  
    stars = new ArrayList();  
    for (int i = 0; i < STAR_COUNT; i++) {  
      stars.add(new Star());
    }  
    speed = (MAX_SPEED + MIN_SPEED) / 2;
  }
  void run() {  
    for (Star s : stars) {  
      s.move(speed);  
      **s.transform(endpoint);
      **  
        s.checkEdge();  
      s.display();
    }
  }
  void updateEndpoint(float x, float y) {  
    endpoint.x = x;  
    endpoint.y = y;
  }  
  void speedUP() {  
    speed += SPEED_STEP;  
    speed = constrain(speed, MIN_SPEED, MAX_SPEED);
  }  
  void speedDown() {  
    speed -= SPEED_STEP;  
    speed = constrain(speed, MIN_SPEED, MAX_SPEED);
  }
}
1 Like

You should share your Star class as well – and a minimal sketch, if you have it.

It looks like you are calling myStar(myPVector), but your star class does not have a method

void transform (PVector pv){}

Thankyou for your fast reply!

Here’s my Star class:

class Star{  
final float MAX_DIAM = 16;  
final float MAX_DEPTH = width / 2;  
final float SCALE = MAX_DEPTH;  
PVector worldPosition, screenPosition, viewPosition;  
float diam;  
Star(){  
worldPosition = new PVector(random(0, width), random(0, height), random(0, MAX_DEPTH));  
}  
void move(float speed){  
worldPosition.z -= speed;  
worldPosition.z = constrain(worldPosition.z, 0, MAX_DEPTH);  
}  
void transfrom(PVector endpoint){  
viewPosition.x = (worldPosition.x - endpoint.x) / worldPosition.z * SCALE; 
viewPosition.y = (worldPosition.y - endpoint.y) / worldPosition.z * SCALE; 
viewPosition = PVector.sub(worldPosition, endpoint).div(worldPosition.z).mult(SCALE);  
screenPosition.x = endpoint.x + viewPosition.x; 
screenPosition.y = endpoint.y + viewPosition.y; 
screenPosition = PVector.add(endpoint, viewPosition);  
diam = map(worldPosition.z, 0, MAX_DEPTH, MAX_DIAM, 0);  
}  
void checkEdge(){  
if(screenPosition.x <= 0 || screenPosition.x >= width || screenPosition.y <=0 || screenPosition.y >= height){  
worldPosition.set(random(0, width), random(0, height), MAX_DEPTH);   
 }   
 }  
  
void display(){  
fill(255);  
noStroke();  
ellipse(screenPosition.x, screenPosition.y, diam, diam);  
}    
}
1 Like

transfrom --> transform

1 Like

I am so silly, thank you so much, I can’t believe I didn’t notice the typo. I pressed run and it now says Debugger busy…

When not using the PDE, size() can only be used inside settings().
Remove the size() method from setup(), and add the following:
public void settings() {
size(400, 400);
}

1 Like

Are you in Eclipse or Netbeans?

I’ve just been using this.


This is the latest update.

NullPointerException

Ah. You renamed your sketch tab to “Main” – you can’t do that. This is Java – not C++.

Processing sketches are compiled as inner classes of their PApplet.

When you create a sketch and save it, it will always have the form:

/sketches/MySketch/MySketch.pde
/sketches/Another/Another.pde
/sketches/Foo/Foo.pde
/sketches/Bar/Bar.pde

The “main” entrypoint pde file must match the name of its enclosing folder – which it will always do if you create a new sketch and save it, or if you Save As etc. from inside PDE. You will notice this is also true of every example in the Examples folders.

1 Like

Hi, again this is the new update. I don’t understand where I should make the change. What’s wrong with the size?

StarField sf;
void setup(){
size(400, 400);
sf = new StarField();
}

void draw(){
background(0);
sf.run();
}

void mousePressed(){
if(mouseButton == LEFT){
sf.speedUP();
}else if(mouseButton == RIGHT){
sf.speedDown();
}
}
void mouseMoved(){
sf.updateEndpoint(mouseX, mouseY);
}

There are so many errors one after another, this is whole a mess now :dizzy_face:

I now have no idea where to fix or change, thank you for your patience.

Are you modifying a sketch that you found somewhere? Is this your first time using Processing? Are you new to programmming? I’m just trying to get a sense of where you are coming from, and where this code came from.

  1. create a brand new sketch.
  2. save it with a meaningful name, like StarFieldTest. The name may not be the name of a class in your sketch.
  3. add this code to the main tab, “StarFieldTest”
void setup(){
  size(400, 400);
}

void draw(){
  background(0);
}
  1. Save, then run it. Does it work?
1 Like

Hi, yes I am new to programming, completely new and this code came from a tutorial.

Hello, I have inserted the set of code in the new file created.

This showed after after run.

When the error says duplicate method setup() it means there’s two methods called ‘setup’. Keep in mind that, throughout your entire sketch (this includes all the tabs), you can’t have functions or methods with the same name (there are exceptions, but for now my advice is to assume it’s not possible).

For instance, the following code won’t run because there are two duplicate function names:

void setup() {
  size(500, 500);
}

void draw() {
  background(240);
  stroke(0);
  fill(255, 0, 0);
  drawRectangle();
}

void drawRectangle() {
  rect(100, 100, 300, 200);
}

void drawRectangle() { // try renaming this function and it will work
  rect(100, 100, 200, 300);  
}
1 Like

It is up to you, but just so you know, this code is not recommended for a beginner learning programming – you don’t usually want to start with multi-tab sketches or classes. Instead, learn the basics first:

https://processing.org/tutorials/

If not, remove Star.pde, Main.pde, and StarField.pde, and add their parts back in slowly a bit at a time. Start with a working sketch that does nothing. That way it will always be clear what you just changed that broke things.

2 Likes

Hello,

Thank you so much for being this patient with me, I realised that I will need to take it slowly since there’s always an error after another. I am going to watch the tutorials and learn more about it, hopefully I can get it to run.

J

2 Likes