Skip to content

Commit

Permalink
simpler initial seed
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheraff committed Oct 4, 2024
1 parent edd451d commit c938c06
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
10 changes: 5 additions & 5 deletions src/pages/wave-function-collapse/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ export default function () {
worker.postMessage({ type, data }, { transfer })
}

const height = 30
const width = 30
const height = 40
const width = 40
const drawX = ctx.canvas.width / width
const drawY = ctx.canvas.height / height
let map: Extract<Outgoing, { type: "started" }>["data"]["map"]
Expand Down Expand Up @@ -132,15 +132,15 @@ export default function () {
}

const seed = (count: number) => {
const forces: Array<[x: number, y: number, t: number]> = []
const forces: Array<[x: number, y: number]> = []
for (let i = 0; i < count; i++) {
forces.push([Math.floor(Math.random() * width), Math.floor(Math.random() * height), tiles[Math.floor(Math.random() * tiles.length)].name])
forces.push([Math.floor(Math.random() * width), Math.floor(Math.random() * height)])
}
return forces
}

worker.addEventListener('message', onMessage)
const force = seed(4)
const force = seed(10)
console.log(force)
post("start", { height, width, tiles, force })
return () => {
Expand Down
24 changes: 12 additions & 12 deletions src/pages/wave-function-collapse/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export type Tile = {
}

export type Incoming =
| { type: "start", data: { height: number, width: number, tiles: Pick<Tile, 'name' | 'sides'>[], force?: Array<[x: number, y: number, name: number]> } }
| { type: "start", data: { height: number, width: number, tiles: Pick<Tile, 'name' | 'sides'>[], force?: Array<[x: number, y: number]> } }

export type Outgoing =
| { type: "started", data: { buffer: SharedArrayBuffer, map: Pick<Tile, 'name' | 'rotate'>[] } }
Expand All @@ -28,11 +28,11 @@ function handleMessage(event: Incoming) {
for (const tile of event.data.tiles) {
const clone = tiles.find((other) => other.sides.every((side, i) => side === tile.sides[i]))
if (clone) {
if (event.data.force) {
for (const forced of event.data.force) {
if (clone.name === forced[2]) forced[2] = tile.name
}
}
// if (event.data.force) {
// for (const forced of event.data.force) {
// if (clone.name === forced[2]) forced[2] = tile.name
// }
// }
continue
}
tiles.push({
Expand All @@ -41,11 +41,11 @@ function handleMessage(event: Incoming) {
rotate: 0
})
}
if (event.data.force) for (const forced of event.data.force) {
const t = tiles.findIndex((tile) => tile.name === forced[2])
if (t === -1) continue
forced[2] = t
}
// if (event.data.force) for (const forced of event.data.force) {
// const t = tiles.findIndex((tile) => tile.name === forced[2])
// if (t === -1) continue
// forced[2] = t
// }
for (let i = 0, l = tiles.length; i < l; i++) {
const tile = tiles[i]
for (let r = 1; r < tile.sides.length; r++) {
Expand All @@ -71,7 +71,7 @@ function handleMessage(event: Incoming) {
tiles,
buffer,
onDone,
force: event.data.force
force: event.data.force?.map(([x, y]) => [x, y, Math.floor(Math.random() * tiles.length)])
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export const ROUTES = {
image: wave_function_collapse_image
},
git: {
lastModified: NaN,
firstAdded: NaN
lastModified: 1727995709000,
firstAdded: 1727995709000
},
},
"spider-inverse-kinematics": {
Expand Down

0 comments on commit c938c06

Please sign in to comment.