Answer the question
In order to leave comments, you need to log in
How to get a set of points on the coordinate plane?
I set out to get rid of global variables and pass all the data necessary for the function to work through parameters. For the task of getting a set of points on the coordinate plane, I wrote the following code:
const walls$ = combineLatest(
range(0, constants.wallsCnt),
of(constants.canvasWidthPx),
of(constants.canvasHeightPx),
of(constants.wallSizePx),
)
.pipe(
map(([range, canvasWidthPx, canvasHeightPx, wallSizePx]) => {
return {
x: Math.floor(Math.random() * Math.floor(canvasWidthPx - wallSizePx)),
y: Math.floor(Math.random() * Math.floor(canvasHeightPx - wallSizePx)),
strength: Math.floor(Math.random() * Math.floor(constants.wallStrengthMax)) + 1,
}
}),
toArray(),
tap(v => {
console.log(v)
}),
).subscribe()
constants.wallsCnt = 3
const walls$ = range(0, constants.wallsCnt)
.pipe(
map(_ => {
return {
x: Math.floor(Math.random() * Math.floor(constants.canvasWidthPx - constants.wallSizePx)),
y: Math.floor(Math.random() * Math.floor(constants.canvasHeightPx - constants.wallSizePx)),
strength: Math.floor(Math.random() * Math.floor(constants.wallStrengthMax)) + 1,
}
}),
toArray(),
)
Answer the question
In order to leave comments, you need to log in
However, you made me scratch my head with your question
. Of course, the way to calculate coordinates in this way is a complete perversion, however, this behavior of combineLatest puzzled me for a while :)
But everything turned out to be quite simple https://stackblitz.com/edit/tanks-field -without-gl...
Spot the difference.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question