SPB Git

Repository Public

make-background.swift 3.1 KB 42 lines swift

1// ORIX Docs2// File: design/dmg/make-background.swift3// Description: Draws the disk image background (660 × 420 pt, @1x and @2x): ORIX ink ground, drag-to-install arrow and instruction.4//              Usage: swift make-background.swift <output-directory>5//6// Author: Simon-Pierre Boucher7// Contact: contact@spboucher.ai8import AppKit910let out = URL(fileURLWithPath: CommandLine.arguments.count > 1 ? CommandLine.arguments[1] : ".")11let space = CGColorSpace(name: CGColorSpace.sRGB)!12func rgb(_ 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) }1314func draw(scale: CGFloat, name: String) {15    let w: CGFloat = 660, h: CGFloat = 42016    let c = CGContext(data: nil, width: Int(w * scale), height: Int(h * scale), bitsPerComponent: 8, bytesPerRow: 0, space: space, bitmapInfo: CGImageAlphaInfo.premultipliedLast.rawValue)!17    c.scaleBy(x: scale, y: scale)18    c.drawLinearGradient(CGGradient(colorsSpace: space, colors: [rgb(0x1B1F3B), rgb(0x0B0D1A)] as CFArray, locations: nil)!, start: CGPoint(x: 0, y: h), end: CGPoint(x: w, y: 0), options: [])19    c.drawRadialGradient(CGGradient(colorsSpace: space, colors: [rgb(0x4338CA, 0.55), rgb(0x4338CA, 0)] as CFArray, locations: nil)!,20                         startCenter: CGPoint(x: 120, y: h - 40), startRadius: 0, endCenter: CGPoint(x: 120, y: h - 40), endRadius: 420, options: [])21    // Arrow from the app (x 180) to Applications (x 480), at icon height (y from top 190).22    let y = h - 19023    c.setStrokeColor(rgb(0x8B7BFF)); c.setLineWidth(5); c.setLineCap(.round); c.setLineJoin(.round)24    c.move(to: CGPoint(x: 270, y: y)); c.addLine(to: CGPoint(x: 388, y: y))25    c.move(to: CGPoint(x: 370, y: y + 18)); c.addLine(to: CGPoint(x: 390, y: y)); c.addLine(to: CGPoint(x: 370, y: y - 18))26    c.strokePath()27    func text(_ s: String, size: CGFloat, weight: NSFont.Weight, color: CGColor, centerX: CGFloat, baseline: CGFloat, tracking: CGFloat = 0) {28        let attrs: [NSAttributedString.Key: Any] = [.font: NSFont.systemFont(ofSize: size, weight: weight), NSAttributedString.Key(kCTForegroundColorAttributeName as String): color, .kern: tracking]29        let line = CTLineCreateWithAttributedString(NSAttributedString(string: s, attributes: attrs))30        let lw = CGFloat(CTLineGetTypographicBounds(line, nil, nil, nil))31        c.textPosition = CGPoint(x: centerX - lw / 2, y: baseline); CTLineDraw(line, c)32    }33    text("ORIX DOCS", size: 13, weight: .semibold, color: rgb(0xA5ABF7), centerX: w / 2, baseline: h - 54, tracking: 3)34    text("Write Without Limits.", size: 24, weight: .bold, color: rgb(0xFFFFFF), centerX: w / 2, baseline: h - 90)35    text("Drag ORIX Docs to the Applications folder to install", size: 13, weight: .regular, color: rgb(0xFFFFFF, 0.72), centerX: w / 2, baseline: 56)36    let rep = NSBitmapImageRep(cgImage: c.makeImage()!)37    rep.size = NSSize(width: w, height: h)38    try! rep.representation(using: .png, properties: [:])!.write(to: out.appendingPathComponent(name))39}40draw(scale: 1, name: "background.png")41draw(scale: 2, name: "background@2x.png")42
Files main
Menu

Theme