Skip to content

Commit

Permalink
add connect-particles option
Browse files Browse the repository at this point in the history
  • Loading branch information
ibrahimsn98 committed Jul 8, 2019
1 parent c9bbf1f commit 38d2966
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 2 additions & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
Empty file modified gradlew
100755 → 100644
Empty file.
Empty file modified gradlew.bat
100644 → 100755
Empty file.
10 changes: 7 additions & 3 deletions particle/src/main/java/me/ibrahimsn/particle/ParticleView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions particle/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="ParticleView">
<attr name="lines" format="boolean" />
<attr name="backgroundColor" format="color" />
<attr name="particleColor" format="color" />
<attr name="particleCount" format="integer" />
Expand Down

0 comments on commit 38d2966

Please sign in to comment.