SPB Git

Repository Public

make-background.swift 2.7 KB 34 lines swift

1// Draws the DMG window background (660×420 pt, rendered at 2x). Usage: swift make-background.swift <out-dir>2import AppKit3let out = CommandLine.arguments.count > 1 ? CommandLine.arguments[1] : "."4let W = 1320, H = 8405let space = CGColorSpace(name: CGColorSpace.sRGB)!6let ctx = CGContext(data: nil, width: W, height: H, bitsPerComponent: 8, bytesPerRow: 0, space: space, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue)!7func c(_ hex: UInt32, _ a: CGFloat = 1) -> CGColor { CGColor(srgbRed: CGFloat((hex >> 16) & 0xFF) / 255, green: CGFloat((hex >> 8) & 0xFF) / 255, blue: CGFloat(hex & 0xFF) / 255, alpha: a) }8let g = CGGradient(colorsSpace: space, colors: [c(0x16233F), c(0x0B0F1E)] as CFArray, locations: [0, 1])!9ctx.drawLinearGradient(g, start: CGPoint(x: 0, y: H), end: CGPoint(x: 0, y: 0), options: [])10let glow = CGGradient(colorsSpace: space, colors: [c(0x1E6A8A, 0.55), c(0x1E6A8A, 0)] as CFArray, locations: [0, 1])!11ctx.drawRadialGradient(glow, startCenter: CGPoint(x: 300, y: 760), startRadius: 0, endCenter: CGPoint(x: 300, y: 760), endRadius: 720, options: [])12// faint sheet grid13ctx.setStrokeColor(c(0xFFFFFF, 0.035)); ctx.setLineWidth(2)14for x in stride(from: 0, through: W, by: 110) { ctx.move(to: CGPoint(x: x, y: 0)); ctx.addLine(to: CGPoint(x: x, y: H)) }15for y in stride(from: 0, through: H, by: 56) { ctx.move(to: CGPoint(x: 0, y: y)); ctx.addLine(to: CGPoint(x: W, y: y)) }16ctx.strokePath()17// arrow between the icon positions (170,205) and (490,205) in points, y measured from the top18let y = CGFloat(H) - 205 * 219ctx.setStrokeColor(c(0x22D3EE, 0.9)); ctx.setLineWidth(7); ctx.setLineCap(.round); ctx.setLineJoin(.round)20ctx.move(to: CGPoint(x: 560, y: y)); ctx.addLine(to: CGPoint(x: 760, y: y)); ctx.strokePath()21ctx.move(to: CGPoint(x: 728, y: y + 30)); ctx.addLine(to: CGPoint(x: 762, y: y)); ctx.addLine(to: CGPoint(x: 728, y: y - 30)); ctx.strokePath()22NSGraphicsContext.current = NSGraphicsContext(cgContext: ctx, flipped: false)23func text(_ s: String, _ size: CGFloat, _ weight: NSFont.Weight, _ color: NSColor, _ yy: CGFloat) {24    let a = NSAttributedString(string: s, attributes: [.font: NSFont.systemFont(ofSize: size, weight: weight), .foregroundColor: color])25    a.draw(at: CGPoint(x: (CGFloat(W) - a.size().width) / 2, y: yy))26}27text("ORIX Sheet", 56, .bold, .white, 690)28text("Beyond Spreadsheets.", 26, .medium, NSColor(srgbRed: 0.13, green: 0.83, blue: 0.93, alpha: 1), 646)29text("Drag ORIX Sheet to the Applications folder", 26, .regular, NSColor(white: 1, alpha: 0.72), 96)30let rep = NSBitmapImageRep(cgImage: ctx.makeImage()!)31rep.size = NSSize(width: W / 2, height: H / 2)32try! rep.representation(using: .png, properties: [:])!.write(to: URL(fileURLWithPath: "\(out)/background.png"))33print("wrote \(out)/background.png")34
Files main
Menu

Theme