-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
199 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#Tue Aug 21 22:29:52 IDT 2018 | ||
#Sun Oct 14 03:02:00 IDT 2018 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
stars/src/main/java/com/sofakingforever/stars/MeteorEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package com.sofakingforever.stars | ||
|
||
import android.graphics.Canvas | ||
import android.graphics.Paint | ||
|
||
internal class MeteorEntity(starConstraints: Star.StarConstraints, var x: Int, var y: Int, var color: Int, viewWidth: Int, viewHeight: Int, private val colorListener: () -> Int, private val onDoneListener: () -> Unit) { | ||
|
||
// private val length: Double = (starConstraints.minStarSize + Math.random() * (starConstraints.maxStarSize - starConstraints.minStarSize)) | ||
private val fillPaint = Paint(Paint.ANTI_ALIAS_FLAG) | ||
// private val strokePaint = Paint(Paint.ANTI_ALIAS_FLAG) | ||
|
||
private var shape: Star.StarShape = Star.StarShape.Dot | ||
|
||
private val meteor: Meteor = Meteor(starConstraints, x, y, color, viewWidth, viewHeight, colorListener, onDoneListener) | ||
private val trail: Trail = Trail(meteor.star.length, meteor.star.fillPaint) | ||
|
||
init { | ||
|
||
// init fill paint for small and big stars | ||
fillPaint.color = color | ||
|
||
|
||
} | ||
|
||
fun calculateFrame(viewWidth: Int, viewHeight: Int) { | ||
trail.addPixel(meteor.star.x, meteor.star.y) | ||
trail.calculatePixels() | ||
meteor.calculateFrame(viewWidth, viewHeight) | ||
} | ||
|
||
fun onDraw(canvas: Canvas?): Canvas? { | ||
var newCanvas = canvas | ||
newCanvas = meteor.onDraw(newCanvas) | ||
newCanvas = trail.onDraw(newCanvas) | ||
|
||
return newCanvas | ||
} | ||
|
||
internal class Meteor(starConstraints: Star.StarConstraints, var x: Int, var y: Int, var color: Int, viewWidth: Int, viewHeight: Int, private val colorListener: () -> Int, private val onDoneListener: () -> Unit) { | ||
|
||
private var onDoneInvoked = false | ||
internal val star: Star = Star(starConstraints, x, y, false, 1.0, color, viewWidth, viewHeight, colorListener) | ||
|
||
|
||
fun calculateFrame(viewWidth: Int, viewHeight: Int) { | ||
// star.calculateFrame(viewWidth, viewHeight) | ||
star.x = star.x - 8 | ||
star.y = star.y + 8 | ||
|
||
if (star.x < viewWidth * -1 && !onDoneInvoked) { | ||
onDoneListener.invoke() | ||
onDoneInvoked = true | ||
} | ||
} | ||
|
||
fun onDraw(canvas: Canvas?): Canvas? { | ||
canvas?.drawCircle(star.x.toFloat(), star.y.toFloat(), star.length.toFloat() / 2f, star.fillPaint) | ||
|
||
return canvas | ||
} | ||
|
||
} | ||
|
||
|
||
internal class Trail(val length: Double, val fillPaint: Paint) { | ||
|
||
private val trailPixels: MutableList<TrailPixel> = mutableListOf() | ||
|
||
fun addPixel(x: Int, y: Int) { | ||
trailPixels.add(TrailPixel(x, y, length)) | ||
} | ||
|
||
fun calculatePixels() { | ||
trailPixels.forEach { it.calculatePixel() } | ||
} | ||
|
||
fun onDraw(canvas: Canvas?): Canvas? { | ||
|
||
val newList = trailPixels.toList() | ||
newList.forEach { | ||
val newPaint = fillPaint | ||
newPaint.alpha = (it.opacity * 255.0).toInt() | ||
canvas?.drawCircle(it.x.toFloat(), it.y.toFloat(), it.length.toFloat() / 2f, fillPaint) | ||
} | ||
return canvas | ||
} | ||
|
||
|
||
internal class TrailPixel(val x: Int, val y: Int, val length: Double) { | ||
fun calculatePixel() { | ||
opacity -= 0.015 | ||
|
||
if (opacity < 0) { | ||
opacity = 0.0 | ||
} | ||
} | ||
|
||
var opacity: Double = 0.90 | ||
|
||
|
||
} | ||
} | ||
} |
Oops, something went wrong.