Add mulberry32
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
|||||||
getNeighbours,
|
getNeighbours,
|
||||||
type Node,
|
type Node,
|
||||||
} from "#/lib/Graph.ts";
|
} from "#/lib/Graph.ts";
|
||||||
|
import { mulberry32 } from "#/lib/mulberry32.ts";
|
||||||
import {
|
import {
|
||||||
createVector,
|
createVector,
|
||||||
getDistance,
|
getDistance,
|
||||||
@@ -119,8 +120,10 @@ function hookEdge<T extends PhysicsPartial>([a, b]: Edge<T>): void {
|
|||||||
|
|
||||||
export const GraphBrowser: Component<{
|
export const GraphBrowser: Component<{
|
||||||
graph: Graph<string>;
|
graph: Graph<string>;
|
||||||
|
seed: number;
|
||||||
}> = (props) => {
|
}> = (props) => {
|
||||||
let canvasRef!: HTMLCanvasElement;
|
let canvasRef!: HTMLCanvasElement;
|
||||||
|
const next = mulberry32(props.seed);
|
||||||
|
|
||||||
const [width] = createSignal(300);
|
const [width] = createSignal(300);
|
||||||
const [height] = createSignal(300);
|
const [height] = createSignal(300);
|
||||||
@@ -128,7 +131,7 @@ export const GraphBrowser: Component<{
|
|||||||
const enhanceNode = (node: string) => {
|
const enhanceNode = (node: string) => {
|
||||||
return {
|
return {
|
||||||
name: node,
|
name: node,
|
||||||
position: createVector(Math.random() * 128 - 64, Math.random() * 32 - 16),
|
position: createVector(next() * 128 - 64, next() * 32 - 16),
|
||||||
velocity: createVector(),
|
velocity: createVector(),
|
||||||
acceleration: createVector(),
|
acceleration: createVector(),
|
||||||
};
|
};
|
||||||
|
|||||||
+1
-1
@@ -182,7 +182,7 @@ const DevTools: Component<{ gameContainer: HTMLElement }> = ({
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ItemList name="Scenes" handler={setCurrentScene} items={scenes} />
|
<ItemList name="Scenes" handler={setCurrentScene} items={scenes} />
|
||||||
<GraphBrowser graph={sceneGraph} />
|
<GraphBrowser graph={sceneGraph} seed={1308146451} />
|
||||||
|
|
||||||
<ItemList name="Entities" handler={selectEntity} items={entities} />
|
<ItemList name="Entities" handler={selectEntity} items={entities} />
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
/**
|
||||||
|
* @see https://github.com/cprosche/mulberry32
|
||||||
|
*/
|
||||||
|
export function mulberry32(a: number) {
|
||||||
|
return () => {
|
||||||
|
a |= 0;
|
||||||
|
a = (a + 0x6d2b79f5) | 0;
|
||||||
|
let t = Math.imul(a ^ (a >>> 15), 1 | a);
|
||||||
|
t = (t + Math.imul(t ^ (t >>> 7), 61 | t)) ^ t;
|
||||||
|
return ((t ^ (t >>> 14)) >>> 0) / 4294967296;
|
||||||
|
};
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user