@@ -6,6 +6,7 @@ import android.util.AttributeSet
66import android.view.SurfaceHolder
77import android.view.SurfaceView
88import android.view.ViewTreeObserver
9+ import kotlin.math.sqrt
910import kotlin.random.Random
1011
1112class ParticleView : SurfaceView , SurfaceHolder .Callback {
@@ -17,6 +18,7 @@ class ParticleView : SurfaceView, SurfaceHolder.Callback {
1718 private var count = 20
1819 private var minRadius = 5
1920 private var maxRadius = 10
21+ private var lines = true
2022 private var hasSurface: Boolean = false
2123
2224 private var background = Color .BLACK
@@ -33,6 +35,7 @@ class ParticleView : SurfaceView, SurfaceHolder.Callback {
3335 constructor (context: Context , attrs: AttributeSet ) : super (context, attrs) {
3436 val a = context.obtainStyledAttributes(attrs, R .styleable.ParticleView , 0 , 0 )
3537
38+ lines = a.getBoolean(R .styleable.ParticleView_lines , lines)
3639 count = a.getInt(R .styleable.ParticleView_particleCount , count)
3740 minRadius = a.getInt(R .styleable.ParticleView_minParticleRadius , minRadius)
3841 maxRadius = a.getInt(R .styleable.ParticleView_maxParticleRadius , maxRadius)
@@ -141,8 +144,9 @@ class ParticleView : SurfaceView, SurfaceHolder.Callback {
141144 else if (particles[i]!! .y > height)
142145 particles[i]!! .y = 0F
143146
144- for (j in 0 until count)
145- linkParticles(canvas, particles[i]!! , particles[j]!! )
147+ if (lines)
148+ for (j in 0 until count)
149+ linkParticles(canvas, particles[i]!! , particles[j]!! )
146150
147151 paint.alpha = particles[i]!! .alpha
148152 canvas.drawCircle(particles[i]!! .x, particles[i]!! .y, particles[i]!! .radius, paint)
@@ -173,7 +177,7 @@ class ParticleView : SurfaceView, SurfaceHolder.Callback {
173177 private fun linkParticles (canvas : Canvas , p1 : Particle , p2 : Particle ) {
174178 val dx = p1.x - p2.x
175179 val dy = p1.y - p2.y
176- val dist = Math . sqrt((dx * dx + dy * dy).toDouble()).toInt()
180+ val dist = sqrt((dx * dx + dy * dy).toDouble()).toInt()
177181
178182 if (dist < 225 ) {
179183 path.moveTo(p1.x, p1.y)
0 commit comments