Skip to content

Instantly share code, notes, and snippets.

View Priva28's full-sized avatar
🪴

Christian Privitelli Priva28

🪴
View GitHub Profile
@FredrikSjoberg
FredrikSjoberg / RGBtoHSV.swift
Last active September 24, 2024 10:06
Color space conversion between RGB and HSV
// https://www.cs.rit.edu/~ncs/color/t_convert.html
struct RGB {
// Percent
let r: Float // [0,1]
let g: Float // [0,1]
let b: Float // [0,1]
static func hsv(r: Float, g: Float, b: Float) -> HSV {
let min = r < g ? (r < b ? r : b) : (g < b ? g : b)
let max = r > g ? (r > b ? r : b) : (g > b ? g : b)