Skip to content

Commit 68e1b49

Browse files
committed
Limit the amount of eyes that can be generated
1 parent b3dead2 commit 68e1b49

File tree

3 files changed

+19
-6
lines changed

3 files changed

+19
-6
lines changed

components/Eyes/generatePoints.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,25 @@
1-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
2-
// @ts-ignore No types
31
import PoissonDiskSampling from 'poisson-disk-sampling'
42

53
export const generatePoints = (height: number, width: number, size: number) => {
64
const sample = new PoissonDiskSampling({
7-
shape: [height, width],
5+
shape: [Math.min(height, 2000), Math.min(width, 2000)],
86
minDistance: size,
97
maxDistance: size + (size * .5),
108
tries: 20,
119
})
1210

13-
const points: [number, number][] = sample.fill()
11+
// Area to avoid in the centre
12+
const avoid = {
13+
y: sample.shape[0] / 2,
14+
x: sample.shape[1] / 2,
15+
r: size * 1.5, // radius
16+
}
17+
18+
const points = sample.fill()
1419

1520
return points
16-
.map(([y, x]) => [(y / height) * 100, (x / width) * 100] as [number, number])
17-
.filter(([y, x]) => !(y > 30 && y < 70 && x > 40 && x < 60))
21+
// Remove points from the avoidance area
22+
.filter(([y, x]) => Math.pow(avoid.y - y, 2) + Math.pow(avoid.x - x, 2) > Math.pow(avoid.r, 2))
23+
// Convert to percentages
24+
.map(([y, x]) => [(y / sample.shape[0]) * 100, (x / sample.shape[1]) * 100] as [number, number])
1825
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"@giraugh/tools": "^1.6.0",
1313
"@notionhq/client": "^2.2.5",
1414
"@types/node": "20.2.5",
15+
"@types/poisson-disk-sampling": "^2.2.1",
1516
"@types/react": "18.2.7",
1617
"@types/react-dom": "18.2.4",
1718
"@types/react-syntax-highlighter": "^15.5.7",

yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@
210210
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.2.5.tgz#26d295f3570323b2837d322180dfbf1ba156fefb"
211211
integrity sha512-JJulVEQXmiY9Px5axXHeYGLSjhkZEnD+MDPDGbCbIAbMslkKwmygtZFy1X6s/075Yo94sf8GuSlFfPzysQrWZQ==
212212

213+
"@types/poisson-disk-sampling@^2.2.1":
214+
version "2.2.1"
215+
resolved "https://registry.yarnpkg.com/@types/poisson-disk-sampling/-/poisson-disk-sampling-2.2.1.tgz#7848179b767e585f0ec6c42c7f9d6c0ad6c4d6b3"
216+
integrity sha512-v8koCm097E+3ovd7HAeNvsmJfIfI6MFQZJN1pGPbAsM2DwLe+1vGA4SxNP7b1cTED/yl0ZoZ/NzRv6mOLIy/qQ==
217+
213218
"@types/postcss-modules-local-by-default@^4.0.0":
214219
version "4.0.0"
215220
resolved "https://registry.yarnpkg.com/@types/postcss-modules-local-by-default/-/postcss-modules-local-by-default-4.0.0.tgz#5c141c9bd3a994ae1ebe23d2ae094b24d19538f5"

0 commit comments

Comments
 (0)