Skip to content

Instantly share code, notes, and snippets.

@thacuber2a03
Last active May 31, 2022 00:39
Show Gist options
  • Select an option

  • Save thacuber2a03/44655cffa21e73352881cff5e73696c3 to your computer and use it in GitHub Desktop.

Select an option

Save thacuber2a03/44655cffa21e73352881cff5e73696c3 to your computer and use it in GitHub Desktop.
SCRIPT-8
init = state => {
}
update = (state, input, elapsed) => {
}
draw = state => {
}
class Vector2D {
constructor(x=0,y=0) {
this.x = x;
this.y = y;
}
set(v) {
this.x = v.x;
this.y = v.y;
}
add(v,s=1) {
this.x += v.x * s;
this.y += v.y * s;
return this;
}
addVectors(a,b) {
this.x = a.x + b.x;
this.y = a.y + b.y;
}
sub(v,s=1) {
this.x -= v.x * s;
this.y -= v.y * s;
return this;
}
subVectors(a,b) {
this.x = a.x - b.x;
this.y = a.y - b.y;
}
scale(s) {
this.x *= s;
this.y *= s;
return this;
}
clone() { return new Vector2D(this.x,this.y); }
len() { return Math.sqrt(this.x*this.x+this.y*this.y); }
dot(v) { return this.x * v.x + this.y * v.y; }
perp() { return new Vector2D(-this.y,this.x); }
}
class Ball {
constructor(radius, mass, pos, vel, res) {
this.radius = radius;
this.mass = mass;
this.res = res;
this.pos = pos.clone();
this.vel = vel.clone();
}
simulate(dt,gravity) {
this.vel.add(gravity,dt);
this.pos.add(this.vel,dt);
}
}
class Obstacle {
constructor(radius, pos, pushVel) {
this.radius = radius;
this.pos = pos.clone();
this.pushVel = pushVel;
}
}
{
"iframeVersion": "0.1.280",
"lines": [
8,
44,
22,
0,
0,
0,
0,
0
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment