Orbit Demo: add delta animation + velocity
This commit is contained in:
parent
82f5a75ecd
commit
9a261f6f3c
1 changed files with 15 additions and 6 deletions
|
@ -43,10 +43,18 @@ export function OrbitDemo() {
|
|||
cx.scale(1 / 2, 1 / 2);
|
||||
cx.translate(512, 512);
|
||||
|
||||
const masses: { x: number; y: number; r: number; m: number; c: string }[] = [
|
||||
{ x: 0, y: 0, r: 10, m: 10000, c: "yellow" },
|
||||
{ x: -200, y: 200, r: 4, m: 4, c: "red" },
|
||||
{ x: -450, y: 0, r: 5, m: 5, c: "blue" },
|
||||
const masses: {
|
||||
x: number;
|
||||
y: number;
|
||||
vx: number;
|
||||
vy: number;
|
||||
r: number;
|
||||
m: number;
|
||||
c: string;
|
||||
}[] = [
|
||||
{ x: 0, y: 0, vx: 0, vy: 0, r: 10, m: 10000, c: "yellow" },
|
||||
{ x: -200, y: 200, vx: 100, vy: 100, r: 4, m: 4, c: "red" },
|
||||
{ x: -450, y: 0, vx: 0, vy: 100, r: 5, m: 5, c: "blue" },
|
||||
];
|
||||
|
||||
const tickSource = tick(16);
|
||||
|
@ -61,12 +69,13 @@ export function OrbitDemo() {
|
|||
case "physics":
|
||||
break;
|
||||
case "render":
|
||||
const [, dt] = tick;
|
||||
cx.fillStyle = "black";
|
||||
cx.fillRect(-512, -512, 1024, 1024);
|
||||
masses.forEach(({ x, y, r, c }) => {
|
||||
masses.forEach(({ x, y, vx, vy, r, c }) => {
|
||||
cx.fillStyle = c;
|
||||
cx.beginPath();
|
||||
cx.arc(x, y, r, 0, Math.PI * 2);
|
||||
cx.arc(x + vx * dt, y + vy * dt, r, 0, Math.PI * 2);
|
||||
cx.fill();
|
||||
});
|
||||
break;
|
||||
|
|
Loading…
Add table
Reference in a new issue