Stop working on the graph
This commit is contained in:
@@ -9,8 +9,6 @@ import {
|
|||||||
} from "#/lib/Graph.ts";
|
} from "#/lib/Graph.ts";
|
||||||
import {
|
import {
|
||||||
createVector,
|
createVector,
|
||||||
fromPolar,
|
|
||||||
getDirection,
|
|
||||||
getDistance,
|
getDistance,
|
||||||
scale,
|
scale,
|
||||||
setDistanceNormal,
|
setDistanceNormal,
|
||||||
@@ -102,7 +100,7 @@ function applyRepulsion(nodes: Array<PhysicsPartial>): void {
|
|||||||
|
|
||||||
function hookEdge<T extends PhysicsPartial>([a, b]: Edge<T>): void {
|
function hookEdge<T extends PhysicsPartial>([a, b]: Edge<T>): void {
|
||||||
const restLength = 86;
|
const restLength = 86;
|
||||||
const stiffness = 0.2;
|
const stiffness = 0.05;
|
||||||
|
|
||||||
const direction = createVector();
|
const direction = createVector();
|
||||||
setDistanceNormal(direction, a.position, b.position);
|
setDistanceNormal(direction, a.position, b.position);
|
||||||
@@ -130,7 +128,7 @@ export const GraphBrowser: Component<{
|
|||||||
const enhanceNode = (node: string) => {
|
const enhanceNode = (node: string) => {
|
||||||
return {
|
return {
|
||||||
name: node,
|
name: node,
|
||||||
position: createVector(Math.random(), Math.random()),
|
position: createVector(Math.random() * 128 - 64, Math.random() * 32 - 16),
|
||||||
velocity: createVector(),
|
velocity: createVector(),
|
||||||
acceleration: createVector(),
|
acceleration: createVector(),
|
||||||
};
|
};
|
||||||
@@ -184,6 +182,7 @@ export const GraphBrowser: Component<{
|
|||||||
hookEdge(edge);
|
hookEdge(edge);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let absV = 0;
|
||||||
for (const node of nodes) {
|
for (const node of nodes) {
|
||||||
node.velocity.x += node.acceleration.x;
|
node.velocity.x += node.acceleration.x;
|
||||||
node.velocity.y += node.acceleration.y;
|
node.velocity.y += node.acceleration.y;
|
||||||
@@ -196,8 +195,11 @@ export const GraphBrowser: Component<{
|
|||||||
|
|
||||||
node.acceleration.x = 0;
|
node.acceleration.x = 0;
|
||||||
node.acceleration.y = 0;
|
node.acceleration.y = 0;
|
||||||
|
|
||||||
|
absV = Math.abs(node.velocity.x) + Math.abs(node.velocity.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (absV < 0.01) {
|
||||||
ctx.restore();
|
ctx.restore();
|
||||||
ctx.clearRect(0, 0, canvasRef.width, canvasRef.height);
|
ctx.clearRect(0, 0, canvasRef.width, canvasRef.height);
|
||||||
ctx.save();
|
ctx.save();
|
||||||
@@ -221,8 +223,10 @@ export const GraphBrowser: Component<{
|
|||||||
drawNode(activeRenderNode, ctx, "#ee459e");
|
drawNode(activeRenderNode, ctx, "#ee459e");
|
||||||
|
|
||||||
setTimeout(animate, 100);
|
setTimeout(animate, 100);
|
||||||
|
} else {
|
||||||
|
animate();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
animate();
|
animate();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"name": "fuzzScene",
|
||||||
|
"width": 240,
|
||||||
|
"height": 160,
|
||||||
|
"entities": [
|
||||||
|
{
|
||||||
|
"name": "barEntity",
|
||||||
|
"position": {
|
||||||
|
"x": 0,
|
||||||
|
"y": 0
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "barEntity",
|
||||||
|
"position": {
|
||||||
|
"x": 24,
|
||||||
|
"y": 16
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
import { useScene } from "#/engine/Scene.ts";
|
||||||
|
import data from "./data.json";
|
||||||
|
|
||||||
|
const { process, linkScenes } = useScene(data);
|
||||||
|
|
||||||
|
linkScenes(["testScene"] as const);
|
||||||
|
|
||||||
|
process((_ctx, _delta) => {});
|
||||||
@@ -3,6 +3,6 @@ import data from "./data.json";
|
|||||||
|
|
||||||
const { process, linkScenes } = useScene(data);
|
const { process, linkScenes } = useScene(data);
|
||||||
|
|
||||||
linkScenes(["fooScene", "barScene"] as const);
|
linkScenes(["fooScene", "fuzzScene"] as const);
|
||||||
|
|
||||||
process((_ctx, _delta) => {});
|
process((_ctx, _delta) => {});
|
||||||
|
|||||||
Reference in New Issue
Block a user