diff --git a/app/src/main/java/com/kylecorry/trail_sense/shared/Extensions.kt b/app/src/main/java/com/kylecorry/trail_sense/shared/Extensions.kt index 50831c1c2..3d51a4489 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/shared/Extensions.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/shared/Extensions.kt @@ -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 @@ -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 @@ -215,4 +219,26 @@ fun List.padRight(minLength: Int, value: T): List { fun formatEnumName(name: String): String { return name.map { if (it.isUpperCase()) " $it" else it } .joinToString("").trim() -} \ No newline at end of file +} + +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) +} diff --git a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ui/layers/ARAstronomyLayer.kt b/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ui/layers/ARAstronomyLayer.kt index 049afbcaf..8d00e040b 100644 --- a/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ui/layers/ARAstronomyLayer.kt +++ b/app/src/main/java/com/kylecorry/trail_sense/tools/augmented_reality/ui/layers/ARAstronomyLayer.kt @@ -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 @@ -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 @@ -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()) @@ -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): List> { val lines = mutableListOf>() var currentLine = mutableListOf() diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 96c1d82a5..6ae706b70 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -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"