MCPcopy Create free account
hub / github.com/Barrior/JParticles / createDots

Method createDots

src/particle.ts:195–231  ·  view source on GitHub ↗

* 根据配置参数创建许多粒子(纯数据) * 最后通过 draw 函数绘制真实可见的图形

()

Source from the content-addressed store, hash-verified

193 * 最后通过 draw 函数绘制真实可见的图形
194 */
195 private createDots(): void {
196 const { canvasWidth, canvasHeight, getColor } = this
197 const {
198 maxR,
199 minR,
200 maxSpeed,
201 minSpeed,
202 parallaxLayer,
203 spin,
204 spinMaxSpeed,
205 spinMinSpeed,
206 } = this.options
207 const layerLength = parallaxLayer.length
208 let { num } = this.options
209
210 while (num--) {
211 const r = randomInRange(maxR, minR)
212 this.elements.push({
213 r,
214 x: randomInRange(canvasWidth - r, r),
215 y: randomInRange(canvasHeight - r, r),
216 vx: randomSpeed(maxSpeed, minSpeed),
217 vy: randomSpeed(maxSpeed, minSpeed),
218 color: getColor(),
219 shape: this.getShapeData(),
220 // 定义粒子在视差图层里的层数及每层的层级大小
221 parallaxLayer: parallaxLayer[Math.floor(Math.random() * layerLength)],
222 // 定义粒子视差的偏移值
223 parallaxOffsetX: 0,
224 parallaxOffsetY: 0,
225 // 定义粒子的旋转角度
226 rotate: spin ? randomInRange(0, 360) : 0,
227 // 粒子的旋转速度
228 rotateSpeed: randomSpeed(spinMaxSpeed, spinMinSpeed),
229 })
230 }
231 }
232
233 /**
234 * 绘制粒子

Callers 1

initMethod · 0.95

Calls 2

randomInRangeFunction · 0.90
randomSpeedFunction · 0.90

Tested by

no test coverage detected