Skip to content

Commit 38d2966

Browse files
committed
add connect-particles option
1 parent c9bbf1f commit 38d2966

File tree

6 files changed

+12
-6
lines changed

6 files changed

+12
-6
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.kotlin_version = '1.3.11'
4+
ext.kotlin_version = '1.3.41'
55
repositories {
66
google()
77
jcenter()
88
}
99
dependencies {
10-
classpath 'com.android.tools.build:gradle:3.2.1'
10+
classpath 'com.android.tools.build:gradle:3.4.1'
1111
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
1212
// NOTE: Do not place your application dependencies here; they belong
1313
// in the individual module build.gradle files
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
#Mon Jul 08 20:51:22 EET 2019
12
distributionBase=GRADLE_USER_HOME
23
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip

gradlew

100755100644
File mode changed.

gradlew.bat

100644100755
File mode changed.

particle/src/main/java/me/ibrahimsn/particle/ParticleView.kt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import android.util.AttributeSet
66
import android.view.SurfaceHolder
77
import android.view.SurfaceView
88
import android.view.ViewTreeObserver
9+
import kotlin.math.sqrt
910
import kotlin.random.Random
1011

1112
class 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)

particle/src/main/res/values/attrs.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
33
<declare-styleable name="ParticleView">
4+
<attr name="lines" format="boolean" />
45
<attr name="backgroundColor" format="color" />
56
<attr name="particleColor" format="color" />
67
<attr name="particleCount" format="integer" />

0 commit comments

Comments
 (0)