Why? My class exists!

The compiler says…
the class “Circle” does not exist
…but it does.

Code:

Circle circle = new Circle(10,color(0),color(255,0,0),0,new PVector(400,400),new PVector(0,0),new PVector(0,0));

class Circle{
  float diameter;
  color colorStroke;
  color colorFill;
  float thickness;
  PVector position;
  PVector velocity;
  PVector acceleration;
  
  Circle(float d,color cs,color cf,float t,PVector p,PVector v,PVector a){
    diameter = d;
    colorStroke = cs;
    colorFill = cf;
    thickness = t;
    position = p;
    velocity = v;
    acceleration = a;
  }
  
  void update(){
    velocity.add(acceleration);
    position.add(velocity);
    if(thickness == 0){
      noStroke();
    }else{
      strokeWeight(thickness);
    }
    stroke(colorStroke);
    fill(colorFill);
    ellipse(position.x - (diameter / 2),position.y - (diameter / 2),position.x + (diameter / 2),position.y + (diameter / 2));
  }
}
1 Like

Is this your entire code?

But you have setup() and draw()?

2 Likes

it is necessary

Chrisir

1 Like

Whoops…
Adding setup and draw works…
Thanks!

:grin:

1 Like

Arr… I told you I am a noob… :upside_down_face:

Circle circle1 = new Circle(50,color(0),color(255,0,0),0,new PVector(400,400),new PVector(0,0),new PVector(0,0));

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

void draw(){
background(0);
circle1.update();
circle1.position.x = mouseX;
circle1.position.y = mouseY;
}

class Circle{
float diameter,thickness;
color colorStroke,colorFill;
PVector position,velocity,acceleration;

class Circle{
float radius,thickness;
color colorStroke,colorFill;
PVector position,velocity,acceleration;

Circle(float r,color cs,color cf,float t,PVector p,PVector v,PVector a){
radius = r;
colorStroke = cs;
colorFill = cf;
thickness = t;
position = p;
velocity = v;
acceleration = a;
}

void update(){
velocity.add(acceleration);
position.add(velocity);
if(thickness == 0){
noStroke();
}else{
strokeWeight(thickness);
}
stroke(colorStroke);
fill(colorFill);
ellipse(position.x,position.y,radius,radius);
}
}

Just for a test…

instead of doing this position.x - (diameter / 2),position.y - (diameter / 2),

use ellipseMode(CENTER); // Set ellipseMode to CENTER previous to ellipse() command

see ellipseMode() / Reference / Processing.org

AND the last two parameters are wrong: just use diameter here

Remarks

  • don’t use a Sketch name (on your hard drive) when it’s already a class name
  • everything is case sensitive
  • circle is a command, so maybe not a good idea to have an object with the same name (it works but…): Use circle1 or myCircle instead

Chrisir

1 Like

Yeah, I changed it. :grinning:

1 Like

Thanks Chrisir :smile:

1 Like