class Vehicle{
PVector location;
PVector velocity;
PVector acceleration;
float r;
float maxforce;
float maxspeed;
Vehicle(float x,float y){
acceleration = new PVector(0,0);
velocity = new PVector(0,0);
location = new PVector(x,y);
r = 3.0;
maxspeed = 4;
maxforce = 0.1;
}
void update(){
velocity.add(acceleration);
velocity.limit(maxspeed);
location.add(velocity);
acceleration.mult(0);
}
void applyForce(PVector force){
acceleration.add(force);
}
void seek(PVector target){
PVector desired = PVector.sub(target,location);
desired.normalize();
desired.mult(maxspeed);
PVector steer = PVector.sub(desired,velocity);
steer.limit(maxforce);
applyForce(steer);
}
void display(){
float theta = velocity.heading2D()+ PI/2;
fill(175);
stroke(0);
pushMatrix();
translate(location.x,location.y);
rotate(theta);
beginShape();
vertex(0,-r*2);
vertex(-r,r*2);
vertex(r,r*2);
endShape(CLOSE);
popMatrix();
}
}
Hell @jiajia,
When you compile a blank sketch this is what you get and it will run once:
/* autogenerated by Processing revision 1292 on 2023-04-25 */
import processing.core.*;
import processing.data.*;
import processing.event.*;
import processing.opengl.*;
import java.util.HashMap;
import java.util.ArrayList;
import java.io.File;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
public class sketch_230425a extends PApplet {
public void setup() {
noLoop();
}
static public void main(String[] passedArgs) {
String[] appletArgs = new String[] { "sketch_230425a" };
if (passedArgs != null) {
PApplet.main(concat(appletArgs, passedArgs));
} else {
PApplet.main(appletArgs);
}
}
}
You can find the above in the %temp%/processing
folder on W10.
When you compile a sketch with only a class it will put your class inside of the setup() and compile that.
This may provide some insight:
You should be using a class in Processing with setup() and draw() in most cases:
:)