xM: improve the bundle icon a bit

This commit is contained in:
Přemysl Eric Janouch 2023-09-04 06:11:58 +02:00
parent 9e4692bb09
commit 13d2ff115b
Signed by: p
GPG Key ID: A0420B94F92B9493
1 changed files with 13 additions and 21 deletions

View File

@ -1,4 +1,4 @@
// gen-icon.awk: generate a program icon for xM in the Apple icon format // gen-icon.swift: generate a program icon for xM in the Apple icon format
// //
// Copyright (c) 2023, Přemysl Eric Janouch <p@janouch.name> // Copyright (c) 2023, Přemysl Eric Janouch <p@janouch.name>
// SPDX-License-Identifier: 0BSD // SPDX-License-Identifier: 0BSD
@ -10,24 +10,17 @@ import Foundation
import ImageIO import ImageIO
import UniformTypeIdentifiers import UniformTypeIdentifiers
// XXX: Not even AppKit provides real superelliptic squircles; screw it. // Apple uses something that's close to a "quintic superellipse" in their icons,
func drawSquircle(context: CGContext, bounds: CGRect, radius: CGFloat) { // but doesn't quite match. Either way, it looks better than rounded rectangles.
context.move(to: CGPointMake(bounds.minX, bounds.maxY - radius)) func addSquircle(context: CGContext, bounds: CGRect) {
context.addArc( context.move(to: CGPoint(x: bounds.maxX, y: bounds.midY))
center: CGPointMake(bounds.minX + radius, bounds.maxY - radius), for theta in stride(from: 0.0, to: .pi * 2, by: .pi / 1e4) {
radius: radius, startAngle: .pi, endAngle: .pi / 2, clockwise: true) let x = pow(abs(cos(theta)), 2 / 5.0) * bounds.width / 2
context.addLine(to: CGPointMake(bounds.maxX - radius, bounds.maxY)) * CGFloat(signOf: cos(theta), magnitudeOf: 1) + bounds.midX
context.addArc( let y = pow(abs(sin(theta)), 2 / 5.0) * bounds.height / 2
center: CGPointMake(bounds.maxX - radius, bounds.maxY - radius), * CGFloat(signOf: sin(theta), magnitudeOf: 1) + bounds.midY
radius: radius, startAngle: .pi / 2, endAngle: 0, clockwise: true) context.addLine(to: CGPoint(x: x, y: y))
context.addLine(to: CGPointMake(bounds.maxX, bounds.maxY - radius)) }
context.addArc(
center: CGPointMake(bounds.maxX - radius, bounds.minY + radius),
radius: radius, startAngle: 0, endAngle: .pi / -2, clockwise: true)
context.addLine(to: CGPointMake(bounds.minX + radius, bounds.minY))
context.addArc(
center: CGPointMake(bounds.minX + radius, bounds.minY + radius),
radius: radius, startAngle: .pi / -2, endAngle: .pi, clockwise: true)
context.closePath() context.closePath()
} }
@ -42,8 +35,7 @@ func drawIcon(scale: CGFloat) -> CGImage? {
context.scaleBy(x: scale, y: scale) context.scaleBy(x: scale, y: scale)
let bounds = CGRectMake(100, 100, size.width - 200, size.height - 200) let bounds = CGRectMake(100, 100, size.width - 200, size.height - 200)
// The radius was something like size.{width,height}/6.4, at least for iOS. addSquircle(context: context, bounds: bounds)
drawSquircle(context: context, bounds: bounds, radius: 180)
let squircle = context.path! let squircle = context.path!
// Gradients don't draw shadows, so draw it separately. // Gradients don't draw shadows, so draw it separately.