xxxxxxxxxx
92
// use radar to get the speed of the car moving to the side
// for the radar, let's use the doppler formula:
// v = (\delta f * c)/()
// now make some sort of RR problems about a camera that is positioned x down the road and how fast to turn the camera
class Radar {
constructor(x,y,a){
this.pos = createVector(x.y);
this.angle = a;
this.angleDt = 0;
}
accelerate(acc){
this.angleDt = 0;
}
update(){
this.angle += this.angleDt;
}
render(){
stroke(0)
let size = 10;
circle(this.pos.x,this.pos.y,size);
push();
rotate(this.angle);
line(this.pos.x,this.pos.y,this.pos.x,this.pos.y+100)
pop();
}
}
class Car {
constructor(x, y) {
this.pos = createVector(x, y);
this.vel = createVector(0, 0);
this.acc = createVector(0, 0);
}
accelerate(acc) {
this.acc.add(acc);
}
update() {
// v = v_o + a*t
this.vel.add(this.acc.mult(dt));
// p = p_0 + v_0 * t + 1/2 * a * t^2
this.pos.add(this.vel.mult(dt));
this.acc.mult(0);
}
render(){
stroke(0);
let size = 10;
circle(this.pos.x,this.pos.y,size);
}
}
let car;
let radar;
const dt = 1;
function setup() {
createCanvas(400, 400);
car = new Car(0,200);
car.accelerate(1);
radar = new Radar(200,200,0);
}
function draw() {
background(220);
car.update();
car.render();
radar.update();
radar.render();
}