Skip to content

Commit

Permalink
Improve Ice Bar color algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanbaird committed Jul 5, 2024
1 parent 2f592fb commit e9a9155
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions Ice/IceBar/IceBarColorManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,18 @@ class IceBarColorManager: ObservableObject {
return
}

let percentage = ((frame.midX - screen.frame.origin.x) / screen.frame.width).clamped(to: 0...1)
let bounds = CGRect(
x: frame.origin.x + (frame.width * percentage),
y: 0,
width: 0,
height: 1
).insetBy(dx: -10, dy: 0)
let imageBounds = CGRect(x: 0, y: 0, width: windowImage.width, height: windowImage.height)
let insetScreenFrame = screen.frame.insetBy(dx: frame.width / 2, dy: 0)
let percentage = ((frame.midX - insetScreenFrame.minX) / insetScreenFrame.width).clamped(to: 0...1)
let cropRect = CGRect(x: imageBounds.width * percentage, y: 0, width: 0, height: 1)
.insetBy(dx: -50, dy: 0)
.intersection(imageBounds)

guard
let croppedImage = windowImage.cropping(to: bounds),
let croppedImage = windowImage.cropping(to: cropRect),
let averageColor = croppedImage.averageColor(resolution: .low)
else {
colorInfo = nil
return
}

Expand Down

0 comments on commit e9a9155

Please sign in to comment.