22 * particles.js
33 * --------------------------------------------------
44 * 背景パーティクルアニメーションを生成するスクリプト。
5- * p5.js を使用し、5種類のビジュアルモードをランダムで表示 。
5+ * p5.js を使用し、3種類のビジュアルモードをランダムで表示 。
66 *
77 * モード一覧:
8- * 0: Network, 1: Cosmos, 2: Polygons,
9- * 3: Circuit, 4: Grid
8+ * 0: Network, 1: Polygons, 2: Circuit
109 * --------------------------------------------------
1110 */
1211let canvas ;
1312let particles = [ ] ;
1413let mode = 0 ;
15- // 0: Network, 1: Cosmos, 2: Polygons
16- // 3: Circuit, 4: Grid
17- const NUM_MODES = 5 ;
18- const modeNames = [
19- "Network" ,
20- "Cosmos" ,
21- "Polygons" ,
22- "Circuit" ,
23- "Grid" ,
24- ] ;
14+ // 0: Network, 1: Polygons, 2: Circuit
15+ const NUM_MODES = 3 ;
16+ const modeNames = [ "Network" , "Polygons" , "Circuit" ] ;
2517
2618// サイトのテーマカラー(Indigo, SkyBlue, Whiteish + Alpha variants)
2719const themeColors = [
@@ -54,17 +46,11 @@ function draw() {
5446 drawNetwork ( ) ;
5547 break ;
5648 case 1 :
57- drawCosmos ( ) ;
58- break ;
59- case 2 :
6049 drawPolygons ( ) ;
6150 break ;
62- case 3 :
51+ case 2 :
6352 drawCircuit ( ) ;
6453 break ;
65- case 4 :
66- drawGrid ( ) ;
67- break ;
6854 }
6955}
7056
@@ -86,28 +72,15 @@ function initParticles() {
8672 for ( let i = 0 ; i < count ; i ++ )
8773 particles . push ( new NetworkParticle ( ) ) ;
8874 } else if ( mode === 1 ) {
89- // Cosmos
90- count = constrain ( Math . floor ( area / 4000 ) , 80 , 250 ) ;
91- for ( let i = 0 ; i < count ; i ++ )
92- particles . push ( new StarParticle ( ) ) ;
93- } else if ( mode === 2 ) {
9475 // Polygons
9576 count = constrain ( Math . floor ( area / 20000 ) , 15 , 40 ) ;
9677 for ( let i = 0 ; i < count ; i ++ )
9778 particles . push ( new PolygonParticle ( ) ) ;
98- } else if ( mode === 3 ) {
79+ } else if ( mode === 2 ) {
9980 // Circuit
10081 count = constrain ( Math . floor ( area / 15000 ) , 15 , 40 ) ;
10182 for ( let i = 0 ; i < count ; i ++ )
10283 particles . push ( new CircuitPulse ( ) ) ;
103- } else if ( mode === 4 ) {
104- // Grid
105- let step = 50 ; // グリッド間隔
106- for ( let x = step / 2 ; x < width ; x += step ) {
107- for ( let y = step / 2 ; y < height ; y += step ) {
108- particles . push ( new GridPoint ( x , y ) ) ;
109- }
110- }
11184 }
11285}
11386
@@ -186,74 +159,7 @@ function drawNetwork() {
186159}
187160
188161// ------------------------------------------------------------
189- // Mode 1: Cosmos
190- // ------------------------------------------------------------
191- class StarParticle {
192- constructor ( ) {
193- this . pos = createVector ( random ( width ) , random ( height ) ) ;
194- this . vel = createVector (
195- random ( - 0.1 , 0.1 ) ,
196- random ( - 0.1 , 0.1 ) ,
197- ) ;
198- this . baseSize = random ( 1 , 3 ) ;
199- this . color = random ( themeColors ) ;
200- this . twinkleSpeed = random ( 0.02 , 0.08 ) ;
201- this . twinkleOffset = random ( TWO_PI ) ;
202- }
203- update ( ) {
204- this . pos . add ( this . vel ) ;
205- if ( this . pos . x < 0 ) this . pos . x = width ;
206- if ( this . pos . x > width ) this . pos . x = 0 ;
207- if ( this . pos . y < 0 ) this . pos . y = height ;
208- if ( this . pos . y > height ) this . pos . y = 0 ;
209- }
210- display ( ) {
211- let val = sin (
212- frameCount * this . twinkleSpeed + this . twinkleOffset ,
213- ) ;
214- let size = map (
215- val ,
216- - 1 ,
217- 1 ,
218- this . baseSize * 0.5 ,
219- this . baseSize * 1.5 ,
220- ) ;
221- let alpha = map ( val , - 1 , 1 , 100 , 255 ) ;
222- noStroke ( ) ;
223- fill (
224- this . color [ 0 ] ,
225- this . color [ 1 ] ,
226- this . color [ 2 ] ,
227- alpha * 0.3 ,
228- ) ;
229- circle ( this . pos . x , this . pos . y , size * 3 ) ;
230- fill ( 255 , 255 , 255 , alpha ) ;
231- circle ( this . pos . x , this . pos . y , size * 0.8 ) ;
232- }
233- }
234- function drawCosmos ( ) {
235- let mouse = createVector ( mouseX , mouseY ) ;
236- let isMouseActive =
237- mouseX > 0 &&
238- mouseX < width &&
239- mouseY > 0 &&
240- mouseY < height ;
241- for ( let p of particles ) {
242- if ( isMouseActive ) {
243- let d = p . pos . dist ( mouse ) ;
244- if ( d < 100 ) {
245- let force = p5 . Vector . sub ( p . pos , mouse ) ;
246- force . setMag ( 0.5 ) ;
247- p . pos . add ( force ) ;
248- }
249- }
250- p . update ( ) ;
251- p . display ( ) ;
252- }
253- }
254-
255- // ------------------------------------------------------------
256- // Mode 2: Polygons
162+ // Mode 1: Polygons
257163// ------------------------------------------------------------
258164class PolygonParticle {
259165 constructor ( ) {
@@ -304,7 +210,7 @@ function drawPolygons() {
304210}
305211
306212// ------------------------------------------------------------
307- // Mode 3 : Circuit (Electronic Circuit Pulse)
213+ // Mode 2 : Circuit (Electronic Circuit Pulse)
308214// ------------------------------------------------------------
309215class CircuitPulse {
310216 constructor ( ) {
@@ -394,47 +300,3 @@ function drawCircuit() {
394300 p . display ( ) ;
395301 }
396302}
397-
398- // ------------------------------------------------------------
399- // Mode 4: Grid
400- // ------------------------------------------------------------
401- class GridPoint {
402- constructor ( x , y ) {
403- this . origPos = createVector ( x , y ) ;
404- this . pos = this . origPos . copy ( ) ;
405- this . color = random ( themeColors ) ;
406- this . size = 3 ;
407- }
408- update ( ) {
409- let mouse = createVector ( mouseX , mouseY ) ;
410- if (
411- mouseX > 0 &&
412- mouseX < width &&
413- mouseY > 0 &&
414- mouseY < height
415- ) {
416- let d = this . origPos . dist ( mouse ) ;
417- if ( d < 150 ) {
418- let force = p5 . Vector . sub ( this . origPos , mouse ) ;
419- let strength = map ( d , 0 , 150 , 30 , 0 ) ;
420- force . setMag ( strength ) ;
421- this . pos = p5 . Vector . add ( this . origPos , force ) ;
422- } else {
423- this . pos . lerp ( this . origPos , 0.1 ) ;
424- }
425- } else {
426- this . pos . lerp ( this . origPos , 0.1 ) ;
427- }
428- }
429- display ( ) {
430- noStroke ( ) ;
431- fill ( this . color [ 0 ] , this . color [ 1 ] , this . color [ 2 ] , 150 ) ;
432- circle ( this . pos . x , this . pos . y , this . size ) ;
433- }
434- }
435- function drawGrid ( ) {
436- for ( let p of particles ) {
437- p . update ( ) ;
438- p . display ( ) ;
439- }
440- }
0 commit comments