From 38d2966d5d9fa049f2bcd6cd3ce5e0b8050dd73f Mon Sep 17 00:00:00 2001 From: melianor Date: Mon, 8 Jul 2019 20:54:58 +0300 Subject: [PATCH] add connect-particles option --- build.gradle | 4 ++-- gradle/wrapper/gradle-wrapper.properties | 3 ++- gradlew | 0 gradlew.bat | 0 .../main/java/me/ibrahimsn/particle/ParticleView.kt | 10 +++++++--- particle/src/main/res/values/attrs.xml | 1 + 6 files changed, 12 insertions(+), 6 deletions(-) mode change 100755 => 100644 gradlew mode change 100644 => 100755 gradlew.bat diff --git a/build.gradle b/build.gradle index d80d416..f1fb5ef 100644 --- a/build.gradle +++ b/build.gradle @@ -1,13 +1,13 @@ // Top-level build file where you can add configuration options common to all sub-projects/modules. buildscript { - ext.kotlin_version = '1.3.11' + ext.kotlin_version = '1.3.41' repositories { google() jcenter() } dependencies { - classpath 'com.android.tools.build:gradle:3.2.1' + classpath 'com.android.tools.build:gradle:3.4.1' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9a4163a..157a4e0 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,6 @@ +#Mon Jul 08 20:51:22 EET 2019 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip diff --git a/gradlew b/gradlew old mode 100755 new mode 100644 diff --git a/gradlew.bat b/gradlew.bat old mode 100644 new mode 100755 diff --git a/particle/src/main/java/me/ibrahimsn/particle/ParticleView.kt b/particle/src/main/java/me/ibrahimsn/particle/ParticleView.kt index 318f474..d8511a2 100644 --- a/particle/src/main/java/me/ibrahimsn/particle/ParticleView.kt +++ b/particle/src/main/java/me/ibrahimsn/particle/ParticleView.kt @@ -6,6 +6,7 @@ import android.util.AttributeSet import android.view.SurfaceHolder import android.view.SurfaceView import android.view.ViewTreeObserver +import kotlin.math.sqrt import kotlin.random.Random class ParticleView : SurfaceView, SurfaceHolder.Callback { @@ -17,6 +18,7 @@ class ParticleView : SurfaceView, SurfaceHolder.Callback { private var count = 20 private var minRadius = 5 private var maxRadius = 10 + private var lines = true private var hasSurface: Boolean = false private var background = Color.BLACK @@ -33,6 +35,7 @@ class ParticleView : SurfaceView, SurfaceHolder.Callback { constructor(context: Context, attrs: AttributeSet) : super(context, attrs) { val a = context.obtainStyledAttributes(attrs, R.styleable.ParticleView, 0, 0) + lines = a.getBoolean(R.styleable.ParticleView_lines, lines) count = a.getInt(R.styleable.ParticleView_particleCount, count) minRadius = a.getInt(R.styleable.ParticleView_minParticleRadius, minRadius) maxRadius = a.getInt(R.styleable.ParticleView_maxParticleRadius, maxRadius) @@ -141,8 +144,9 @@ class ParticleView : SurfaceView, SurfaceHolder.Callback { else if (particles[i]!!.y > height) particles[i]!!.y = 0F - for (j in 0 until count) - linkParticles(canvas, particles[i]!!, particles[j]!!) + if (lines) + for (j in 0 until count) + linkParticles(canvas, particles[i]!!, particles[j]!!) paint.alpha = particles[i]!!.alpha canvas.drawCircle(particles[i]!!.x, particles[i]!!.y, particles[i]!!.radius, paint) @@ -173,7 +177,7 @@ class ParticleView : SurfaceView, SurfaceHolder.Callback { private fun linkParticles(canvas: Canvas, p1: Particle, p2: Particle) { val dx = p1.x - p2.x val dy = p1.y - p2.y - val dist = Math.sqrt((dx * dx + dy * dy).toDouble()).toInt() + val dist = sqrt((dx * dx + dy * dy).toDouble()).toInt() if (dist < 225) { path.moveTo(p1.x, p1.y) diff --git a/particle/src/main/res/values/attrs.xml b/particle/src/main/res/values/attrs.xml index 7f34389..85cfef3 100644 --- a/particle/src/main/res/values/attrs.xml +++ b/particle/src/main/res/values/attrs.xml @@ -1,6 +1,7 @@ +