-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate.js
More file actions
26 lines (20 loc) · 780 Bytes
/
generate.js
File metadata and controls
26 lines (20 loc) · 780 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { replicate } from './util.js'
export const generators = {
Field2D(width, height) {
const TARGET_CELLS = 1000000
const scale = Math.ceil(Math.sqrt(width * height / TARGET_CELLS))
const xLength = Math.ceil(width / scale)
const yLength = Math.ceil(height / scale)
field = replicate(xLength, () => replicate(yLength, () => [ 0, 0 ]))
return { ...this.Particles([ width, height ]), field }
},
Particles(dimensions) {
const QUANTITY = 1000
const particles = replicate(QUANTITY, () => ({
position: dimensions.map((dim) => (Math.random() - .5) * dim),
velocity: dimensions.map(() => Math.random() - .5),
mass: 1
}))
return { particles }
},
}