Conversation
HPezz
commented
Dec 22, 2023
- 🧑💻 (RobotKit): Extend UIColor with toHsv() function
- ♻️ (RobotKit): Update Robot.Color to future Gradient struct
- ✨ (RobotKit): Add Robot.Gradient struct
- 🐛 (GEK): Add reinforcer duration
- ♻️ (GEK): Refactor Pairing breathe animation with Gradient
2e6c295 to
908d583
Compare
908d583 to
450a2c8
Compare
|
ladislas
left a comment
There was a problem hiding this comment.
LGTM 👍 quelques questions techniques :)
| public var robotUiColor: UIColor { | ||
| UIColor( | ||
| red: Double(self.robotRGB[0]) / 255.0, | ||
| green: Double(self.robotRGB[1]) / 255.0, | ||
| blue: Double(self.robotRGB[2]) / 255.0, | ||
| alpha: 1.0 | ||
| ) | ||
| } | ||
|
|
||
| public var screenUiColor: UIColor { | ||
| UIColor( | ||
| red: Double(self.screenRGB[0]) / 255.0, | ||
| green: Double(self.screenRGB[1]) / 255.0, | ||
| blue: Double(self.screenRGB[2]) / 255.0, | ||
| alpha: 1.0 | ||
| ) | ||
| } |
There was a problem hiding this comment.
pourquoi tu as besoin de passer par UIColor? pourquoi pas une simple struct?
| public func color(at position: Float) -> Robot.Color { | ||
| let positionClamped = max(min(position, 1), 0) | ||
|
|
||
| let scaledIndex = positionClamped * Float(self.gradientColors.count - 1) | ||
| let firstIndex = Int(scaledIndex) | ||
| let secondIndex = min(firstIndex + 1, gradientColors.count - 1) | ||
| let fraction = CGFloat(scaledIndex - Float(firstIndex)) | ||
|
|
||
| let firstColor = self.gradientColors[firstIndex] | ||
| let secondColor = self.gradientColors[secondIndex] | ||
|
|
||
| let (h1, s1, v1) = firstColor.robotUiColor.toHSV() | ||
| let (h2, s2, v2) = secondColor.robotUiColor.toHSV() | ||
|
|
||
| let h = self.interpolateHue(from: h1, to: h2, fraction: fraction) | ||
| let s = self.interpolate(from: s1, to: s2, fraction: fraction) | ||
| let v = self.interpolate(from: v1, to: v2, fraction: fraction) | ||
|
|
||
| let uiColor = UIColor(hue: h, saturation: s, brightness: v, alpha: 1) | ||
|
|
||
| let r = UInt8(max(min(uiColor.cgColor.components![0] * 255.0, 255), 0)) | ||
| let g = UInt8(max(min(uiColor.cgColor.components![1] * 255.0, 255), 0)) | ||
| let b = UInt8(max(min(uiColor.cgColor.components![2] * 255.0, 255), 0)) | ||
|
|
||
| return Robot.Color(red: r, green: g, blue: b) | ||
| } |
There was a problem hiding this comment.
par curiosité, cette formule elle vient d'où? c'est intéressant de mettre en commentaire la source de l'explication scientifique/mathématiques du calcul
| public init(fromColors colors: Color...) { | ||
| self.gradientColors = colors | ||
| } |
There was a problem hiding this comment.
j'ai un "petit" soucis avec ça : c'est que si tu mets + de 2 couleurs, tu pars du principe qu'elles sont toutes équidistante les unes des autres.
dans Illustrator, tu peux faire varier la distance entre 2 couleurs.
dans notre cas ça peut être très pratique pour "accélérer/raccourcir" les zones dans lesquelles les variations sont faibles (ou faiblement perçues) et "ralentir/allonger" des zones où la variation est plus importante
There was a problem hiding this comment.
une manière simple est d'avoir un autre init qui te permet d'associer couleur et position
| public var robotUiColor: UIColor { | ||
| UIColor( | ||
| red: Double(self.robotRGB[0]) / 255.0, | ||
| green: Double(self.robotRGB[1]) / 255.0, | ||
| blue: Double(self.robotRGB[2]) / 255.0, | ||
| alpha: 1.0 | ||
| ) | ||
| } | ||
|
|
||
| public var screenUiColor: UIColor { | ||
| UIColor( | ||
| red: Double(self.screenRGB[0]) / 255.0, | ||
| green: Double(self.screenRGB[1]) / 255.0, | ||
| blue: Double(self.screenRGB[2]) / 255.0, | ||
| alpha: 1.0 | ||
| ) | ||
| } |
There was a problem hiding this comment.
| public var robotUiColor: UIColor { | |
| UIColor( | |
| red: Double(self.robotRGB[0]) / 255.0, | |
| green: Double(self.robotRGB[1]) / 255.0, | |
| blue: Double(self.robotRGB[2]) / 255.0, | |
| alpha: 1.0 | |
| ) | |
| } | |
| public var screenUiColor: UIColor { | |
| UIColor( | |
| red: Double(self.screenRGB[0]) / 255.0, | |
| green: Double(self.screenRGB[1]) / 255.0, | |
| blue: Double(self.screenRGB[2]) / 255.0, | |
| alpha: 1.0 | |
| ) | |
| } | |
| public var robotUIColor: UIColor { | |
| UIColor( | |
| red: Double(self.robotRGB[0]) / 255.0, | |
| green: Double(self.robotRGB[1]) / 255.0, | |
| blue: Double(self.robotRGB[2]) / 255.0, | |
| alpha: 1.0 | |
| ) | |
| } | |
| public var screenUIColor: UIColor { | |
| UIColor( | |
| red: Double(self.screenRGB[0]) / 255.0, | |
| green: Double(self.screenRGB[1]) / 255.0, | |
| blue: Double(self.screenRGB[2]) / 255.0, | |
| alpha: 1.0 | |
| ) | |
| } |
1d4a80e to
a25305d
Compare
