From 8221e2b479feafe4e6f2b840a696f06032885add Mon Sep 17 00:00:00 2001 From: HR0101 Date: Thu, 15 Oct 2026 19:43:16 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20=E6=98=BC=E3=81=AE=E7=A9=BA=E3=82=92?= =?UTF-8?q?=E5=AD=A3=E7=AF=80=E3=81=94=E3=81=A8=E3=81=AB=E6=8F=8F=E3=81=8D?= =?UTF-8?q?=E5=88=86=E3=81=91=E3=80=81=E6=AD=A3=E5=8D=88=E3=81=AE=E5=AD=A3?= =?UTF-8?q?=E7=AF=80=E3=81=AE=E9=81=95=E3=81=84=E3=82=92=E8=A6=8B=E5=88=86?= =?UTF-8?q?=E3=81=91=E3=82=89=E3=82=8C=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 季節の色を10〜13%混ぜるだけだったため、正午の空は春・秋・冬がほぼ同じ色 (季節どうしの色差ΔEが0.8〜8.4)になっていた。 - 昼のキーフレーム(日の出1.5時間後、南中の1時間前と3時間後)に、季節ごとの 空の色を持たせる - 春: かすみがかった淡い空。地平線は桃色を帯びた白 - 夏: 濃く高い青。最も鮮やか - 秋: 夏より紫に寄った、澄んだ深い青 - 冬: 低く白っぽい空。最も淡い - 季節ごとの色を持つ時間帯は、一律の季節の色を混ぜない - 正午の季節どうしの色差がΔE 10以上になったため、#72 で既知の問題として 記録していた比較テストを通常のテストにする Refs #65 Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01ATcUWKWDs87zwTrKyiKpY4 --- BusTimeApp/DesignSystem/SkyPalette.swift | 121 ++++++++++++++++++----- BusTimeAppTests/BusTimeAppTests.swift | 53 +++++++--- README.md | 4 +- 3 files changed, 140 insertions(+), 38 deletions(-) diff --git a/BusTimeApp/DesignSystem/SkyPalette.swift b/BusTimeApp/DesignSystem/SkyPalette.swift index c50cc2a..a46ccd1 100644 --- a/BusTimeApp/DesignSystem/SkyPalette.swift +++ b/BusTimeApp/DesignSystem/SkyPalette.swift @@ -456,15 +456,37 @@ private struct SkyKeyframe { let event: SolarEvent /// 節目からの前後です。時間単位で、負の値は節目より前を表します。 let offset: Double + /// 季節ごとの色を持たないときの、空の上端の色です。 let skyTop: RGBComponents + /// 季節ごとの色を持たないときの、空の下端の色です。 let skyBottom: RGBComponents /// 空の暗さです。0が完全な昼、1が完全な夜を表し、文字色やカード色の決定に使います。 let nightness: Double + /// 季節ごとに描き分ける空の色です。ここにない季節は`skyTop`と`skyBottom`を使います。 + var seasonal: [Season: SkyColors] = [:] /// その日のこのキーフレームの時刻です。 func hour(in daylight: DaylightSchedule) -> Double { event.hour(in: daylight) + offset } + + /// その季節の空の色です。 + func colors(for season: Season) -> SkyColors { + seasonal[season] ?? SkyColors(top: skyTop, bottom: skyBottom) + } + + /// 季節の色(`Season.tint`)を混ぜる強さの倍率です。 + /// + /// 季節ごとの色を持つキーフレームは、それ自体が季節の空なので混ぜません。 + var seasonTintWeight: Double { + seasonal.isEmpty ? 1 : 0 + } +} + +/// 空の上端と下端の色の組です。 +private struct SkyColors { + let top: RGBComponents + let bottom: RGBComponents } /// 時刻に応じて連続的に変化するアプリ全体の配色です。 @@ -557,6 +579,34 @@ struct SkyPalette: Equatable { // MARK: - 時刻から配色を生成する + /// 昼の空の、季節ごとの色を作ります。 + /// + /// 季節の色を一律に混ぜるだけでは、昼の空がどの季節もほぼ同じ色になります。 + /// そこで昼のあいだは、季節ごとに空そのものの彩度・明度・地平線のかすみを変えます。 + /// - 春: かすみがかった淡い空です。地平線は桃色を帯びた白にかすみます。 + /// - 夏: 濃く高い青です。最も鮮やかで、地平線まで青が残ります。 + /// - 秋: 澄んだ青です。夏より紫に寄った深い青で、地平線はすっきり晴れます。 + /// - 冬: 低く白っぽい空です。最も淡く、地平線は冷たい白になります。 + private static func daytimeColors( + spring: (top: (Double, Double, Double), bottom: (Double, Double, Double)), + summer: (top: (Double, Double, Double), bottom: (Double, Double, Double)), + autumn: (top: (Double, Double, Double), bottom: (Double, Double, Double)), + winter: (top: (Double, Double, Double), bottom: (Double, Double, Double)) + ) -> [Season: SkyColors] { + func colors(_ pair: (top: (Double, Double, Double), bottom: (Double, Double, Double))) -> SkyColors { + SkyColors( + top: RGBComponents(red: pair.top.0, green: pair.top.1, blue: pair.top.2), + bottom: RGBComponents(red: pair.bottom.0, green: pair.bottom.1, blue: pair.bottom.2) + ) + } + return [ + .spring: colors(spring), + .summer: colors(summer), + .autumn: colors(autumn), + .winter: colors(winter) + ] + } + /// 1日の空の色を定義するキーフレームです。時刻順に並べる必要があります。 /// /// 日の出の前後は、空が白み始める薄明(約1時間15分前)から、 @@ -590,21 +640,39 @@ struct SkyPalette: Equatable { offset: 1.5, skyTop: RGBComponents(red: 0.318, green: 0.596, blue: 0.910), skyBottom: RGBComponents(red: 0.878, green: 0.941, blue: 0.988), - nightness: 0.0 + nightness: 0.0, + seasonal: daytimeColors( + spring: (top: (0.47, 0.66, 0.90), bottom: (0.95, 0.90, 0.93)), + summer: (top: (0.16, 0.56, 0.96), bottom: (0.74, 0.91, 0.99)), + autumn: (top: (0.31, 0.47, 0.87), bottom: (0.84, 0.89, 0.97)), + winter: (top: (0.60, 0.72, 0.84), bottom: (0.88, 0.92, 0.95)) + ) ), SkyKeyframe( event: .solarNoon, offset: -1, skyTop: RGBComponents(red: 0.400, green: 0.671, blue: 0.941), skyBottom: RGBComponents(red: 0.851, green: 0.937, blue: 0.996), - nightness: 0.0 + nightness: 0.0, + seasonal: daytimeColors( + spring: (top: (0.53, 0.70, 0.93), bottom: (0.95, 0.91, 0.94)), + summer: (top: (0.16, 0.60, 0.98), bottom: (0.70, 0.90, 1.00)), + autumn: (top: (0.33, 0.50, 0.90), bottom: (0.80, 0.88, 0.98)), + winter: (top: (0.64, 0.76, 0.86), bottom: (0.89, 0.93, 0.96)) + ) ), SkyKeyframe( event: .solarNoon, offset: 3, skyTop: RGBComponents(red: 0.353, green: 0.635, blue: 0.914), skyBottom: RGBComponents(red: 0.980, green: 0.929, blue: 0.831), - nightness: 0.0 + nightness: 0.0, + seasonal: daytimeColors( + spring: (top: (0.50, 0.68, 0.91), bottom: (0.98, 0.90, 0.86)), + summer: (top: (0.17, 0.57, 0.96), bottom: (0.88, 0.94, 0.90)), + autumn: (top: (0.32, 0.48, 0.87), bottom: (0.98, 0.88, 0.74)), + winter: (top: (0.62, 0.73, 0.84), bottom: (0.95, 0.92, 0.87)) + ) ), SkyKeyframe( event: .sunset, @@ -753,13 +821,12 @@ struct SkyPalette: Equatable { let daylight = day.daylight let (previous, next, ratio) = surroundingKeyframes(for: normalizedHour, in: daylight) - let baseSkyTop = previous.skyTop.mixed(with: next.skyTop, ratio: ratio) - let baseSkyBottom = previous.skyBottom.mixed(with: next.skyBottom, ratio: ratio) - // 季節の色をうっすら混ぜます。夏は青く、秋は暖かく、冬は白っぽくなります。 - // 隣り合う季節のあいだでは、それぞれの色を混ぜた空を日付に応じて混ぜ合わせます。 + // 隣り合う2つの季節の空をそれぞれ作り、日付に応じて混ぜ合わせます。 let blend = day.seasonBlend - let skyTop = seasonalSky(baseSkyTop, blend: blend, strengthScale: 1) - let skyBottom = seasonalSky(baseSkyBottom, blend: blend, strengthScale: horizonTintScale) + let earlierSky = skyColors(between: previous, and: next, ratio: ratio, season: blend.earlier) + let laterSky = skyColors(between: previous, and: next, ratio: ratio, season: blend.later) + let skyTop = earlierSky.top.mixed(with: laterSky.top, ratio: blend.ratio) + let skyBottom = earlierSky.bottom.mixed(with: laterSky.bottom, ratio: blend.ratio) let nightness = previous.nightness + (next.nightness - previous.nightness) * ratio // 外観指定はカードと操作部品に適用し、時刻による風景は維持します。 @@ -937,23 +1004,29 @@ struct SkyPalette: Equatable { return (last, last, 0) } - /// 季節の色を混ぜた空の色です。 + /// ある季節の、2つのキーフレームのあいだの空の色です。 /// - /// 隣り合う2つの季節の色をそれぞれ混ぜた空を作り、その2つを季節の割合で混ぜます。 - private static func seasonalSky( - _ base: RGBComponents, - blend: SeasonBlend, - strengthScale: Double - ) -> RGBComponents { - let earlier = base.mixed( - with: blend.earlier.tint, - ratio: blend.earlier.tintStrength * strengthScale - ) - let later = base.mixed( - with: blend.later.tint, - ratio: blend.later.tintStrength * strengthScale + /// 昼は季節ごとの空の色をそのまま使います。季節ごとの色を持たない時間帯は、 + /// 共通の空に季節の色をうっすら混ぜます。夏は青く、秋は暖かく、冬は白っぽくなります。 + /// 混ぜる強さもキーフレームのあいだで補間し、朝夕に急に切り替わらないようにします。 + private static func skyColors( + between previous: SkyKeyframe, + and next: SkyKeyframe, + ratio: Double, + season: Season + ) -> SkyColors { + let from = previous.colors(for: season) + let to = next.colors(for: season) + let tintStrength = season.tintStrength + * interpolate(from: previous.seasonTintWeight, to: next.seasonTintWeight, ratio: ratio) + return SkyColors( + top: from.top + .mixed(with: to.top, ratio: ratio) + .mixed(with: season.tint, ratio: tintStrength), + bottom: from.bottom + .mixed(with: to.bottom, ratio: ratio) + .mixed(with: season.tint, ratio: tintStrength * horizonTintScale) ) - return earlier.mixed(with: later, ratio: blend.ratio) } /// 数値を比率で補間します。 diff --git a/BusTimeAppTests/BusTimeAppTests.swift b/BusTimeAppTests/BusTimeAppTests.swift index 434bd0f..37774d4 100644 --- a/BusTimeAppTests/BusTimeAppTests.swift +++ b/BusTimeAppTests/BusTimeAppTests.swift @@ -1796,25 +1796,52 @@ struct BusTimeAppTests { func seasonsLookDifferentAtNoon() { // 同じ正午の空を季節どうしで比べ、どの組み合わせも見分けられる色差があることを確かめます。 // 色差はCIELABのΔE(CIE76)です。2.3前後が見分けられる最小の差で、10を超えると別の色に見えます。 + // 季節の色を一律に混ぜていたころは0.8〜8.4しかなく、春と冬はほぼ同じ色でした。 let threshold = 10.0 - withKnownIssue("季節ごとの空の基本色を設計し直すまでは、春・秋・冬の正午がほぼ同じ色です(#65)") { - for (index, first) in Season.allCases.enumerated() { - for second in Season.allCases.dropFirst(index + 1) { - let difference = skyColorDifference( - SkyPalette.at(hour: 12, season: first), - SkyPalette.at(hour: 12, season: second) - ) - #expect( - difference >= threshold, - "正午の\(first)と\(second)の空の色差が\(difference)でした" - ) - } + for (index, first) in Season.allCases.enumerated() { + for second in Season.allCases.dropFirst(index + 1) { + let difference = skyColorDifference( + SkyPalette.at(hour: 12, season: first), + SkyPalette.at(hour: 12, season: second) + ) + #expect( + difference >= threshold, + "正午の\(first)と\(second)の空の色差が\(difference)でした" + ) } } } - // MARK: - ショートカット(Siri) + @Test + func daytimeSkyShowsEachSeasonsCharacter() { + typealias RGBA = (r: Double, g: Double, b: Double, a: Double) + func noonSky(_ season: Season) -> (top: RGBA, bottom: RGBA) { + let palette = SkyPalette.at(hour: 12, season: season) + return (components(of: palette.skyColor(at: 0)), components(of: palette.skyColor(at: 1))) + } + func saturation(_ color: RGBA) -> Double { + let highest = max(color.r, color.g, color.b) + return highest > 0 ? (highest - min(color.r, color.g, color.b)) / highest : 0 + } + + // 夏は濃く高い青、秋は澄んだ青、春はかすんだ淡い空、冬は低く白っぽい空です。 + // 空の上端の鮮やかさが、この順に下がります。 + let order: [Season] = [.summer, .autumn, .spring, .winter] + for (vivid, pale) in zip(order, order.dropFirst()) { + #expect( + saturation(noonSky(vivid).top) > saturation(noonSky(pale).top), + "\(vivid)の空は\(pale)より鮮やかにします" + ) + } + // 冬の空がいちばん明るく白っぽくなります。 + for season in [Season.spring, .summer, .autumn] { + #expect(relativeLuminance(noonSky(.winter).top) > relativeLuminance(noonSky(season).top)) + } + // 春の地平線は桃色を帯びたかすみ、冬の地平線は冷たい白です。 + #expect(noonSky(.spring).bottom.r > noonSky(.spring).bottom.b) + #expect(noonSky(.winter).bottom.b > noonSky(.winter).bottom.r) + } @Test func shortcutAnswerNamesTheRouteAndTheNextDeparture() { diff --git a/README.md b/README.md index 25633e4..2298f8f 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,7 @@ - 0時、明け方、朝、昼、夕方、夜のキーフレーム間を連続補間し、空・水面・地面・カード・文字・アクセントを同じ時刻から生成します。 - 日の出・日の入りは、海浜幕張駅付近の緯度経度とその日の日付から計算します(NOAAの太陽位置の近似式)。夏至はおよそ4:25〜19:00、冬至は6:45〜16:30で、南中は経度と均時差により11:23〜11:54です。 +- 昼の空は季節ごとに彩度・明度・地平線のかすみを描き分けます。春はかすんだ淡い空、夏は濃く高い青、秋は澄んだ深い青、冬は低く白っぽい空です。同じ正午の空は、どの季節の組み合わせでもΔE 10以上離れます。 - 季節の色は月で切り替えず、各季節の代表日(4/15、7/16、10/16、1/15)で最も強く、隣の季節の代表日へ向けて日ごとになだらかに移します。5月末・8月末・11月末・2月末が2つの季節のちょうど中間です。 - 空のキーフレームは時計の時刻ではなく、日の出・南中・日の入りからの前後で持ちます。薄明の長さは季節であまり変わらないため、昼の長さだけが日付に応じて伸び縮みします。空の色、太陽・月の軌道、太陽と月の入れ替わり、街灯は同じ日の出・日の入り(`DaylightSchedule`)を共有し、空と天体の位置が食い違わないようにしています。季節と背景の時刻は、運行判定と同じ日本時間の暦とアプリ内の現在時刻(`AppDate`)で決めます。 - 空と海は色数を量子化し、ベイヤーディザと決定的な疑似乱数で、毎フレームちらつかないピクセル表現にしています。 @@ -1156,7 +1157,8 @@ UIテストでは、ホーム/時刻表の遷移、最大Dynamic Typeでの主 - `seasonOverrideIgnoresUnknownValues`: 不明な季節名や範囲外の日数を無視 - `skyChangesGraduallyFromDayToDay`: 隣り合う日の同じ時刻の空の色差(ΔE)が一年を通して2.0以下 - `seasonsBlendBetweenTheirRepresentativeDays`: 季節の色が代表日で最も強く、隣の季節へ連続して移る -- `seasonsLookDifferentAtNoon`: 同じ正午の空が季節どうしで見分けられる色差(ΔE)を持つ +- `seasonsLookDifferentAtNoon`: 同じ正午の空が季節どうしで見分けられる色差(ΔE 10以上)を持つ +- `daytimeSkyShowsEachSeasonsCharacter`: 正午の空の鮮やかさが夏・秋・春・冬の順に下がり、春の地平線は桃色のかすみ、冬は白く冷たい - `moonPhaseMatchesRealNewAndFullMoons`: 実日付の新月・満月との整合 - `inkSwitchesAtOnceInsteadOfFadingThroughGrey`: 文字色を灰色経由で補間しない - `cardSurfaceSwitchesTogetherWithTheInk`: Card面と文字色を同じ閾値で切替