-
Notifications
You must be signed in to change notification settings - Fork 0
hugo/feature/Add Gradient class #560
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 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
