Skip to content

Commit

Permalink
Add color to stars
Browse files Browse the repository at this point in the history
Signed-off-by: Kyle Corry <[email protected]>
  • Loading branch information
kylecorry31 committed Dec 8, 2024
1 parent 03049f6 commit f35e736
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 30 deletions.
28 changes: 27 additions & 1 deletion app/src/main/java/com/kylecorry/trail_sense/shared/Extensions.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kylecorry.trail_sense.shared

import android.graphics.Color
import android.os.Bundle
import android.view.View
import android.view.Window
Expand All @@ -11,9 +12,12 @@ import androidx.navigation.NavOptions
import com.kylecorry.andromeda.canvas.ICanvasDrawer
import com.kylecorry.andromeda.core.system.GeoUri
import com.kylecorry.andromeda.core.tryOrDefault
import com.kylecorry.andromeda.core.ui.Colors
import com.kylecorry.andromeda.core.ui.colormaps.RgbInterpolationColorMap
import com.kylecorry.andromeda.core.units.PixelCoordinate
import com.kylecorry.andromeda.signal.CellNetworkQuality
import com.kylecorry.andromeda.signal.ICellSignalSensor
import com.kylecorry.sol.math.SolMath
import com.kylecorry.sol.math.SolMath.roundPlaces
import com.kylecorry.sol.math.Vector2
import com.kylecorry.sol.math.geometry.Rectangle
Expand Down Expand Up @@ -215,4 +219,26 @@ fun <T> List<T>.padRight(minLength: Int, value: T): List<T> {
fun formatEnumName(name: String): String {
return name.map { if (it.isUpperCase()) " $it" else it }
.joinToString("").trim()
}
}

fun Colors.fromColorTemperature(temp: Float): Int {
// http://www.vendian.org/mncharity/dir3/blackbody/UnstableURLs/bbr_color.html
val map = RgbInterpolationColorMap(
arrayOf(
Color.rgb(255, 51, 0), // 1000K
Color.rgb(255, 137, 18), // 2000K
Color.rgb(255, 185, 105), // 3000K
Color.rgb(255, 209, 163), // 4000K
Color.rgb(255, 231, 204), // 5000K
Color.rgb(255, 244, 237), // 6000K
Color.rgb(245, 243, 255), // 7000K
Color.rgb(229, 233, 255), // 8000K
Color.rgb(217, 225, 255), // 9000K
Color.rgb(207, 218, 255), // 10000K
)
)

val percent = SolMath.map(temp, 1000f, 10000f, 0f, 1f, true)

return map.getColor(percent)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package com.kylecorry.trail_sense.tools.augmented_reality.ui.layers

import android.graphics.Color
import com.kylecorry.andromeda.canvas.ICanvasDrawer
import com.kylecorry.andromeda.core.ui.Colors
import com.kylecorry.andromeda.core.ui.Colors.withAlpha
import com.kylecorry.andromeda.core.units.PixelCoordinate
import com.kylecorry.luna.coroutines.CoroutineQueueRunner
import com.kylecorry.luna.coroutines.onDefault
import com.kylecorry.luna.hooks.Hooks
import com.kylecorry.sol.math.SolMath.map
import com.kylecorry.sol.science.astronomy.Astronomy
Expand All @@ -14,6 +16,7 @@ import com.kylecorry.sol.time.Time
import com.kylecorry.sol.units.Coordinate
import com.kylecorry.sol.units.Distance
import com.kylecorry.trail_sense.shared.colors.AppColor
import com.kylecorry.trail_sense.shared.fromColorTemperature
import com.kylecorry.trail_sense.shared.hooks.HookTriggers
import com.kylecorry.trail_sense.tools.astronomy.domain.AstronomyService
import com.kylecorry.trail_sense.tools.astronomy.ui.MoonPhaseImageMapper
Expand Down Expand Up @@ -297,33 +300,7 @@ class ARAstronomyLayer(
)
}

// STARS
val starMarkers = if (drawStars) {
val stars = astro.getVisibleStars(location, time)
stars.map {
ARMarker(
SphericalARPoint(
it.second.first.value,
it.second.second,
isTrueNorth = true,
angularDiameter = map(
-it.first.magnitude,
-2f,
1.5f,
0.4f,
0.8f,
true
)
),
canvasObject = CanvasCircle(Color.WHITE),
onFocusedFn = {
onStarFocus(it.first)
}
)
}
} else {
emptyList()
}
updateStarLayer(location, time)

lineLayer.setLines(sunLines + moonLines)
sunLayer.setMarkers(sunPointsToDraw.flatten())
Expand All @@ -332,11 +309,47 @@ class ARAstronomyLayer(
// The sun and moon can be drawn below the horizon
currentSunLayer.setMarkers(listOf(sun))
currentMoonLayer.setMarkers(listOf(moon))
starLayer.setMarkers(starMarkers)
}
}
}

private suspend fun updateStarLayer(location: Coordinate, time: ZonedDateTime) = onDefault {
val starMarkers = if (drawStars) {
val stars = astro.getVisibleStars(location, time)
stars.map {
ARMarker(
SphericalARPoint(
it.second.first.value,
it.second.second,
isTrueNorth = true,
angularDiameter = map(
-it.first.magnitude,
-2f,
1.5f,
0.4f,
0.8f,
true
)
),
canvasObject = CanvasCircle(
Colors.fromColorTemperature(
Astronomy.getColorTemperature(
it.first
)
)
),
onFocusedFn = {
onStarFocus(it.first)
}
)
}
} else {
emptyList()
}

starLayer.setMarkers(starMarkers)
}

private fun getMarkersAboveHorizon(points: List<ARMarker>): List<List<ARMarker>> {
val lines = mutableListOf<List<ARMarker>>()
var currentLine = mutableListOf<ARMarker>()
Expand Down
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ material = "1.10.0"
luna = "0.3.5"
mockitoKotlin = "5.1.0"
roomVersion = "2.6.1"
sol = "9.12.1"
sol = "9.12.2"
subsamplingScaleImageView = "3.11.9"
workRuntimeKtx = "2.10.0"
preferenceKtx = "1.2.1"
Expand Down

0 comments on commit f35e736

Please sign in to comment.