sprag-cli 3.132.0 → 3.134.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/mac/SpragBar.swift +742 -79
- package/package.json +1 -1
package/mac/SpragBar.swift
CHANGED
|
@@ -270,6 +270,38 @@ func jump(to s: Session) {
|
|
|
270
270
|
}
|
|
271
271
|
owningApp(s.pid)?.activate(options: [.activateAllWindows])
|
|
272
272
|
}
|
|
273
|
+
/** The folder a Claude session worked in, read from its transcript (`<config>/projects/<folder>/<id>.jsonl`, whose lines carry `cwd`). */
|
|
274
|
+
func sessionCwd(_ sid: String) -> String? {
|
|
275
|
+
let base = ProcessInfo.processInfo.environment["CLAUDE_CONFIG_DIR"].map { ($0 as NSString).expandingTildeInPath } ?? NSHomeDirectory() + "/.claude"
|
|
276
|
+
let root = base + "/projects", fm = FileManager.default
|
|
277
|
+
for dir in (try? fm.contentsOfDirectory(atPath: root)) ?? [] {
|
|
278
|
+
let file = root + "/" + dir + "/" + sid + ".jsonl"
|
|
279
|
+
guard let h = FileHandle(forReadingAtPath: file) else { continue }
|
|
280
|
+
defer { try? h.close() }
|
|
281
|
+
let head = h.readData(ofLength: 256 * 1024)
|
|
282
|
+
for line in head.split(separator: UInt8(ascii: "\n")).prefix(200) {
|
|
283
|
+
if let o = try? JSONSerialization.jsonObject(with: Data(line)) as? [String: Any], let c = o["cwd"] as? String, fm.fileExists(atPath: c) { return c }
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
return nil
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Reopen an ended Claude session in a new terminal window, in the folder it worked in, so a person can read what it was
|
|
290
|
+
* doing before deciding whether to stop what it left running. Once it is back, its leftovers count as that session's again.
|
|
291
|
+
*/
|
|
292
|
+
@discardableResult func resumeSession(_ sid: String, fallbackDir: String?) -> Bool {
|
|
293
|
+
guard !sid.isEmpty, sid.count <= 64, sid.allSatisfy({ $0.isHexDigit || $0 == "-" }) else { return false }
|
|
294
|
+
let dir = sessionCwd(sid) ?? fallbackDir ?? NSHomeDirectory()
|
|
295
|
+
let q = "'" + dir.replacingOccurrences(of: "'", with: "'\\''") + "'"
|
|
296
|
+
// a login, interactive shell so PATH finds claude; the shell stays open after claude exits
|
|
297
|
+
let script = "#!/bin/zsh\ncd \(q) || exit 1\nexec /bin/zsh -lic 'claude --resume \(sid); exec /bin/zsh -il'\n"
|
|
298
|
+
let url = FileManager.default.temporaryDirectory.appendingPathComponent("sprag-resume-\(sid).command")
|
|
299
|
+
do {
|
|
300
|
+
try script.write(to: url, atomically: true, encoding: .utf8)
|
|
301
|
+
try FileManager.default.setAttributes([.posixPermissions: 0o700], ofItemAtPath: url.path)
|
|
302
|
+
} catch { return false }
|
|
303
|
+
return NSWorkspace.shared.open(url)
|
|
304
|
+
}
|
|
273
305
|
/** A name a person recognises: the app for anything inside an .app bundle, else the executable's file name. */
|
|
274
306
|
func appName(_ pid: Int32, _ fallback: String) -> String {
|
|
275
307
|
var buf = [CChar](repeating: 0, count: 4096)
|
|
@@ -448,6 +480,7 @@ final class Model: ObservableObject {
|
|
|
448
480
|
var leftoverPids: [String: [(pid: Int32, start: UInt64)]] = [:] // each leftover line: its processes, with the start time that identifies them
|
|
449
481
|
var leftoverShared: Set<String> = [] // leftover lines that are apps, virtual machines or databases: never part of a clean-up
|
|
450
482
|
var leftoverWhere: [String: String] = [:] // each leftover line: the folder it runs in, which names the project its session worked on
|
|
483
|
+
var leftoverSession: [String: String] = [:] // each leftover line: the id of the ended Claude session that started it
|
|
451
484
|
/** The leftover lines that hold an open connection right now. Read when the clean-up choices open, not on every poll. */
|
|
452
485
|
func leftoverBusy(_ labels: [String]) -> Set<String> {
|
|
453
486
|
Set(labels.filter { label in (leftoverPids[label] ?? []).contains { hasOpenConnection($0.pid) } })
|
|
@@ -516,6 +549,7 @@ final class Model: ObservableObject {
|
|
|
516
549
|
var cls: [Int32: Cls] = [:], nameAs: [Int32: Proc] = [:], kids: [Int32: [Int32]] = [:]
|
|
517
550
|
for p in all.values { kids[p.ppid, default: []].append(p.pid) }
|
|
518
551
|
let home = NSHomeDirectory()
|
|
552
|
+
var leftSid: [Int32: String] = [:] // top of a leftover tree: the ended session that started it
|
|
519
553
|
for r in rows where r.owner == nil && cls[r.top.pid] == nil {
|
|
520
554
|
let own = origin(r.top)
|
|
521
555
|
var sid = own.sid, cpid = own.cpid
|
|
@@ -527,7 +561,7 @@ final class Model: ObservableObject {
|
|
|
527
561
|
let here = sessions.filter { $0.cwd == dir }
|
|
528
562
|
if here.count == 1 { live = here[0].pid }
|
|
529
563
|
}
|
|
530
|
-
if let o = live { cls[r.top.pid] = .session(o) } else { cls[r.top.pid] = (sid != nil || cpid != nil) ? .left : .other }
|
|
564
|
+
if let o = live { cls[r.top.pid] = .session(o) } else { cls[r.top.pid] = (sid != nil || cpid != nil) ? .left : .other; if let s = sid { leftSid[r.top.pid] = s } }
|
|
531
565
|
}
|
|
532
566
|
// 3. a helper the system started on a program's behalf (a virtual machine, an XPC service) goes where that program went
|
|
533
567
|
if let responsible = RESPONSIBLE {
|
|
@@ -536,11 +570,11 @@ final class Model: ObservableObject {
|
|
|
536
570
|
let r = responsible(top)
|
|
537
571
|
guard r > 1, r != top else { continue }
|
|
538
572
|
if let o = treeOwner[r] { cls[top] = .session(Int(o)); nameAs[top] = all[r] }
|
|
539
|
-
else if let t = topOf[r], t != top, let c2 = cls[t] { if case .other = c2 { continue }; cls[top] = c2; nameAs[top] = all[t] }
|
|
573
|
+
else if let t = topOf[r], t != top, let c2 = cls[t] { if case .other = c2 { continue }; cls[top] = c2; nameAs[top] = all[t]; if let s = leftSid[t] { leftSid[top] = s } }
|
|
540
574
|
}
|
|
541
575
|
}
|
|
542
576
|
var use: [Int: Usage] = [:], left = Load(), leftBy: [String: Load] = [:], otherBy: [String: Load] = [:], owners: [Int32: Int] = [:], labels: [Int32: String] = [:]
|
|
543
|
-
var leftProcs: [String: [(pid: Int32, start: UInt64)]] = [:], shared: Set<String> = [], leftWhere: [String: String] = [:]
|
|
577
|
+
var leftProcs: [String: [(pid: Int32, start: UInt64)]] = [:], shared: Set<String> = [], leftWhere: [String: String] = [:], leftSession: [String: String] = [:]
|
|
544
578
|
let nowSec = UInt64(now)
|
|
545
579
|
for r in rows {
|
|
546
580
|
if let o = r.owner {
|
|
@@ -556,11 +590,12 @@ final class Model: ObservableObject {
|
|
|
556
590
|
left.add(r.cpu, r.p.memMb); leftBy[label, default: Load()].add(r.cpu, r.p.memMb); owners[r.p.pid] = -1
|
|
557
591
|
leftProcs[label, default: []].append((pid: r.p.pid, start: r.p.start))
|
|
558
592
|
if leftWhere[label] == nil, let c = procCwd(r.p.pid), c.count > 1, c != NSHomeDirectory() { leftWhere[label] = (c as NSString).lastPathComponent }
|
|
593
|
+
if leftSession[label] == nil, let s = leftSid[r.top.pid] { leftSession[label] = s }
|
|
559
594
|
if !shared.contains(label), isSharedService(nameAs[r.top.pid] ?? r.top) || isSharedService(r.top) { shared.insert(label) }
|
|
560
595
|
case .other: otherBy[label, default: Load()].add(r.cpu, r.p.memMb)
|
|
561
596
|
}
|
|
562
597
|
}
|
|
563
|
-
ownerOf = owners; labelOf = labels; leftoverPids = leftProcs; leftoverShared = shared; leftoverWhere = leftWhere
|
|
598
|
+
ownerOf = owners; labelOf = labels; leftoverPids = leftProcs; leftoverShared = shared; leftoverWhere = leftWhere; leftoverSession = leftSession
|
|
564
599
|
cpuSeen = all.mapValues { $0.cpuNs }; cpuSeenAt = now; if span > 0 { censusReady = true }
|
|
565
600
|
origins = origins.filter { all[$0.key] != nil }; appNames = appNames.filter { all[$0.key] != nil }; inherited = inherited.filter { all[$0.key] != nil }
|
|
566
601
|
let list: ([String: Load]) -> [AppLoad] = { d in d.map { AppLoad(id: $0.key, name: $0.key, cpu: $0.value.cpu, mem: $0.value.mem, n: $0.value.n) }.sorted { $0.mem > $1.mem } }
|
|
@@ -836,74 +871,671 @@ final class RuleBook: ObservableObject {
|
|
|
836
871
|
}
|
|
837
872
|
}
|
|
838
873
|
|
|
839
|
-
// ---------- the runner:
|
|
840
|
-
|
|
841
|
-
//
|
|
842
|
-
|
|
843
|
-
Pose(fn: (70, 80), ff: (54, 66), hn: (-66, -80), hf: (-50, -64), lift: 1.0, stretch: 0.9), // flight, stretched out
|
|
844
|
-
Pose(fn: (38, 18), ff: (54, 42), hn: (-56, -82), hf: (-42, -68), lift: 0.3, stretch: 0.6), // front legs land
|
|
845
|
-
Pose(fn: (2, -14), ff: (20, 6), hn: (-24, -70), hf: (-38, -80), lift: -0.5, stretch: 0.1), // weight over the front
|
|
846
|
-
Pose(fn: (-28, -52), ff: (-12, -34), hn: (34, 10), hf: (20, -6), lift: -0.3, stretch: -0.8), // gathered, hind legs reach under
|
|
847
|
-
Pose(fn: (16, -52), ff: (34, -32), hn: (14, 0), hf: (0, -14), lift: 0.2, stretch: -0.4), // hind legs carry
|
|
848
|
-
Pose(fn: (56, 26), ff: (66, 46), hn: (-30, -40), hf: (-44, -56), lift: 0.7, stretch: 0.4), // push off
|
|
849
|
-
]
|
|
850
|
-
let STAND = Pose(fn: (4, -2), ff: (-7, 3), hn: (-9, 6), hf: (5, 12), lift: 0, stretch: 0)
|
|
874
|
+
// ---------- the runner: the member's town animal, drawn in code as a template image ----------
|
|
875
|
+
// Thirty species and the ghost, one per grade of Sprag Town (GRADES in site/assets/scene/office-scene.js). They share a
|
|
876
|
+
// whole-body gallop (the spine gathers and stretches, the body pitches and bounces, the tail trails) in a three-quarter
|
|
877
|
+
// view with two eyes; birds and the dragon fly, the frog hops, the duck and chick walk, the ghost floats.
|
|
851
878
|
let RUNNER_SCALE: CGFloat = 0.9
|
|
852
|
-
|
|
879
|
+
/** The species to draw: the member's town grade; without one (no team, nothing uploaded) the ghost. */
|
|
880
|
+
func runnerSpecies(_ grade: String?) -> Sp { SPECIES.first { $0.id == grade } ?? SPECIES.first { $0.id == "ghost" }! }
|
|
881
|
+
struct Key { let flex, pitch, lift: Double; let fn, ff, hn, hf: (Double, Double) }
|
|
882
|
+
// flex: +1 stretched out, -1 gathered (back arched). pitch: degrees, + nose up. lift: units above the standing height.
|
|
883
|
+
let GAL: [Key] = [
|
|
884
|
+
Key(flex: 1.0, pitch: 0, lift: 1.9, fn: (72, 84), ff: (60, 74), hn: (-74, -88), hf: (-60, -78)), // flight, stretched
|
|
885
|
+
Key(flex: 0.55, pitch: -7, lift: 0.7, fn: (36, 14), ff: (52, 36), hn: (-62, -84), hf: (-48, -72)), // front lands
|
|
886
|
+
Key(flex: 0.0, pitch: -11, lift: -0.4, fn: (2, -16), ff: (20, 4), hn: (-26, -62), hf: (-40, -76)), // weight over the front
|
|
887
|
+
Key(flex: -0.6, pitch: -5, lift: 0.3, fn: (-30, -58), ff: (-16, -44), hn: (24, 4), hf: (8, -14)), // front pushes, hind swing under
|
|
888
|
+
Key(flex: -1.0, pitch: 3, lift: 1.4, fn: (-44, -88), ff: (-30, -76), hn: (52, 30), hf: (40, 16)), // gathered flight
|
|
889
|
+
Key(flex: -0.55, pitch: 9, lift: 0.3, fn: (8, -50), ff: (24, -30), hn: (30, 8), hf: (16, -8)), // hind lands
|
|
890
|
+
Key(flex: 0.0, pitch: 11, lift: -0.3, fn: (44, 18), ff: (56, 34), hn: (0, -14), hf: (-16, -30)), // hind carry
|
|
891
|
+
Key(flex: 0.6, pitch: 6, lift: 0.9, fn: (66, 58), ff: (62, 64), hn: (-44, -60), hf: (-56, -70)), // push off
|
|
892
|
+
]
|
|
893
|
+
let STAND2 = Key(flex: 0, pitch: 0, lift: 0, fn: (4, -2), ff: (-6, 3), hn: (-8, 6), hf: (5, 12))
|
|
894
|
+
|
|
895
|
+
enum Ear { case pricked, round, long, cat, tiny, floppy, side, mouse, horse, sheep, pig, none }
|
|
896
|
+
enum Tail { case curl, long, bushy, stub, tuft, thin, curly, ringed, squirrel, thinLong, hang, flow, wag, short, monkey, rope, none }
|
|
897
|
+
struct Sp {
|
|
898
|
+
let id: String, label: String
|
|
899
|
+
var ear: Ear = .pricked, tail: Tail = .long
|
|
900
|
+
var len = 9.6, chest = 3.4, hip = 3.0 // spine length, torso radii
|
|
901
|
+
var legF = 7.4, legH = 7.6 // leg lengths
|
|
902
|
+
var head = 2.9, snout = 3.0, snoutH = 1.0 // head radius, muzzle length and depth
|
|
903
|
+
var neckX = 3.6, neckY = 4.4 // head offset from the shoulder
|
|
904
|
+
var flexAmp = 1.0, liftAmp = 1.0, pitchAmp = 1.0
|
|
905
|
+
var mane = false, legW = 1.0, waddle = false, fly = 0, hump = false, eyeK = 1.0, x: Set<String> = [], kind = 0, eyeDx: Double = 0
|
|
906
|
+
}
|
|
907
|
+
let SPECIES: [Sp] = [
|
|
908
|
+
Sp(id: "husky", label: "허스키", ear: .pricked, tail: .curl),
|
|
909
|
+
Sp(id: "cat", label: "고양이", ear: .cat, tail: .long, len: 10.4, chest: 3.0, hip: 2.8, legF: 7.0, legH: 7.4, head: 2.7, snout: 1.2, snoutH: 1.4, neckX: 3.2, neckY: 4.0, flexAmp: 1.25, liftAmp: 1.15, pitchAmp: 1.1, legW: 0.9),
|
|
910
|
+
Sp(id: "fox", label: "여우", ear: .pricked, tail: .bushy, len: 10.0, chest: 3.1, hip: 2.8, legF: 7.0, legH: 7.2, head: 2.6, snout: 3.6, snoutH: 0.8, flexAmp: 1.1, legW: 0.9),
|
|
911
|
+
Sp(id: "cheetah", label: "치타", ear: .round, tail: .long, len: 11.4, chest: 3.0, hip: 2.5, legF: 8.2, legH: 8.4, head: 2.3, snout: 1.4, snoutH: 1.2, neckX: 3.0, neckY: 3.4, flexAmp: 1.45, liftAmp: 1.1, pitchAmp: 1.0, legW: 0.85),
|
|
912
|
+
Sp(id: "lion", label: "사자", ear: .round, tail: .tuft, len: 10.6, chest: 3.8, hip: 3.0, legF: 7.4, legH: 7.6, head: 2.5, snout: 1.8, snoutH: 1.6, flexAmp: 0.9, liftAmp: 0.9, mane: true, legW: 1.1),
|
|
913
|
+
Sp(id: "rabbit", label: "토끼", ear: .long, tail: .stub, len: 8.4, chest: 3.0, hip: 3.6, legF: 5.0, legH: 8.0, head: 2.7, snout: 1.0, snoutH: 1.6, neckX: 3.0, neckY: 3.6, flexAmp: 1.4, liftAmp: 1.5, pitchAmp: 1.6, legW: 0.95),
|
|
914
|
+
Sp(id: "bear", label: "곰", ear: .round, tail: .stub, len: 12.6, chest: 3.5, hip: 3.3, legF: 10.0, legH: 10.0, head: 2.5, snout: 3.2, snoutH: 1.3, neckX: 4.4, neckY: 0.9, flexAmp: 0.6, liftAmp: 0.6, pitchAmp: 0.9, legW: 1.5, hump: true, eyeK: 0.85),
|
|
915
|
+
Sp(id: "penguin", label: "펭귄", waddle: true),
|
|
916
|
+
Sp(id: "eagle", label: "독수리", fly: 1),
|
|
917
|
+
Sp(id: "owl", label: "부엉이", fly: 2),
|
|
918
|
+
Sp(id: "dragon", label: "용", fly: 3),
|
|
919
|
+
Sp(id: "unicorn", label: "유니콘", ear: .horse, tail: .flow, len: 11.0, chest: 3.1, hip: 2.9, legF: 9.2, legH: 9.2, head: 2.2, snout: 3.2, snoutH: 1.2, neckX: 4.2, neckY: 4.2, flexAmp: 1.0, liftAmp: 1.1, legW: 0.95, x: ["horn", "neckmane", "wings"]),
|
|
920
|
+
Sp(id: "tiger", label: "호랑이", ear: .round, tail: .long, len: 11.0, chest: 3.6, hip: 3.1, legF: 7.6, legH: 7.8, head: 2.6, snout: 1.7, snoutH: 1.5, flexAmp: 1.1, legW: 1.1, x: ["stripes"]),
|
|
921
|
+
Sp(id: "wolf", label: "늑대", ear: .pricked, tail: .hang, len: 10.8, chest: 3.3, hip: 2.8, legF: 8.4, legH: 8.6, head: 2.6, snout: 3.6, snoutH: 0.95, flexAmp: 1.15, legW: 0.95),
|
|
922
|
+
Sp(id: "panda", label: "판다", ear: .round, tail: .stub, len: 9.6, chest: 4.0, hip: 3.8, legF: 6.6, legH: 6.6, head: 3.0, snout: 1.2, snoutH: 1.6, neckX: 3.4, neckY: 2.8, flexAmp: 0.6, liftAmp: 0.6, pitchAmp: 1.2, legW: 1.4, x: ["panda"]),
|
|
923
|
+
Sp(id: "koala", label: "코알라", ear: .side, tail: .none, len: 8.6, chest: 3.6, hip: 3.6, legF: 6.0, legH: 6.0, head: 3.1, snout: 0, snoutH: 1.0, neckX: 3.2, neckY: 3.2, flexAmp: 0.7, liftAmp: 0.8, legW: 1.3, x: ["koalanose"]),
|
|
924
|
+
Sp(id: "raccoon", label: "너구리", ear: .cat, tail: .ringed, len: 9.6, chest: 3.1, hip: 3.1, legF: 6.4, legH: 6.6, head: 2.6, snout: 2.4, snoutH: 0.9, flexAmp: 1.0, legW: 1.0),
|
|
925
|
+
Sp(id: "dog", label: "강아지", ear: .floppy, tail: .wag, len: 9.0, chest: 3.2, hip: 2.9, legF: 6.8, legH: 7.0, head: 2.8, snout: 2.9, snoutH: 1.2, flexAmp: 1.0, liftAmp: 1.1, legW: 1.0),
|
|
926
|
+
Sp(id: "monkey", label: "원숭이", ear: .side, tail: .monkey, len: 9.0, chest: 3.0, hip: 2.8, legF: 8.6, legH: 7.4, head: 2.8, snout: 1.3, snoutH: 1.5, flexAmp: 1.1, liftAmp: 1.2, legW: 0.95),
|
|
927
|
+
Sp(id: "deer", label: "사슴", ear: .horse, tail: .short, len: 10.4, chest: 3.0, hip: 2.8, legF: 11.0, legH: 11.4, head: 2.3, snout: 2.8, snoutH: 1.0, neckX: 3.6, neckY: 5.2, flexAmp: 1.2, liftAmp: 1.35, legW: 0.8, x: ["antlers"]),
|
|
928
|
+
Sp(id: "elephant", label: "코끼리", ear: .none, tail: .rope, len: 11.2, chest: 4.5, hip: 4.2, legF: 7.4, legH: 7.4, head: 3.1, snout: 0, snoutH: 1.0, neckX: 3.2, neckY: 2.6, flexAmp: 0.4, liftAmp: 0.45, pitchAmp: 0.8, legW: 1.8, x: ["trunk"], eyeDx: 0.18),
|
|
929
|
+
Sp(id: "pig", label: "돼지", ear: .pig, tail: .curly, len: 10.0, chest: 3.6, hip: 3.6, legF: 5.6, legH: 5.6, head: 2.8, snout: 0, snoutH: 1.0, neckX: 3.4, neckY: 2.6, flexAmp: 0.6, liftAmp: 0.7, legW: 1.2, x: ["pigsnout"]),
|
|
930
|
+
Sp(id: "sheep", label: "양", ear: .sheep, tail: .stub, len: 9.6, chest: 3.6, hip: 3.6, legF: 9.2, legH: 9.2, head: 2.2, snout: 1.8, snoutH: 1.3, neckX: 4.4, neckY: 3.0, flexAmp: 0.7, liftAmp: 0.9, legW: 0.75, x: ["wool"]),
|
|
931
|
+
Sp(id: "hedgehog", label: "고슴도치", ear: .round, tail: .none, len: 8.4, chest: 3.0, hip: 3.0, legF: 4.2, legH: 4.2, head: 2.3, snout: 2.8, snoutH: 0.8, neckX: 3.6, neckY: 1.6, flexAmp: 0.4, liftAmp: 0.4, legW: 0.9, x: ["spikes"]),
|
|
932
|
+
Sp(id: "squirrel", label: "다람쥐", ear: .cat, tail: .squirrel, len: 8.0, chest: 2.6, hip: 2.9, legF: 5.0, legH: 7.0, head: 2.5, snout: 1.2, snoutH: 1.2, neckX: 3.0, neckY: 3.4, flexAmp: 1.3, liftAmp: 1.35, pitchAmp: 1.4, legW: 0.85),
|
|
933
|
+
Sp(id: "hamster", label: "햄스터", ear: .round, tail: .none, len: 7.6, chest: 3.6, hip: 3.8, legF: 3.6, legH: 3.6, head: 3.0, snout: 1.0, snoutH: 1.5, neckX: 2.6, neckY: 2.4, flexAmp: 0.3, liftAmp: 0.45, legW: 1.0),
|
|
934
|
+
Sp(id: "mouse", label: "생쥐", ear: .mouse, tail: .thinLong, len: 8.0, chest: 2.6, hip: 2.8, legF: 4.6, legH: 4.8, head: 2.4, snout: 2.6, snoutH: 0.8, neckX: 3.2, neckY: 2.4, flexAmp: 0.8, liftAmp: 0.8, legW: 0.8),
|
|
935
|
+
Sp(id: "frog", label: "개구리", kind: 4),
|
|
936
|
+
Sp(id: "duck", label: "오리", kind: 5),
|
|
937
|
+
Sp(id: "chick", label: "병아리", kind: 6),
|
|
938
|
+
Sp(id: "ghost", label: "유령", kind: 7),
|
|
939
|
+
]
|
|
940
|
+
|
|
941
|
+
func rot(_ p: NSPoint, _ c: NSPoint, _ a: CGFloat) -> NSPoint {
|
|
942
|
+
let dx = p.x - c.x, dy = p.y - c.y
|
|
943
|
+
return NSPoint(x: c.x + dx * cos(a) - dy * sin(a), y: c.y + dx * sin(a) + dy * cos(a))
|
|
944
|
+
}
|
|
945
|
+
func line2(_ a: NSPoint, _ b: NSPoint, _ w: CGFloat) { let q = NSBezierPath(); q.lineWidth = w; q.lineCapStyle = .round; q.move(to: a); q.line(to: b); q.stroke() }
|
|
946
|
+
func oval(_ c: NSPoint, _ rx: CGFloat, _ ry: CGFloat) { NSBezierPath(ovalIn: NSRect(x: c.x - rx, y: c.y - ry, width: rx * 2, height: ry * 2)).fill() }
|
|
947
|
+
|
|
948
|
+
func runner(_ sp: Sp, frame: Int, idle: Bool) -> NSImage {
|
|
853
949
|
let size = NSSize(width: 31 * RUNNER_SCALE, height: 21.4 * RUNNER_SCALE)
|
|
854
950
|
let img = NSImage(size: size, flipped: false) { _ in
|
|
855
951
|
let t = NSAffineTransform(); t.scale(by: RUNNER_SCALE); t.concat()
|
|
856
|
-
let p = idle ? STAND : GALLOP[frame % GALLOP.count]
|
|
857
|
-
let L = CGFloat(p.lift), s = CGFloat(p.stretch)
|
|
858
952
|
NSColor.black.setFill(); NSColor.black.setStroke()
|
|
859
|
-
|
|
860
|
-
|
|
953
|
+
if sp.waddle { penguin(frame: frame, idle: idle); return true }
|
|
954
|
+
if sp.fly > 0 { flyer(sp, frame: frame, idle: idle); return true }
|
|
955
|
+
if sp.kind == 4 { frog(frame: frame, idle: idle); return true }
|
|
956
|
+
if sp.kind == 5 || sp.kind == 6 { biped(chick: sp.kind == 6, frame: frame, idle: idle); return true }
|
|
957
|
+
if sp.kind == 7 { ghost(frame: frame, idle: idle); return true }
|
|
958
|
+
let k = idle ? STAND2 : GAL[frame % GAL.count]
|
|
959
|
+
let n = GAL.count, ph = 2 * CGFloat.pi * CGFloat(frame % n) / CGFloat(n)
|
|
960
|
+
let flex = CGFloat(k.flex * sp.flexAmp), lift = CGFloat(k.lift * sp.liftAmp) * 1.2
|
|
961
|
+
let pitch = CGFloat(k.pitch * sp.pitchAmp) * .pi / 180
|
|
962
|
+
let ground: CGFloat = 1.3
|
|
963
|
+
let airborne = sp.x.contains("wings") && !idle // runs on air: the hooves never touch the ground
|
|
964
|
+
let y0 = ground + sp.legH * LEGK * 0.86 + 0.9 + lift + (idle ? 0.12 * sin(ph) : 0) + (airborne ? 1.2 : 0)
|
|
965
|
+
let c = NSPoint(x: 14.6, y: y0)
|
|
966
|
+
let half = CGFloat(sp.len) * BODYK / 2 * (1 + 0.17 * flex)
|
|
967
|
+
let arch = flex < 0 ? -flex * 1.5 : -flex * 0.3 // gathered: the back humps up; stretched: nearly flat
|
|
968
|
+
let H = rot(NSPoint(x: c.x - half, y: y0), c, pitch), S = rot(NSPoint(x: c.x + half, y: y0), c, pitch)
|
|
969
|
+
let M = rot(NSPoint(x: c.x, y: y0 + arch * 2), c, pitch)
|
|
970
|
+
func leg(_ joint: NSPoint, _ a: (Double, Double), _ len: CGFloat, _ near: Bool) {
|
|
861
971
|
let a1 = CGFloat(a.0) * .pi / 180, a2 = CGFloat(a.1) * .pi / 180
|
|
862
|
-
let
|
|
863
|
-
|
|
864
|
-
foot
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
tail
|
|
874
|
-
|
|
875
|
-
tail
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
972
|
+
let u = len * 0.5, l = len * 0.52
|
|
973
|
+
let knee = NSPoint(x: joint.x + sin(a1) * u, y: joint.y - cos(a1) * u)
|
|
974
|
+
var foot = NSPoint(x: knee.x + sin(a2) * l, y: knee.y - cos(a2) * l)
|
|
975
|
+
foot.y = max(foot.y, airborne ? 1.1 : ground)
|
|
976
|
+
let w = CGFloat(sp.legW) * (near ? 1 : 0.86)
|
|
977
|
+
taper(joint, knee, 3.6 * w, 2.0 * w); taper(knee, foot, 2.0 * w, 1.35 * w)
|
|
978
|
+
oval(NSPoint(x: foot.x + 0.35, y: foot.y + 0.05), 1.0 * w, 0.72 * w)
|
|
979
|
+
}
|
|
980
|
+
let sh = NSPoint(x: S.x - 0.4, y: S.y - CGFloat(sp.chest) * 0.35), hp = NSPoint(x: H.x + 0.5, y: H.y - CGFloat(sp.hip) * 0.3)
|
|
981
|
+
// far legs
|
|
982
|
+
leg(sh, k.ff, CGFloat(sp.legF) * LEGK, false); leg(hp, k.hf, CGFloat(sp.legH) * LEGK, false)
|
|
983
|
+
// tail, trailing the body by a quarter stride
|
|
984
|
+
let lag = sin(ph - .pi / 2), tb = rot(NSPoint(x: c.x - half - 0.6, y: y0 + 0.8), c, pitch)
|
|
985
|
+
let tail = NSBezierPath(); tail.lineCapStyle = .round; tail.lineJoinStyle = .round
|
|
986
|
+
switch sp.tail {
|
|
987
|
+
case .curl:
|
|
988
|
+
tail.lineWidth = 3.1
|
|
989
|
+
tail.move(to: tb)
|
|
990
|
+
tail.curve(to: NSPoint(x: tb.x + 1.0 + flex * 0.4, y: tb.y + 5.2 - flex * 0.6), controlPoint1: NSPoint(x: tb.x - 5.0, y: tb.y + 0.4), controlPoint2: NSPoint(x: tb.x - 5.0 + lag, y: tb.y + 6.2))
|
|
991
|
+
tail.stroke()
|
|
992
|
+
case .long, .tuft, .thin:
|
|
993
|
+
tail.lineWidth = sp.tail == .tuft ? 1.4 : 1.6
|
|
994
|
+
let end = NSPoint(x: tb.x - 7.0 + abs(flex) * 0.6, y: tb.y + 1.2 - flex * 2.4 + lag * 1.6)
|
|
995
|
+
tail.move(to: tb)
|
|
996
|
+
tail.curve(to: end, controlPoint1: NSPoint(x: tb.x - 2.6, y: tb.y - 1.4 - lag), controlPoint2: NSPoint(x: end.x + 2.6, y: end.y - 2.2 + lag * 1.4))
|
|
997
|
+
tail.stroke()
|
|
998
|
+
if sp.tail == .tuft { oval(end, 1.3, 1.1) }
|
|
999
|
+
case .bushy:
|
|
1000
|
+
let end = NSPoint(x: tb.x - 7.2, y: tb.y - 0.4 - flex * 1.6 + lag * 1.2)
|
|
1001
|
+
let b = NSBezierPath()
|
|
1002
|
+
b.move(to: NSPoint(x: tb.x + 0.4, y: tb.y + 1.2))
|
|
1003
|
+
b.curve(to: end, controlPoint1: NSPoint(x: tb.x - 2.6, y: tb.y + 2.4 + lag * 0.6), controlPoint2: NSPoint(x: end.x + 2.4, y: end.y + 2.2))
|
|
1004
|
+
b.curve(to: NSPoint(x: tb.x + 0.4, y: tb.y - 1.2), controlPoint1: NSPoint(x: end.x + 1.6, y: end.y - 1.8), controlPoint2: NSPoint(x: tb.x - 2.8, y: tb.y - 2.0 + lag * 0.6))
|
|
1005
|
+
b.close(); b.fill()
|
|
1006
|
+
case .stub:
|
|
1007
|
+
oval(NSPoint(x: tb.x + 0.6, y: tb.y + 0.6), 1.5, 1.4)
|
|
1008
|
+
case .none: break
|
|
1009
|
+
case .curly: // a pig's corkscrew
|
|
1010
|
+
let cc = NSPoint(x: tb.x - 1.2, y: tb.y + 1.0 + lag * 0.3), t = NSBezierPath(); t.lineWidth = 0.85; t.lineCapStyle = .round
|
|
1011
|
+
t.move(to: NSPoint(x: tb.x + 0.2, y: tb.y + 0.2))
|
|
1012
|
+
t.appendArc(withCenter: cc, radius: 0.95, startAngle: -20, endAngle: 300, clockwise: false); t.stroke()
|
|
1013
|
+
case .ringed, .hang:
|
|
1014
|
+
let end = sp.tail == .hang ? NSPoint(x: tb.x - 5.6, y: tb.y - 3.6 + lag * 0.9 - flex * 0.6) : NSPoint(x: tb.x - 7.0, y: tb.y + 0.4 - flex * 1.4 + lag * 1.2)
|
|
1015
|
+
let b = NSBezierPath()
|
|
1016
|
+
b.move(to: NSPoint(x: tb.x + 0.4, y: tb.y + 1.2))
|
|
1017
|
+
b.curve(to: end, controlPoint1: NSPoint(x: tb.x - 2.4, y: tb.y + 1.6 + lag * 0.5), controlPoint2: NSPoint(x: end.x + 2.0, y: end.y + 2.0))
|
|
1018
|
+
b.curve(to: NSPoint(x: tb.x + 0.4, y: tb.y - 1.2), controlPoint1: NSPoint(x: end.x + 1.4, y: end.y - 1.6), controlPoint2: NSPoint(x: tb.x - 2.6, y: tb.y - 1.8 + lag * 0.5))
|
|
1019
|
+
b.close(); b.fill()
|
|
1020
|
+
if sp.tail == .ringed { // dark and pale rings: two gaps cut across the tail
|
|
1021
|
+
NSGraphicsContext.current?.compositingOperation = .clear
|
|
1022
|
+
for t in [0.42, 0.7] as [CGFloat] {
|
|
1023
|
+
let m = NSPoint(x: tb.x + (end.x - tb.x) * t, y: tb.y + (end.y - tb.y) * t + 0.3)
|
|
1024
|
+
line2(NSPoint(x: m.x + 0.5, y: m.y + 2.2), NSPoint(x: m.x - 0.5, y: m.y - 2.2), 0.6)
|
|
1025
|
+
}
|
|
1026
|
+
NSGraphicsContext.current?.compositingOperation = .sourceOver
|
|
1027
|
+
}
|
|
1028
|
+
case .squirrel: // a big plume carried up over the back, its tip curling forward
|
|
1029
|
+
let t = NSBezierPath(); t.lineWidth = 3.6; t.lineCapStyle = .round
|
|
1030
|
+
let tip = NSPoint(x: tb.x + 0.8 + lag * 0.4, y: tb.y + 8.6 - flex * 0.6)
|
|
1031
|
+
t.move(to: tb); t.curve(to: tip, controlPoint1: NSPoint(x: tb.x - 5.2, y: tb.y + 1.4), controlPoint2: NSPoint(x: tb.x - 4.4 + lag * 0.5, y: tb.y + 9.4)); t.stroke()
|
|
1032
|
+
oval(tip, 1.8, 1.6)
|
|
1033
|
+
case .thinLong, .monkey:
|
|
1034
|
+
tail.lineWidth = sp.tail == .monkey ? 1.1 : 0.75
|
|
1035
|
+
let end = NSPoint(x: tb.x - 7.4, y: tb.y + (sp.tail == .monkey ? 4.2 : 0.2) - flex * 1.2 + lag * 1.4)
|
|
1036
|
+
tail.move(to: tb)
|
|
1037
|
+
tail.curve(to: end, controlPoint1: NSPoint(x: tb.x - 2.8, y: tb.y - 1.6 - lag), controlPoint2: NSPoint(x: end.x + 2.6, y: end.y - 2.4 + lag))
|
|
1038
|
+
if sp.tail == .monkey { tail.appendArc(withCenter: NSPoint(x: end.x + 0.9, y: end.y), radius: 0.9, startAngle: 180, endAngle: 450, clockwise: false) }
|
|
1039
|
+
tail.stroke()
|
|
1040
|
+
case .flow: // a horse's tail: a few strands streaming back
|
|
1041
|
+
for (dy, w) in [(0.0, 1.5), (-0.9, 1.1), (0.8, 1.0)] as [(CGFloat, CGFloat)] {
|
|
1042
|
+
let t = NSBezierPath(); t.lineWidth = w; t.lineCapStyle = .round
|
|
1043
|
+
let end = NSPoint(x: tb.x - 6.4, y: tb.y - 2.2 + dy - flex * 1.2 + lag * 1.4)
|
|
1044
|
+
t.move(to: NSPoint(x: tb.x, y: tb.y + 0.6)); t.curve(to: end, controlPoint1: NSPoint(x: tb.x - 2.4, y: tb.y + 1.4 + dy), controlPoint2: NSPoint(x: end.x + 2.6, y: end.y + 1.2 - lag)); t.stroke()
|
|
1045
|
+
}
|
|
1046
|
+
case .wag: // a puppy's short tail, held up and wagging
|
|
1047
|
+
line2(NSPoint(x: tb.x + 0.3, y: tb.y + 0.4), NSPoint(x: tb.x - 1.8 + lag * 0.9, y: tb.y + 3.0), 1.4)
|
|
1048
|
+
case .short:
|
|
1049
|
+
oval(NSPoint(x: tb.x - 0.4, y: tb.y + 1.2), 0.9, 1.3)
|
|
1050
|
+
case .rope: // an elephant's thin tail with a tuft
|
|
1051
|
+
let e = NSPoint(x: tb.x - 1.6 + lag * 0.5, y: tb.y - 2.8)
|
|
1052
|
+
line2(tb, e, 0.7); oval(e, 0.6, 0.8)
|
|
1053
|
+
}
|
|
1054
|
+
// wings beat once a stride, the downstroke as the body rises; the far wing goes behind the body
|
|
1055
|
+
let wingFlap: CGFloat = idle ? -0.15 : sin(ph + 0.6)
|
|
1056
|
+
let wingRoot = rot(NSPoint(x: c.x + half - 1.8, y: y0 + CGFloat(sp.chest) * 0.75), c, pitch)
|
|
1057
|
+
if sp.x.contains("wings") { featherWing(NSPoint(x: wingRoot.x + 0.6, y: wingRoot.y + 0.3), flap: idle ? -0.15 : sin(ph + 0.25), span: idle ? 5.5 : 7.6, near: false) }
|
|
1058
|
+
// torso: hip and chest masses joined along a spine that bends
|
|
1059
|
+
let sp2 = NSBezierPath(); sp2.lineWidth = CGFloat(min(sp.chest, sp.hip)) * 2.15; sp2.lineCapStyle = .round
|
|
1060
|
+
sp2.move(to: H); sp2.curve(to: S, controlPoint1: M, controlPoint2: M); sp2.stroke()
|
|
1061
|
+
let sq = 1 - 0.09 * max(0, -lift) // squashed a little on landing
|
|
1062
|
+
oval(NSPoint(x: H.x + 0.3, y: H.y), CGFloat(sp.hip) * (2 - sq), CGFloat(sp.hip) * 0.95 * sq)
|
|
1063
|
+
oval(NSPoint(x: S.x - 0.2, y: S.y - 0.25), CGFloat(sp.chest) * (2 - sq), CGFloat(sp.chest) * sq)
|
|
1064
|
+
if sp.hump { oval(rot(NSPoint(x: S.x - 1.4, y: S.y + CGFloat(sp.chest) * 0.62), S, pitch), CGFloat(sp.chest) * 0.78, CGFloat(sp.chest) * 0.62) }
|
|
1065
|
+
let br = CGFloat(min(sp.chest, sp.hip)) * 1.07
|
|
1066
|
+
func along(_ t: CGFloat) -> NSPoint { // a point on the spine, t = 0 at the hip and 1 at the shoulder
|
|
1067
|
+
let u = 1 - t; return NSPoint(x: u * u * u * H.x + 3 * u * u * t * M.x + 3 * u * t * t * M.x + t * t * t * S.x, y: u * u * u * H.y + 3 * u * u * t * M.y + 3 * u * t * t * M.y + t * t * t * S.y)
|
|
1068
|
+
}
|
|
1069
|
+
if sp.x.contains("wool") { // a white fleece with a scalloped outline: the puffs drawn dark, then hollowed out
|
|
1070
|
+
leg(sh, k.fn, CGFloat(sp.legF) * LEGK, true); leg(hp, k.hn, CGFloat(sp.legH) * LEGK, true) // under the fleece
|
|
1071
|
+
var puffs: [(NSPoint, CGFloat)] = []
|
|
1072
|
+
for i in 0...5 { let p = along(CGFloat(i) / 5); puffs.append((NSPoint(x: p.x, y: p.y + br * 0.8), br * 0.62)); puffs.append((NSPoint(x: p.x, y: p.y - br * 0.55), br * 0.58)) }
|
|
1073
|
+
puffs.append((NSPoint(x: H.x - br * 0.8, y: H.y + 0.2), br * 0.62)); puffs.append((NSPoint(x: S.x + br * 0.55, y: S.y + br * 0.35), br * 0.6))
|
|
1074
|
+
for (c3, r) in puffs { oval(c3, r, r) }
|
|
1075
|
+
oval(along(0.5), br * 1.6, br * 1.1)
|
|
1076
|
+
NSGraphicsContext.current?.compositingOperation = .clear
|
|
1077
|
+
for (c3, r) in puffs { oval(c3, r - 0.75, r - 0.75) }
|
|
1078
|
+
oval(along(0.5), br * 1.6 - 0.75, br * 1.1 - 0.75)
|
|
1079
|
+
NSGraphicsContext.current?.compositingOperation = .sourceOver
|
|
1080
|
+
}
|
|
1081
|
+
if sp.x.contains("spikes") { // a hedgehog's coat: spines over the back, pointing back
|
|
1082
|
+
for i in 0..<10 {
|
|
1083
|
+
let t = 0.05 + CGFloat(i) / 10, p = along(t), up = br * (0.6 + 0.4 * sin(t * .pi))
|
|
1084
|
+
let b0 = NSPoint(x: p.x - 0.8, y: p.y + up * 0.7), b1 = NSPoint(x: p.x + 0.8, y: p.y + up * 0.75)
|
|
1085
|
+
let tip = NSPoint(x: p.x - 2.6 - lag * 0.2, y: p.y + up + 2.8)
|
|
1086
|
+
let sp3 = NSBezierPath(); sp3.move(to: b0); sp3.line(to: tip); sp3.line(to: b1); sp3.close(); sp3.fill()
|
|
1087
|
+
}
|
|
1088
|
+
for i in 0..<3 { let p = along(0.02); let sp3 = NSBezierPath(); sp3.move(to: NSPoint(x: p.x - 0.4, y: p.y + CGFloat(i) - 0.6)); sp3.line(to: NSPoint(x: p.x - br - 1.6, y: p.y + CGFloat(i) * 1.2 - 0.6)); sp3.line(to: NSPoint(x: p.x - 0.4, y: p.y + CGFloat(i) + 0.4)); sp3.close(); sp3.fill() }
|
|
1089
|
+
}
|
|
1090
|
+
if sp.x.contains("stripes") {
|
|
1091
|
+
NSGraphicsContext.current?.compositingOperation = .clear
|
|
1092
|
+
// a tiger's stripes, cut across the back
|
|
1093
|
+
for t in [0.12, 0.32, 0.52, 0.72] as [CGFloat] { let p = along(t); line2(NSPoint(x: p.x - 0.4, y: p.y + br * 1.05), NSPoint(x: p.x + 0.4, y: p.y + br * 0.15), 0.55) }
|
|
1094
|
+
NSGraphicsContext.current?.compositingOperation = .sourceOver
|
|
1095
|
+
}
|
|
1096
|
+
if sp.x.contains("wings") { featherWing(wingRoot, flap: wingFlap, span: idle ? 6.0 : 9.0, near: true) }
|
|
1097
|
+
// neck and head, turned three-quarters toward the viewer so both eyes show; the head stays steadier than the body
|
|
1098
|
+
let hpitch = pitch * 0.35, hr = CGFloat(sp.head) * HEADK
|
|
1099
|
+
let hc = NSPoint(x: S.x + CGFloat(sp.neckX) * 0.62 * cos(pitch) - CGFloat(sp.neckY) * 0.4 * sin(pitch),
|
|
1100
|
+
y: S.y + CGFloat(sp.neckY) * 0.62 - lift * 0.3 + CGFloat(sp.neckX) * 0.8 * sin(pitch))
|
|
1101
|
+
line2(NSPoint(x: S.x + 0.4, y: S.y + 0.4), hc, hr * 1.3)
|
|
1102
|
+
if sp.mane {
|
|
1103
|
+
lionMane(hc, hr, sweep: idle ? 0.05 : 0.32 + 0.12 * lag)
|
|
1104
|
+
}
|
|
1105
|
+
oval(hc, hr * 1.05, hr)
|
|
1106
|
+
let sn = CGFloat(sp.snout), sh2 = CGFloat(sp.snoutH)
|
|
1107
|
+
if sn > 1.6 { // a dog's or fox's muzzle points forward and down from the turned face
|
|
1108
|
+
let mc = rot(NSPoint(x: hc.x + hr * 0.62 + sn * 0.2, y: hc.y - hr * 0.45), hc, hpitch)
|
|
1109
|
+
oval(mc, hr * 0.42 + sn * 0.24, sh2 * 0.7 + 0.45)
|
|
1110
|
+
if sp.hump { oval(rot(NSPoint(x: mc.x + hr * 0.42 + sn * 0.2, y: mc.y + sh2 * 0.5), mc, 0), 0.85, 0.7) } // a bear's nose at the tip
|
|
1111
|
+
}
|
|
1112
|
+
let back = (lift > 0.8 ? 0.35 : 0.0) + (idle ? 0 : 0.12)
|
|
1113
|
+
func ear(_ base0: CGFloat, _ base1: CGFloat, _ tipX: CGFloat, _ tipY: CGFloat) {
|
|
1114
|
+
let a = rot(NSPoint(x: hc.x + base0, y: hc.y + hr * 0.55), hc, hpitch), b = rot(NSPoint(x: hc.x + base1, y: hc.y + hr * 0.7), hc, hpitch)
|
|
1115
|
+
let tip = rot(NSPoint(x: hc.x + tipX, y: hc.y + tipY), hc, hpitch + CGFloat(back))
|
|
1116
|
+
let e = NSBezierPath(); e.move(to: a); e.line(to: tip); e.line(to: b); e.close(); e.fill()
|
|
1117
|
+
}
|
|
1118
|
+
switch sp.ear {
|
|
1119
|
+
case .pricked: ear(-hr * 0.9, -hr * 0.15, -hr * 0.7, hr * 1.75); ear(hr * 0.05, hr * 0.85, hr * 0.55, hr * 1.75)
|
|
1120
|
+
case .cat: ear(-hr * 0.95, -hr * 0.2, -hr * 0.72, hr * 1.55); ear(hr * 0.0, hr * 0.85, hr * 0.5, hr * 1.55)
|
|
1121
|
+
case .round:
|
|
1122
|
+
for dx in [-hr * 0.6, hr * 0.45] { let p = rot(NSPoint(x: hc.x + dx, y: hc.y + hr * 0.82), hc, hpitch); oval(p, hr * 0.38, hr * 0.38) }
|
|
1123
|
+
case .long:
|
|
1124
|
+
for (dx, sw) in [(-hr * 0.45, 0.1), (hr * 0.2, 0.3)] as [(CGFloat, CGFloat)] {
|
|
1125
|
+
let base = rot(NSPoint(x: hc.x + dx, y: hc.y + hr * 0.6), hc, hpitch)
|
|
1126
|
+
let ang = hpitch + CGFloat(back) * 1.6 + 0.3 + sw - lag * 0.15
|
|
1127
|
+
let tip = NSPoint(x: base.x - sin(ang) * hr * 1.55, y: base.y + cos(ang) * hr * 1.55)
|
|
1128
|
+
taper(base, tip, hr * 0.42, hr * 0.36)
|
|
1129
|
+
}
|
|
1130
|
+
case .tiny, .none: break
|
|
1131
|
+
case .floppy: // a puppy's ears hang and swing
|
|
1132
|
+
// the far ear peeks over the crown; the near one hangs by the cheek, set off from the head by a thin gap
|
|
1133
|
+
let fb = rot(NSPoint(x: hc.x + hr * 0.55, y: hc.y + hr * 0.75), hc, hpitch)
|
|
1134
|
+
taper(fb, NSPoint(x: fb.x + hr * 0.35, y: fb.y - hr * 0.35), hr * 0.5, hr * 0.45)
|
|
1135
|
+
let base = rot(NSPoint(x: hc.x - hr * 0.88, y: hc.y + hr * 0.55), hc, hpitch)
|
|
1136
|
+
let tip = NSPoint(x: base.x - hr * 0.55 - lag * hr * 0.3, y: base.y - hr * 1.4 + (lift > 0.8 ? hr * 0.55 : 0))
|
|
1137
|
+
NSGraphicsContext.current?.compositingOperation = .clear
|
|
1138
|
+
taper(base, tip, hr * 0.5 + 1.0, hr * 0.66 + 1.0)
|
|
1139
|
+
NSGraphicsContext.current?.compositingOperation = .sourceOver
|
|
1140
|
+
taper(base, tip, hr * 0.5, hr * 0.66)
|
|
1141
|
+
case .side: // round ears on the sides: big and fluffy on a koala
|
|
1142
|
+
let big = sp.x.contains("koalanose")
|
|
1143
|
+
for (dx, dy, r) in [(-hr * (big ? 0.95 : 1.0), hr * (big ? 0.55 : 0.15), hr * (big ? 0.62 : 0.36)), (hr * (big ? 0.8 : 0.95), hr * (big ? 0.6 : 0.2), hr * (big ? 0.5 : 0.3))] as [(CGFloat, CGFloat, CGFloat)] {
|
|
1144
|
+
let ec = rot(NSPoint(x: hc.x + dx, y: hc.y + dy), hc, hpitch)
|
|
1145
|
+
oval(ec, r, r)
|
|
1146
|
+
if big { NSGraphicsContext.current?.compositingOperation = .clear; oval(NSPoint(x: ec.x + (dx < 0 ? -r * 0.12 : r * 0.12), y: ec.y + r * 0.05), r * 0.55, r * 0.55); NSGraphicsContext.current?.compositingOperation = .sourceOver }
|
|
1147
|
+
}
|
|
1148
|
+
case .mouse:
|
|
1149
|
+
for (dx, r) in [(-hr * 0.55, hr * 0.62), (hr * 0.45, hr * 0.55)] as [(CGFloat, CGFloat)] { oval(rot(NSPoint(x: hc.x + dx, y: hc.y + hr * 1.0), hc, hpitch), r, r) }
|
|
1150
|
+
case .horse: ear(-hr * 0.6, -hr * 0.15, -hr * 0.55, hr * 1.6); ear(hr * 0.0, hr * 0.4, hr * 0.15, hr * 1.55)
|
|
1151
|
+
case .sheep:
|
|
1152
|
+
for (dx, f) in [(-hr * 0.7, 1.0), (hr * 0.4, 0.8)] as [(CGFloat, CGFloat)] { let b = rot(NSPoint(x: hc.x + dx, y: hc.y + hr * 0.45), hc, hpitch); taper(b, NSPoint(x: b.x - hr * 0.9 * f, y: b.y - hr * 0.1 + lag * 0.2), hr * 0.42, hr * 0.32) }
|
|
1153
|
+
case .pig: ear(-hr * 0.85, -hr * 0.15, hr * 0.1, hr * 1.35); ear(hr * 0.0, hr * 0.7, hr * 0.95, hr * 1.2)
|
|
1154
|
+
}
|
|
1155
|
+
// head features
|
|
1156
|
+
if sp.x.contains("horn") {
|
|
1157
|
+
let a = rot(NSPoint(x: hc.x + hr * 0.15, y: hc.y + hr * 0.8), hc, hpitch), b = rot(NSPoint(x: hc.x + hr * 0.65, y: hc.y + hr * 0.85), hc, hpitch), t = rot(NSPoint(x: hc.x + hr * 1.15, y: hc.y + hr * 2.25), hc, hpitch)
|
|
1158
|
+
let h = NSBezierPath(); h.move(to: a); h.line(to: t); h.line(to: b); h.close(); h.fill()
|
|
1159
|
+
}
|
|
1160
|
+
if sp.x.contains("neckmane") { // a mane down the back of the neck, streaming in the run
|
|
1161
|
+
for i in 0..<5 {
|
|
1162
|
+
let t = CGFloat(i) / 4, base = NSPoint(x: hc.x - hr * 0.75 + (S.x - 0.6 - hc.x + hr * 0.75) * t, y: hc.y + hr * 0.55 + (S.y + CGFloat(sp.chest) * 0.7 - hc.y - hr * 0.55) * t)
|
|
1163
|
+
let tip = NSPoint(x: base.x - 2.2 - lag * 0.5, y: base.y + 0.4 - t * 0.6)
|
|
1164
|
+
let m = NSBezierPath(); m.move(to: NSPoint(x: base.x + 0.7, y: base.y + 0.4)); m.line(to: tip); m.line(to: NSPoint(x: base.x + 0.3, y: base.y - 0.9)); m.close(); m.fill()
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
if sp.x.contains("antlers") {
|
|
1168
|
+
for (dx, f) in [(-hr * 0.35, 1.0), (hr * 0.2, 0.85)] as [(CGFloat, CGFloat)] {
|
|
1169
|
+
let b = rot(NSPoint(x: hc.x + dx, y: hc.y + hr * 0.8), hc, hpitch)
|
|
1170
|
+
let top = NSPoint(x: b.x - hr * 0.7 * f, y: b.y + hr * 1.7 * f), m1 = NSPoint(x: b.x - hr * 0.25 * f, y: b.y + hr * 0.75 * f), m2 = NSPoint(x: b.x - hr * 0.5 * f, y: b.y + hr * 1.25 * f)
|
|
1171
|
+
line2(b, top, 0.75); line2(m1, NSPoint(x: m1.x + hr * 0.55 * f, y: m1.y + hr * 0.45 * f), 0.65); line2(m2, NSPoint(x: m2.x + hr * 0.5 * f, y: m2.y + hr * 0.55 * f), 0.6)
|
|
1172
|
+
}
|
|
1173
|
+
}
|
|
1174
|
+
if sp.x.contains("trunk") { // an elephant: a big ear set apart from the head, and a swinging trunk
|
|
1175
|
+
let ec = rot(NSPoint(x: hc.x - hr * 0.95, y: hc.y - hr * 0.05), hc, hpitch)
|
|
1176
|
+
NSGraphicsContext.current?.compositingOperation = .clear
|
|
1177
|
+
NSBezierPath(ovalIn: NSRect(x: ec.x - hr * 0.78, y: ec.y - hr * 0.98, width: hr * 1.56, height: hr * 1.96)).fill()
|
|
1178
|
+
NSGraphicsContext.current?.compositingOperation = .sourceOver
|
|
1179
|
+
oval(ec, hr * 0.68 + lag * 0.15, hr * 0.88)
|
|
1180
|
+
let r0 = rot(NSPoint(x: hc.x + hr * 0.8, y: hc.y - hr * 0.25), hc, hpitch), mid = NSPoint(x: r0.x + hr * 0.55, y: r0.y - hr * 0.8), tip = NSPoint(x: r0.x + hr * 0.6 + lag * hr * 0.35, y: r0.y - hr * 1.7)
|
|
1181
|
+
taper(r0, mid, hr * 0.7, hr * 0.5); taper(mid, tip, hr * 0.5, hr * 0.38)
|
|
1182
|
+
}
|
|
1183
|
+
if sp.x.contains("pigsnout") {
|
|
1184
|
+
let c2 = rot(NSPoint(x: hc.x + hr * 1.0, y: hc.y - hr * 0.3), hc, hpitch)
|
|
1185
|
+
oval(c2, hr * 0.38, hr * 0.48)
|
|
1186
|
+
NSGraphicsContext.current?.compositingOperation = .clear
|
|
1187
|
+
for dy in [hr * 0.15, -hr * 0.17] { oval(NSPoint(x: c2.x + hr * 0.12, y: c2.y + dy), hr * 0.09, hr * 0.12) }
|
|
1188
|
+
NSGraphicsContext.current?.compositingOperation = .sourceOver
|
|
1189
|
+
}
|
|
1190
|
+
if sp.x.contains("koalanose") { oval(rot(NSPoint(x: hc.x + hr * 1.0, y: hc.y - hr * 0.2), hc, hpitch), hr * 0.38, hr * 0.5) }
|
|
1191
|
+
if sp.x.contains("panda") { // pale face, dark eye patches
|
|
1192
|
+
NSGraphicsContext.current?.compositingOperation = .clear
|
|
1193
|
+
oval(hc, hr * 0.84, hr * 0.8)
|
|
1194
|
+
NSGraphicsContext.current?.compositingOperation = .sourceOver
|
|
1195
|
+
for (x, y, r) in [(0.42, 0.06, 0.36), (-0.2, 0.1, 0.3)] as [(CGFloat, CGFloat, CGFloat)] {
|
|
1196
|
+
let p = NSBezierPath(ovalIn: NSRect(x: -r * hr, y: -r * hr * 0.8, width: 2 * r * hr, height: 1.6 * r * hr))
|
|
1197
|
+
let tr = NSAffineTransform(); tr.translateX(by: hc.x + hr * x, yBy: hc.y + hr * y); tr.rotate(byRadians: -0.5); p.transform(using: tr as AffineTransform); p.fill()
|
|
1198
|
+
}
|
|
1199
|
+
oval(NSPoint(x: hc.x + hr * 0.78, y: hc.y - hr * 0.32), hr * 0.17, hr * 0.13)
|
|
1200
|
+
}
|
|
1201
|
+
// near legs
|
|
1202
|
+
if !sp.x.contains("wool") { leg(sh, k.fn, CGFloat(sp.legF) * LEGK, true); leg(hp, k.hn, CGFloat(sp.legH) * LEGK, true) }
|
|
1203
|
+
eyes(NSPoint(x: hc.x + hr * CGFloat(sp.eyeDx), y: hc.y), hr, hpitch, CGFloat(sp.eyeK))
|
|
901
1204
|
return true
|
|
902
1205
|
}
|
|
903
1206
|
img.isTemplate = true
|
|
904
1207
|
return img
|
|
905
1208
|
}
|
|
906
1209
|
|
|
1210
|
+
/** A penguin does not gallop: it waddles, rocking side to side with the flippers out. */
|
|
1211
|
+
func penguin(frame: Int, idle: Bool) {
|
|
1212
|
+
let n = GAL.count, ph = 2 * CGFloat.pi * CGFloat(frame % n) / CGFloat(n)
|
|
1213
|
+
let rock = idle ? 0.04 * sin(ph) : 0.2 * sin(ph), hop = idle ? 0 : 0.7 * abs(cos(ph))
|
|
1214
|
+
let ground: CGFloat = 1.3
|
|
1215
|
+
let base = NSPoint(x: 15.5, y: ground + 1.4 + hop)
|
|
1216
|
+
let c = NSPoint(x: base.x, y: base.y + 7.4)
|
|
1217
|
+
// feet: the one carrying the weight stays down
|
|
1218
|
+
for (i, dx) in [(0, -1.8), (1, 1.6)] as [(Int, CGFloat)] {
|
|
1219
|
+
let up = idle ? 0 : max(0, (i == 0 ? 1 : -1) * sin(ph)) * 1.2
|
|
1220
|
+
oval(NSPoint(x: base.x + dx + 1.0, y: ground + 0.5 + up), 1.9, 0.75)
|
|
1221
|
+
}
|
|
1222
|
+
let body = NSBezierPath(ovalIn: NSRect(x: c.x - 5.0, y: c.y - 7.6, width: 10.0, height: 14.4))
|
|
1223
|
+
let t = NSAffineTransform(); t.translateX(by: base.x, yBy: base.y); t.rotate(byRadians: rock); t.translateX(by: -base.x, yBy: -base.y)
|
|
1224
|
+
body.transform(using: t as AffineTransform); body.fill()
|
|
1225
|
+
let head = rot(NSPoint(x: c.x + 0.6, y: c.y + 7.2), base, rock)
|
|
1226
|
+
oval(head, 3.7, 3.4)
|
|
1227
|
+
let b1 = rot(NSPoint(x: c.x + 3.6, y: c.y + 7.6), base, rock), b2 = rot(NSPoint(x: c.x + 7.0, y: c.y + 6.5), base, rock), b3 = rot(NSPoint(x: c.x + 3.4, y: c.y + 6.0), base, rock)
|
|
1228
|
+
let beak = NSBezierPath(); beak.move(to: b1); beak.line(to: b2); beak.line(to: b3); beak.close(); beak.fill()
|
|
1229
|
+
for (sx, sgn) in [(-4.4, -1.0), (4.4, 1.0)] as [(CGFloat, CGFloat)] { // flippers flap out
|
|
1230
|
+
let root = rot(NSPoint(x: c.x + sx, y: c.y + 2.2), base, rock)
|
|
1231
|
+
let ang = (idle ? 0.25 : 0.45 + 0.35 * sin(ph * 2)) * sgn
|
|
1232
|
+
line2(root, NSPoint(x: root.x + sin(ang) * 5.2, y: root.y - cos(ang) * 5.2), 1.9)
|
|
1233
|
+
}
|
|
1234
|
+
NSGraphicsContext.current?.compositingOperation = .clear
|
|
1235
|
+
let belly = NSBezierPath(ovalIn: NSRect(x: c.x - 1.2, y: c.y - 6.0, width: 5.4, height: 10.2))
|
|
1236
|
+
belly.transform(using: t as AffineTransform); belly.fill()
|
|
1237
|
+
eyes(head, 3.4, rock)
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
let HEADK: CGFloat = 1.42, LEGK: CGFloat = 0.72, BODYK: CGFloat = 0.74
|
|
1241
|
+
/** Two eyes on a face turned toward the viewer: the far one a little smaller, pupils looking where the animal runs. */
|
|
1242
|
+
func eyes(_ hc: NSPoint, _ hr: CGFloat, _ a: CGFloat, _ k: CGFloat = 1) {
|
|
1243
|
+
let spots: [(CGFloat, CGFloat, CGFloat)] = [(0.42, 0.1, 0.33 * k), (-0.2, 0.14, 0.28 * k)]
|
|
1244
|
+
NSGraphicsContext.current?.compositingOperation = .clear
|
|
1245
|
+
for (x, y, r) in spots { oval(rot(NSPoint(x: hc.x + hr * x, y: hc.y + hr * y), hc, a), hr * r, hr * r * 1.1) }
|
|
1246
|
+
NSGraphicsContext.current?.compositingOperation = .sourceOver
|
|
1247
|
+
for (x, y, r) in spots { oval(rot(NSPoint(x: hc.x + hr * (x + r * 0.35), y: hc.y + hr * y), hc, a), hr * r * 0.5, hr * r * 0.6) }
|
|
1248
|
+
}
|
|
1249
|
+
func taper(_ a: NSPoint, _ b: NSPoint, _ w1: CGFloat, _ w2: CGFloat) {
|
|
1250
|
+
let dx = b.x - a.x, dy = b.y - a.y, d = max(0.001, hypot(dx, dy)), nx = -dy / d, ny = dx / d
|
|
1251
|
+
let p = NSBezierPath()
|
|
1252
|
+
p.move(to: NSPoint(x: a.x + nx * w1 / 2, y: a.y + ny * w1 / 2)); p.line(to: NSPoint(x: b.x + nx * w2 / 2, y: b.y + ny * w2 / 2))
|
|
1253
|
+
p.line(to: NSPoint(x: b.x - nx * w2 / 2, y: b.y - ny * w2 / 2)); p.line(to: NSPoint(x: a.x - nx * w1 / 2, y: a.y - ny * w1 / 2)); p.close(); p.fill()
|
|
1254
|
+
oval(a, w1 / 2, w1 / 2); oval(b, w2 / 2, w2 / 2)
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
|
|
1258
|
+
/** Birds and the dragon fly: the wings beat, the body rises on the downstroke, a level wing is seen end-on and looks short. */
|
|
1259
|
+
func flyer(_ sp: Sp, frame: Int, idle: Bool) {
|
|
1260
|
+
let n = GAL.count, ph = 2 * CGFloat.pi * CGFloat(frame % n) / CGFloat(n)
|
|
1261
|
+
let ground: CGFloat = 1.3, style = sp.fly
|
|
1262
|
+
let flap: CGFloat = idle ? 0 : sin(ph)
|
|
1263
|
+
let bob: CGFloat = idle ? 0.15 * sin(ph) : -flap * 1.1
|
|
1264
|
+
let c = NSPoint(x: style == 3 ? 15.0 : 14.2, y: idle ? ground + 6.6 + bob : 10.0 + bob)
|
|
1265
|
+
let tilt: CGFloat = idle ? 0 : 0.1
|
|
1266
|
+
func R(_ x: CGFloat, _ y: CGFloat) -> NSPoint { rot(NSPoint(x: c.x + x, y: c.y + y), c, tilt) }
|
|
1267
|
+
let shoulder = R(style == 2 ? -0.4 : 0.4, 1.4)
|
|
1268
|
+
func wing(_ near: Bool) {
|
|
1269
|
+
if idle { // folded along the body
|
|
1270
|
+
let w = NSBezierPath(); let a = R(1.6, 1.6), t = R(style == 3 ? -5.6 : -6.0, -0.2)
|
|
1271
|
+
w.move(to: a); w.curve(to: t, controlPoint1: R(-1.0, 3.6), controlPoint2: R(-4.4, 2.6)); w.curve(to: a, controlPoint1: R(-3.6, -1.2), controlPoint2: R(-0.6, -0.6)); w.close(); w.fill()
|
|
1272
|
+
return
|
|
1273
|
+
}
|
|
1274
|
+
let phase = near ? flap : sin(ph - 0.35)
|
|
1275
|
+
let g = CGFloat.pi - phase * 1.2 + (near ? 0 : 0.1)
|
|
1276
|
+
let span: CGFloat = (style == 2 ? 8.6 : style == 3 ? 8.8 : 9.8) * (0.42 + 0.58 * abs(phase)) * (near ? 1 : 0.85)
|
|
1277
|
+
let u = NSPoint(x: cos(g), y: sin(g))
|
|
1278
|
+
var v = NSPoint(x: -u.y, y: u.x); if v.x > 0 { v = NSPoint(x: -v.x, y: -v.y) } // toward the tail
|
|
1279
|
+
func P(_ along: CGFloat, _ back: CGFloat) -> NSPoint { NSPoint(x: shoulder.x + u.x * along + v.x * back, y: shoulder.y + u.y * along + v.y * back) }
|
|
1280
|
+
let w = NSBezierPath()
|
|
1281
|
+
switch style {
|
|
1282
|
+
case 1: // eagle: broad wing, fingered tip
|
|
1283
|
+
w.move(to: P(0, -1.2)); w.curve(to: P(span, 0.2), controlPoint1: P(span * 0.4, -1.6), controlPoint2: P(span * 0.8, -0.8))
|
|
1284
|
+
for k in 0..<4 { let a = span * (1 - 0.13 * CGFloat(k)); w.line(to: P(a - 0.4, 1.0 + 0.55 * CGFloat(k))); w.line(to: P(a - 1.0, 0.7 + 0.6 * CGFloat(k))) }
|
|
1285
|
+
w.curve(to: P(-0.6, 3.0), controlPoint1: P(span * 0.4, 3.4), controlPoint2: P(span * 0.15, 3.4))
|
|
1286
|
+
case 2: // owl: round, soft wing
|
|
1287
|
+
w.move(to: P(0, -1.0)); w.curve(to: P(span, 0.8), controlPoint1: P(span * 0.5, -1.8), controlPoint2: P(span * 1.05, -0.6))
|
|
1288
|
+
w.curve(to: P(-0.4, 3.2), controlPoint1: P(span * 0.9, 3.4), controlPoint2: P(span * 0.3, 4.0))
|
|
1289
|
+
default: // dragon: bat wing, membrane scalloped between finger spars
|
|
1290
|
+
let tips: [(CGFloat, CGFloat)] = [(span, -0.2), (span * 0.82, 2.4), (span * 0.55, 3.6)]
|
|
1291
|
+
w.move(to: P(0, -0.8)); w.line(to: P(span * 0.55, -1.0)); w.line(to: P(tips[0].0, tips[0].1))
|
|
1292
|
+
var prev = tips[0]
|
|
1293
|
+
for t in tips.dropFirst() { let mid = P((prev.0 + t.0) / 2 - 1.4, (prev.1 + t.1) / 2 - 0.2); w.curve(to: P(t.0, t.1), controlPoint1: mid, controlPoint2: mid); prev = t }
|
|
1294
|
+
let mid = P(prev.0 / 2 - 1.0, 2.0); w.curve(to: P(-0.6, 2.6), controlPoint1: mid, controlPoint2: mid)
|
|
1295
|
+
for t in tips { line2(P(0, 0.2), P(t.0, t.1), 0.75) }
|
|
1296
|
+
}
|
|
1297
|
+
w.close(); w.fill()
|
|
1298
|
+
}
|
|
1299
|
+
wing(false)
|
|
1300
|
+
// tail
|
|
1301
|
+
switch style {
|
|
1302
|
+
case 1: let t = NSBezierPath(); t.move(to: R(-4.0, 1.2)); t.line(to: R(-8.4, 2.4)); t.line(to: R(-8.6, -1.2)); t.line(to: R(-4.0, -0.8)); t.close(); t.fill()
|
|
1303
|
+
case 2: let t = NSBezierPath(); t.move(to: R(-3.6, 0.8)); t.line(to: R(-6.2, 0.6)); t.line(to: R(-5.8, -1.4)); t.line(to: R(-3.2, -1.2)); t.close(); t.fill()
|
|
1304
|
+
default:
|
|
1305
|
+
let wv = idle ? 0.3 * sin(ph) : 1.4 * sin(ph - 1.2)
|
|
1306
|
+
let t = NSBezierPath(); t.lineCapStyle = .round
|
|
1307
|
+
let end = R(-11.2, 0.4 + wv)
|
|
1308
|
+
t.move(to: R(-3.0, 0.2)); t.curve(to: end, controlPoint1: R(-6.0, -1.6 - wv), controlPoint2: R(-8.6, 1.6 + wv))
|
|
1309
|
+
t.lineWidth = 1.6; t.stroke()
|
|
1310
|
+
let sp = NSBezierPath(); sp.move(to: NSPoint(x: end.x + 0.6, y: end.y)); sp.line(to: NSPoint(x: end.x - 1.4, y: end.y + 1.3)); sp.line(to: NSPoint(x: end.x - 1.0, y: end.y - 1.4)); sp.close(); sp.fill()
|
|
1311
|
+
}
|
|
1312
|
+
// legs: tucked in flight, standing at rest
|
|
1313
|
+
for dx in [CGFloat(-1.2), 0.4] {
|
|
1314
|
+
let hip = R(dx, -1.6)
|
|
1315
|
+
let foot = idle ? NSPoint(x: hip.x + 0.3, y: ground + 0.3) : R(dx - 1.6, -3.6)
|
|
1316
|
+
taper(hip, foot, style == 3 ? 1.8 : 1.2, 0.9)
|
|
1317
|
+
if idle { oval(NSPoint(x: foot.x + 0.5, y: foot.y), 1.1, 0.5) }
|
|
1318
|
+
}
|
|
1319
|
+
// body
|
|
1320
|
+
let (rx, ry): (CGFloat, CGFloat) = style == 2 ? (4.2, 3.9) : style == 3 ? (4.6, 2.9) : (4.8, 3.1)
|
|
1321
|
+
let body = NSBezierPath(ovalIn: NSRect(x: c.x - rx, y: c.y - ry, width: rx * 2, height: ry * 2))
|
|
1322
|
+
let tr = NSAffineTransform(); tr.translateX(by: c.x, yBy: c.y); tr.rotate(byRadians: tilt); tr.translateX(by: -c.x, yBy: -c.y)
|
|
1323
|
+
body.transform(using: tr as AffineTransform); body.fill()
|
|
1324
|
+
// head, three-quarters toward the viewer
|
|
1325
|
+
let hr: CGFloat = style == 2 ? 3.6 : 3.3
|
|
1326
|
+
let hc = style == 2 ? R(2.4, 3.6) : style == 3 ? R(5.4, 3.6) : R(4.6, 2.9)
|
|
1327
|
+
if style == 3 { line2(R(3.0, 1.4), hc, 2.6) }
|
|
1328
|
+
oval(hc, hr * 1.02, hr)
|
|
1329
|
+
switch style {
|
|
1330
|
+
case 1: // hooked beak
|
|
1331
|
+
let b = NSBezierPath(); b.move(to: NSPoint(x: hc.x + hr * 0.55, y: hc.y + hr * 0.15)); b.line(to: NSPoint(x: hc.x + hr * 1.45, y: hc.y - hr * 0.05))
|
|
1332
|
+
b.curve(to: NSPoint(x: hc.x + hr * 1.05, y: hc.y - hr * 0.7), controlPoint1: NSPoint(x: hc.x + hr * 1.7, y: hc.y - hr * 0.35), controlPoint2: NSPoint(x: hc.x + hr * 1.4, y: hc.y - hr * 0.75))
|
|
1333
|
+
b.line(to: NSPoint(x: hc.x + hr * 0.5, y: hc.y - hr * 0.5)); b.close(); b.fill()
|
|
1334
|
+
case 2: // ear tufts and a small beak
|
|
1335
|
+
for (x0, tip, x1) in [(-0.85, -0.85, -0.25), (0.15, 0.75, 0.8)] as [(CGFloat, CGFloat, CGFloat)] {
|
|
1336
|
+
let e = NSBezierPath(); e.move(to: NSPoint(x: hc.x + hr * x0, y: hc.y + hr * 0.6)); e.line(to: NSPoint(x: hc.x + hr * tip, y: hc.y + hr * 1.45)); e.line(to: NSPoint(x: hc.x + hr * x1, y: hc.y + hr * 0.75)); e.close(); e.fill()
|
|
1337
|
+
}
|
|
1338
|
+
default: // snout and two little horns
|
|
1339
|
+
oval(NSPoint(x: hc.x + hr * 0.95, y: hc.y - hr * 0.35), hr * 0.75, hr * 0.5)
|
|
1340
|
+
for (x0, tip) in [(-0.6, -1.05), (0.1, -0.2)] as [(CGFloat, CGFloat)] {
|
|
1341
|
+
let h = NSBezierPath(); h.move(to: NSPoint(x: hc.x + hr * x0, y: hc.y + hr * 0.7)); h.line(to: NSPoint(x: hc.x + hr * tip, y: hc.y + hr * 1.5)); h.line(to: NSPoint(x: hc.x + hr * (x0 + 0.4), y: hc.y + hr * 0.8)); h.close(); h.fill()
|
|
1342
|
+
}
|
|
1343
|
+
}
|
|
1344
|
+
wing(true)
|
|
1345
|
+
if style == 2 { // an owl's face is all eyes
|
|
1346
|
+
NSGraphicsContext.current?.compositingOperation = .clear
|
|
1347
|
+
for x in [-0.42, 0.42] as [CGFloat] { oval(NSPoint(x: hc.x + hr * x, y: hc.y + hr * 0.05), hr * 0.38, hr * 0.4) }
|
|
1348
|
+
NSGraphicsContext.current?.compositingOperation = .sourceOver
|
|
1349
|
+
for x in [-0.42, 0.42] as [CGFloat] { oval(NSPoint(x: hc.x + hr * (x + 0.1), y: hc.y + hr * 0.02), hr * 0.18, hr * 0.2) }
|
|
1350
|
+
let b = NSBezierPath(); b.move(to: NSPoint(x: hc.x - hr * 0.12, y: hc.y - hr * 0.35)); b.line(to: NSPoint(x: hc.x + hr * 0.12, y: hc.y - hr * 0.35)); b.line(to: NSPoint(x: hc.x, y: hc.y - hr * 0.7)); b.close(); b.fill()
|
|
1351
|
+
} else {
|
|
1352
|
+
eyes(hc, hr, 0)
|
|
1353
|
+
}
|
|
1354
|
+
}
|
|
1355
|
+
|
|
1356
|
+
/** A lion's mane drawn as fur: leaf-shaped locks of uneven length, longest over the crown and nape, their tips curling back with the run. */
|
|
1357
|
+
func lionMane(_ hc: NSPoint, _ hr: CGFloat, sweep: CGFloat) {
|
|
1358
|
+
let c = NSPoint(x: hc.x - hr * 0.3, y: hc.y - hr * 0.05), n = 13
|
|
1359
|
+
let jag: [CGFloat] = [1.0, 0.86, 0.96, 0.8, 1.0, 0.9, 0.78] // fixed, so the locks do not flicker between frames
|
|
1360
|
+
oval(c, hr * 1.5, hr * 1.45)
|
|
1361
|
+
for i in 0..<n {
|
|
1362
|
+
let a = 2 * CGFloat.pi * CGFloat(i) / CGFloat(n) + 0.1
|
|
1363
|
+
let back = (1 - cos(a)) / 2 // 0 at the front, 1 at the back
|
|
1364
|
+
let len = hr * (1.95 + 0.6 * back) * jag[i % jag.count]
|
|
1365
|
+
let u = NSPoint(x: cos(a), y: sin(a)), w = NSPoint(x: -sin(a), y: cos(a))
|
|
1366
|
+
let wd = hr * 0.5, base = hr * 1.25
|
|
1367
|
+
func at(_ along: CGFloat, _ side: CGFloat) -> NSPoint { NSPoint(x: c.x + u.x * along + w.x * side, y: c.y + u.y * along + w.y * side) }
|
|
1368
|
+
// the tip curls toward the tail, more when running and more for the locks at the back
|
|
1369
|
+
var tip = at(len, 0); tip.x -= sweep * hr * (0.4 + 0.7 * back); tip.y -= sweep * hr * 0.2
|
|
1370
|
+
let l = NSBezierPath()
|
|
1371
|
+
l.move(to: at(base, wd))
|
|
1372
|
+
l.curve(to: tip, controlPoint1: at(len * 0.72, wd * 1.15), controlPoint2: NSPoint(x: (tip.x + at(len * 0.9, wd * 0.5).x) / 2, y: (tip.y + at(len * 0.9, wd * 0.5).y) / 2))
|
|
1373
|
+
l.curve(to: at(base, -wd), controlPoint1: at(len * 0.85, -wd * 0.3), controlPoint2: at(len * 0.6, -wd * 1.0))
|
|
1374
|
+
l.close(); l.fill()
|
|
1375
|
+
}
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
/** A feathered wing seen from the side: swept back from the root, longest feathers at the tip, foreshortened when level. */
|
|
1379
|
+
func featherWing(_ root: NSPoint, flap: CGFloat, span full: CGFloat, near: Bool) {
|
|
1380
|
+
let g = CGFloat.pi - flap * 1.05 - 0.15
|
|
1381
|
+
let span = full * (0.45 + 0.55 * abs(flap)) * (near ? 1 : 0.85)
|
|
1382
|
+
let u = NSPoint(x: cos(g), y: sin(g))
|
|
1383
|
+
var v = NSPoint(x: -u.y, y: u.x); if v.x > 0 { v = NSPoint(x: -v.x, y: -v.y) } // toward the tail
|
|
1384
|
+
func P(_ along: CGFloat, _ back: CGFloat) -> NSPoint { NSPoint(x: root.x + u.x * along + v.x * back, y: root.y + u.y * along + v.y * back) }
|
|
1385
|
+
let w = NSBezierPath()
|
|
1386
|
+
w.move(to: P(0, -1.0)); w.curve(to: P(span, 0.4), controlPoint1: P(span * 0.45, -1.5), controlPoint2: P(span * 0.85, -0.7))
|
|
1387
|
+
// rounded feather ends along the trailing edge
|
|
1388
|
+
for k in 0..<4 {
|
|
1389
|
+
let a = span * (1 - 0.2 * CGFloat(k)), b = span * (1 - 0.2 * CGFloat(k + 1))
|
|
1390
|
+
let depth = 1.4 + 0.45 * CGFloat(k)
|
|
1391
|
+
w.curve(to: P(b, depth + 0.5), controlPoint1: P(a - 0.1, depth + 1.0), controlPoint2: P(b + 0.6, depth + 1.3))
|
|
1392
|
+
}
|
|
1393
|
+
w.curve(to: P(-0.4, 2.2), controlPoint1: P(span * 0.15, 2.9), controlPoint2: P(0.2, 2.8))
|
|
1394
|
+
w.close()
|
|
1395
|
+
if near { // a thin gap around the near wing, so it stays apart from the body on the downstroke
|
|
1396
|
+
NSGraphicsContext.current?.compositingOperation = .clear
|
|
1397
|
+
w.lineWidth = 1.1; w.lineJoinStyle = .round; w.stroke()
|
|
1398
|
+
NSGraphicsContext.current?.compositingOperation = .sourceOver
|
|
1399
|
+
}
|
|
1400
|
+
w.fill()
|
|
1401
|
+
if near { // a line of coverts, cut in, so the near wing reads apart from the body
|
|
1402
|
+
NSGraphicsContext.current?.compositingOperation = .clear
|
|
1403
|
+
let l = NSBezierPath(); l.lineWidth = 0.5; l.lineCapStyle = .round
|
|
1404
|
+
l.move(to: P(span * 0.1, 0.9)); l.curve(to: P(span * 0.7, 0.9), controlPoint1: P(span * 0.3, 1.5), controlPoint2: P(span * 0.5, 1.4)); l.stroke()
|
|
1405
|
+
NSGraphicsContext.current?.compositingOperation = .sourceOver
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
|
|
1409
|
+
/** A frog hops: it crouches, kicks its long hind legs straight out behind, flies in an arc and lands on its front feet. */
|
|
1410
|
+
func frog(frame: Int, idle: Bool) {
|
|
1411
|
+
let n = GAL.count, i = frame % n, ground: CGFloat = 1.3
|
|
1412
|
+
// phase of the hop: 0 crouched, 1 fully stretched in the air
|
|
1413
|
+
let ext: [CGFloat] = [0.0, 0.7, 1.0, 0.85, 0.55, 0.3, 0.1, 0.0]
|
|
1414
|
+
let hgt: [CGFloat] = [0.0, 1.6, 4.2, 5.4, 4.8, 2.8, 0.6, 0.0]
|
|
1415
|
+
let tilt: [CGFloat] = [0.0, 0.38, 0.3, 0.12, -0.08, -0.25, -0.3, -0.05]
|
|
1416
|
+
let e = idle ? 0 : ext[i], h = idle ? 0.15 * sin(CGFloat(frame) * 0.8) : hgt[i], a = idle ? 0 : tilt[i]
|
|
1417
|
+
let c = NSPoint(x: 15.0, y: ground + 3.4 + h)
|
|
1418
|
+
func R(_ x: CGFloat, _ y: CGFloat) -> NSPoint { rot(NSPoint(x: c.x + x, y: c.y + y), c, a) }
|
|
1419
|
+
let hip = R(-3.4, -0.6)
|
|
1420
|
+
// hind leg: folded in a Z when crouched, a straight line back when stretched
|
|
1421
|
+
for (near, w) in [(false, 0.85), (true, 1.0)] as [(Bool, CGFloat)] {
|
|
1422
|
+
let dz: CGFloat = near ? 0 : 0.5
|
|
1423
|
+
let knee = NSPoint(x: hip.x + 2.6 * (1 - e) - 3.6 * e, y: hip.y - 1.0 * (1 - e) - 1.4 * e + dz)
|
|
1424
|
+
var foot = NSPoint(x: knee.x - 3.4 * (1 - e) - 3.8 * e, y: max(ground, knee.y - 1.6 * (1 - e) - 1.6 * e))
|
|
1425
|
+
if h > 0.5 { foot.y = knee.y - 1.6 * (1 - e) - 1.4 * e }
|
|
1426
|
+
taper(hip, knee, 2.4 * w, 1.6 * w); taper(knee, foot, 1.6 * w, 1.0 * w)
|
|
1427
|
+
oval(NSPoint(x: foot.x - 0.6, y: foot.y), 1.4 * w, 0.6)
|
|
1428
|
+
}
|
|
1429
|
+
// body: a wide, low pear, with the head part of it
|
|
1430
|
+
oval(R(-0.6, 0), 4.6, 3.0)
|
|
1431
|
+
oval(R(2.6, 0.8), 3.4, 2.6)
|
|
1432
|
+
// front legs reach forward when landing
|
|
1433
|
+
let sh = R(2.4, -1.2), reach = idle ? 0 : max(0, -a) * 2.4 + (i == 0 || i == 7 ? 0.4 : 0)
|
|
1434
|
+
for (near, w) in [(false, 0.8), (true, 1.0)] as [(Bool, CGFloat)] {
|
|
1435
|
+
let foot = NSPoint(x: sh.x + 0.8 + reach + (near ? 0 : -0.6), y: max(ground, sh.y - 2.8 + (h > 1.2 ? 1.2 : 0)))
|
|
1436
|
+
taper(sh, foot, 1.5 * w, 1.0 * w); oval(NSPoint(x: foot.x + 0.4, y: foot.y), 1.0 * w, 0.5)
|
|
1437
|
+
}
|
|
1438
|
+
// bulging eyes on top of the head
|
|
1439
|
+
let e1 = R(3.6, 3.0), e2 = R(1.4, 3.1)
|
|
1440
|
+
oval(e1, 1.55, 1.5); oval(e2, 1.35, 1.35)
|
|
1441
|
+
NSGraphicsContext.current?.compositingOperation = .clear
|
|
1442
|
+
oval(e1, 1.0, 1.0); oval(e2, 0.85, 0.85)
|
|
1443
|
+
line2(R(3.0, -0.2), R(5.4, 0.6), 0.45) // a wide mouth
|
|
1444
|
+
NSGraphicsContext.current?.compositingOperation = .sourceOver
|
|
1445
|
+
oval(NSPoint(x: e1.x + 0.35, y: e1.y), 0.5, 0.55); oval(NSPoint(x: e2.x + 0.3, y: e2.y), 0.42, 0.48)
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
/** Two legs: a duck waddles with its tail up and a flat bill; a chick is a round ball on quick little legs, flapping its stubs. */
|
|
1449
|
+
func biped(chick: Bool, frame: Int, idle: Bool) {
|
|
1450
|
+
let n = GAL.count, ph = 2 * CGFloat.pi * CGFloat(frame % n) / CGFloat(n)
|
|
1451
|
+
let ground: CGFloat = 1.3
|
|
1452
|
+
let bob: CGFloat = idle ? 0.15 * sin(ph) : abs(sin(ph)) * (chick ? 1.1 : 0.7)
|
|
1453
|
+
let roll: CGFloat = idle ? 0 : (chick ? 0.08 : 0.12) * sin(ph)
|
|
1454
|
+
let legLen: CGFloat = chick ? 4.2 : 3.8
|
|
1455
|
+
let c = NSPoint(x: 14.6, y: ground + legLen + (chick ? 4.0 : 3.0) + bob)
|
|
1456
|
+
func R(_ x: CGFloat, _ y: CGFloat) -> NSPoint { rot(NSPoint(x: c.x + x, y: c.y + y), c, roll) }
|
|
1457
|
+
// legs: one in front, one behind, swapping each half stride
|
|
1458
|
+
for k in 0..<2 {
|
|
1459
|
+
let sw = idle ? 0 : sin(ph + CGFloat(k) * .pi) * (chick ? 0.7 : 0.5)
|
|
1460
|
+
let hip = R(chick ? 0.2 : 0.6, chick ? -3.6 : -2.4)
|
|
1461
|
+
let foot = NSPoint(x: hip.x + sin(sw) * legLen, y: max(ground, hip.y - cos(sw) * legLen + (idle ? 0 : max(0, -cos(ph + CGFloat(k) * .pi)) * 1.2)))
|
|
1462
|
+
line2(hip, foot, chick ? 0.75 : 1.0)
|
|
1463
|
+
if chick { line2(foot, NSPoint(x: foot.x + 1.4, y: foot.y), 0.6); line2(foot, NSPoint(x: foot.x + 1.0, y: foot.y + 0.7), 0.5) }
|
|
1464
|
+
else { let w = NSBezierPath(); w.move(to: NSPoint(x: foot.x - 0.4, y: foot.y + 0.3)); w.line(to: NSPoint(x: foot.x + 2.2, y: foot.y + 0.1)); w.line(to: NSPoint(x: foot.x + 1.8, y: foot.y - 0.6)); w.line(to: NSPoint(x: foot.x - 0.6, y: foot.y - 0.4)); w.close(); w.fill() }
|
|
1465
|
+
}
|
|
1466
|
+
var hc: NSPoint, hr: CGFloat
|
|
1467
|
+
if chick {
|
|
1468
|
+
oval(c, 5.0, 4.8) // the ball
|
|
1469
|
+
hc = R(1.6, 2.4); hr = 3.2
|
|
1470
|
+
oval(hc, hr, hr)
|
|
1471
|
+
// a tuft on top
|
|
1472
|
+
line2(R(1.0, 5.4), R(0.2, 7.0), 0.7); line2(R(1.6, 5.5), R(1.9, 7.1), 0.7)
|
|
1473
|
+
// a beak
|
|
1474
|
+
let b = NSBezierPath(); b.move(to: R(4.4, 3.0)); b.line(to: R(6.6, 2.3)); b.line(to: R(4.4, 1.6)); b.close(); b.fill()
|
|
1475
|
+
// stubby wings flap fast
|
|
1476
|
+
let fl = idle ? 0.2 : 0.5 + 0.5 * sin(ph * 2)
|
|
1477
|
+
let wr = R(-2.4, 0.6)
|
|
1478
|
+
let w = NSBezierPath(); w.move(to: NSPoint(x: wr.x + 1.2, y: wr.y + 0.6)); w.line(to: NSPoint(x: wr.x - 2.6, y: wr.y + 0.4 + fl * 2.6)); w.line(to: NSPoint(x: wr.x - 1.6, y: wr.y - 1.0)); w.close(); w.fill()
|
|
1479
|
+
} else {
|
|
1480
|
+
// body: a boat with the tail turned up
|
|
1481
|
+
let b = NSBezierPath()
|
|
1482
|
+
b.move(to: R(-6.4, 2.2))
|
|
1483
|
+
b.curve(to: R(3.8, 0.4), controlPoint1: R(-4.0, 1.2), controlPoint2: R(0.6, 2.6))
|
|
1484
|
+
b.curve(to: R(-1.0, -3.4), controlPoint1: R(5.4, -2.0), controlPoint2: R(2.4, -3.6))
|
|
1485
|
+
b.curve(to: R(-6.4, 2.2), controlPoint1: R(-4.6, -3.2), controlPoint2: R(-5.6, -1.0))
|
|
1486
|
+
b.close(); b.fill()
|
|
1487
|
+
line2(R(2.6, 0.6), R(3.4, 4.0), 2.6) // neck
|
|
1488
|
+
hc = R(3.6, 5.0); hr = 2.6
|
|
1489
|
+
oval(hc, hr, hr * 0.95)
|
|
1490
|
+
// a flat, rounded bill
|
|
1491
|
+
let bl = NSBezierPath(roundedRect: NSRect(x: hc.x + hr * 0.6, y: hc.y - hr * 0.6, width: hr * 1.25, height: hr * 0.55), xRadius: hr * 0.27, yRadius: hr * 0.27); bl.fill()
|
|
1492
|
+
// a wing drawn as a cut line on the side, lifting a little each step
|
|
1493
|
+
NSGraphicsContext.current?.compositingOperation = .clear
|
|
1494
|
+
let w = NSBezierPath(); w.lineWidth = 0.55; w.lineCapStyle = .round
|
|
1495
|
+
w.move(to: R(1.8, 0.6)); w.curve(to: R(-4.2, 0.6 + (idle ? 0 : 0.8 * max(0, sin(ph)))), controlPoint1: R(0.4, -2.2), controlPoint2: R(-3.0, -1.6)); w.stroke()
|
|
1496
|
+
NSGraphicsContext.current?.compositingOperation = .sourceOver
|
|
1497
|
+
}
|
|
1498
|
+
eyes(hc, hr, roll, chick ? 0.9 : 0.85)
|
|
1499
|
+
}
|
|
1500
|
+
|
|
1501
|
+
/** The ghost, for a member with no data: a see-through sheet that floats instead of running, its hem rippling. */
|
|
1502
|
+
func ghost(frame: Int, idle: Bool) {
|
|
1503
|
+
let n = GAL.count, ph = 2 * CGFloat.pi * CGFloat(frame % n) / CGFloat(n)
|
|
1504
|
+
guard let ctx = NSGraphicsContext.current?.cgContext else { return }
|
|
1505
|
+
ctx.saveGState(); ctx.setAlpha(0.62); ctx.beginTransparencyLayer(auxiliaryInfo: nil)
|
|
1506
|
+
let bob: CGFloat = idle ? 0.5 * sin(ph) : 1.0 * sin(ph)
|
|
1507
|
+
let lean: CGFloat = idle ? 0 : -0.22 // leaning into the direction it drifts
|
|
1508
|
+
let c = NSPoint(x: 16.0, y: 11.0 + bob)
|
|
1509
|
+
func R(_ x: CGFloat, _ y: CGFloat) -> NSPoint { rot(NSPoint(x: c.x + x, y: c.y + y), c, lean) }
|
|
1510
|
+
let p = NSBezierPath()
|
|
1511
|
+
p.move(to: R(-5.2, 0))
|
|
1512
|
+
p.curve(to: R(5.2, 0), controlPoint1: R(-5.2, 8.2), controlPoint2: R(5.2, 8.2)) // the dome of the head
|
|
1513
|
+
p.line(to: R(5.0, -5.2))
|
|
1514
|
+
// the hem: scallops that travel backward, and a wisp trailing behind
|
|
1515
|
+
let waves = 4, w0 = R(5.0, -5.2)
|
|
1516
|
+
var prev = w0
|
|
1517
|
+
for k in 1...waves {
|
|
1518
|
+
let x = 5.0 - 10.6 * CGFloat(k) / CGFloat(waves), dip = -6.6 - 0.9 * sin(ph * 1.0 + CGFloat(k) * 1.4)
|
|
1519
|
+
let to = R(x, -5.2 - (k == waves ? 1.6 : 0))
|
|
1520
|
+
let mid = R((x + 5.0 - 10.6 * CGFloat(k - 1) / CGFloat(waves)) / 2, dip)
|
|
1521
|
+
p.curve(to: to, controlPoint1: NSPoint(x: (prev.x + mid.x) / 2, y: mid.y), controlPoint2: NSPoint(x: (to.x + mid.x) / 2, y: mid.y))
|
|
1522
|
+
prev = to
|
|
1523
|
+
}
|
|
1524
|
+
let wisp = R(-8.6 - (idle ? 0 : 0.8 * sin(ph)), -5.6 + 1.2 * sin(ph + 1))
|
|
1525
|
+
p.curve(to: wisp, controlPoint1: R(-6.0, -6.6), controlPoint2: R(-7.4, -6.4))
|
|
1526
|
+
p.curve(to: R(-5.2, 0), controlPoint1: R(-7.0, -4.4), controlPoint2: R(-5.6, -2.6))
|
|
1527
|
+
p.close(); p.fill()
|
|
1528
|
+
// little arms reaching forward
|
|
1529
|
+
let arm = idle ? 0 : 0.5 * sin(ph * 2)
|
|
1530
|
+
line2(R(4.4, -0.6), R(7.0, 0.6 + arm), 1.5); line2(R(-4.0, -0.4), R(-5.8, 0.8 - arm), 1.3)
|
|
1531
|
+
// hollow eyes and a small round mouth
|
|
1532
|
+
NSGraphicsContext.current?.compositingOperation = .clear
|
|
1533
|
+
oval(R(2.0, 3.2), 1.05, 1.35); oval(R(-0.6, 3.3), 0.9, 1.2)
|
|
1534
|
+
oval(R(1.0, 0.9), 0.6, 0.75)
|
|
1535
|
+
NSGraphicsContext.current?.compositingOperation = .sourceOver
|
|
1536
|
+
ctx.endTransparencyLayer(); ctx.restoreGState()
|
|
1537
|
+
}
|
|
1538
|
+
|
|
907
1539
|
// ---------- text ----------
|
|
908
1540
|
func memText(_ mb: Double?) -> String { guard let mb = mb else { return "-" }; return mb < 1024 ? "\(Int(mb.rounded())) MB" : String(format: "%.1f GB", mb / 1024) }
|
|
909
1541
|
func pct1(_ v: Double) -> String { String(format: "%.1f%%", v) }
|
|
@@ -2257,6 +2889,9 @@ struct DashboardView: View {
|
|
|
2257
2889
|
}.padding(.horizontal, 10).padding(.vertical, 7).background(RoundedRectangle(cornerRadius: 8).fill(pal.tile)).opacity(cleaning && fixed ? 0.6 : 1)
|
|
2258
2890
|
if cleaning && !fixed {
|
|
2259
2891
|
Pressable(radius: 8, action: { if on { picked.remove(it.id) } else { picked.insert(it.id) } }) { row }.help(it.name)
|
|
2892
|
+
} else if !cleaning, let sid = model.leftoverSession[it.id] {
|
|
2893
|
+
Pressable(radius: 8, action: { resumeSession(sid, fallbackDir: model.leftoverPids[it.id]?.first.flatMap { procCwd($0.pid) }) }) { row }
|
|
2894
|
+
.help("\(it.name): 누르면 이 프로세스를 띄운 세션을 새 터미널에서 다시 엽니다. 무엇을 하던 세션인지 보고 끌지 정하십시오")
|
|
2260
2895
|
} else {
|
|
2261
2896
|
row.help(cleaning && fixed ? "앱, 가상 머신, 데이터베이스는 다른 작업이 쓰고 있을 수 있어 여기서 끄지 않습니다. 그 프로그램에서 직접 끄십시오" : it.name)
|
|
2262
2897
|
}
|
|
@@ -2696,13 +3331,32 @@ struct PanelView: View {
|
|
|
2696
3331
|
|
|
2697
3332
|
// ---------- the menu bar item and its window ----------
|
|
2698
3333
|
final class FloatPanel: NSPanel { override var canBecomeKey: Bool { true } }
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
3334
|
+
/**
|
|
3335
|
+
* The Dock icon while the dashboard is open: the member's town animal, white on a coral rounded square, the same
|
|
3336
|
+
* species that runs in the menu bar. It is one still frame, redrawn only when the grade changes; a running Dock icon
|
|
3337
|
+
* would spend CPU and pull the eye away from the dashboard. Drawn on the macOS icon grid (an 824 square in 1024).
|
|
3338
|
+
*/
|
|
3339
|
+
func dockIcon(_ grade: String?) -> NSImage {
|
|
3340
|
+
let sp = runnerSpecies(grade)
|
|
3341
|
+
// a frame that reads as that animal at rest in motion: wings up for fliers, mid-leap for the frog, a stride otherwise
|
|
3342
|
+
let frame = sp.fly > 0 || sp.x.contains("wings") ? 2 : sp.kind == 4 ? 2 : sp.kind == 7 ? 0 : sp.kind == 5 || sp.kind == 6 ? 1 : 7
|
|
3343
|
+
let still = runner(sp, frame: frame, idle: false)
|
|
3344
|
+
return NSImage(size: NSSize(width: 512, height: 512), flipped: false) { r in
|
|
3345
|
+
let k = r.width / 1024
|
|
3346
|
+
let body = NSRect(x: 100 * k, y: 100 * k, width: 824 * k, height: 824 * k)
|
|
3347
|
+
let shape = NSBezierPath(roundedRect: body, xRadius: 185 * k, yRadius: 185 * k)
|
|
3348
|
+
let top = NSColor(srgbRed: 0.941, green: 0.573, blue: 0.416, alpha: 1), bottom = NSColor(srgbRed: 0.788, green: 0.341, blue: 0.235, alpha: 1)
|
|
3349
|
+
NSGraphicsContext.saveGraphicsState()
|
|
3350
|
+
let sh = NSShadow(); sh.shadowColor = NSColor.black.withAlphaComponent(0.28); sh.shadowBlurRadius = 22 * k; sh.shadowOffset = NSSize(width: 0, height: -10 * k); sh.set()
|
|
3351
|
+
top.setFill(); shape.fill()
|
|
3352
|
+
NSGraphicsContext.restoreGraphicsState()
|
|
3353
|
+
NSGradient(starting: top, ending: bottom)?.draw(in: shape, angle: -90)
|
|
3354
|
+
// a soft shadow on the ground under the animal
|
|
3355
|
+
NSColor(srgbRed: 0.478, green: 0.180, blue: 0.118, alpha: 0.35).setFill()
|
|
3356
|
+
NSBezierPath(ovalIn: NSRect(x: 262 * k, y: 262 * k, width: 500 * k, height: 44 * k)).fill()
|
|
3357
|
+
let w = 700 * k, h = w * still.size.height / still.size.width
|
|
3358
|
+
let white = NSImage(size: still.size, flipped: false) { rr in still.draw(in: rr); NSColor.white.set(); rr.fill(using: .sourceAtop); return true }
|
|
3359
|
+
white.draw(in: NSRect(x: r.midX - w / 2 + 10 * k, y: 250 * k, width: w, height: h))
|
|
2706
3360
|
return true
|
|
2707
3361
|
}
|
|
2708
3362
|
}
|
|
@@ -2757,7 +3411,7 @@ final class App: NSObject {
|
|
|
2757
3411
|
// A menu bar app has no Dock icon, so a dashboard that slipped behind other windows could only be found through the
|
|
2758
3412
|
// menu bar again. While the window is open the app is a regular one: Dock icon, app switcher, and a click on either brings it back.
|
|
2759
3413
|
NSApp.setActivationPolicy(.regular)
|
|
2760
|
-
NSApp.applicationIconImage = dockIcon()
|
|
3414
|
+
dockGrade = model.snap?.animal?.grade; NSApp.applicationIconImage = dockIcon(dockGrade)
|
|
2761
3415
|
if NSApp.mainMenu == nil { NSApp.mainMenu = dashboardMenu() }
|
|
2762
3416
|
NSApp.activate(ignoringOtherApps: true)
|
|
2763
3417
|
if dash?.isMiniaturized == true { dash?.deminiaturize(nil) }
|
|
@@ -2813,15 +3467,19 @@ final class App: NSObject {
|
|
|
2813
3467
|
b.attributedTitle = out
|
|
2814
3468
|
b.toolTip = model.sysCpu != nil ? String(format: "기기 전체 CPU %.0f%%, 그중 AI 세션 %.0f%%. 세션 %d개 실행 중", (model.sysCpu ?? 0) * 100, model.share(nil), s.totals.sessions) : "작업 중인 세션 수 / 실행 중인 세션 수"
|
|
2815
3469
|
}
|
|
3470
|
+
var dockGrade: String? = nil // the grade the Dock icon was drawn for
|
|
2816
3471
|
func animate() {
|
|
3472
|
+
if NSApp.activationPolicy() == .regular, model.snap?.animal?.grade != dockGrade {
|
|
3473
|
+
dockGrade = model.snap?.animal?.grade; NSApp.applicationIconImage = dockIcon(dockGrade)
|
|
3474
|
+
}
|
|
2817
3475
|
// RunCat's rule, on the same thing RunCat measures: the whole machine. A runner that strolls while the machine is
|
|
2818
3476
|
// flat out, because the agent sessions' own share happens to be small, reads as wrong.
|
|
2819
3477
|
let load = min(100, max(0, (model.sysCpu ?? 0) * 100))
|
|
2820
|
-
item.button?.image = runner(frame: frame, idle: load < 5)
|
|
3478
|
+
item.button?.image = runner(runnerSpecies(model.snap?.animal?.grade), frame: frame, idle: load < 5)
|
|
2821
3479
|
frame += 1
|
|
2822
3480
|
// RunCat's own curve: one stride takes (100 - load) / 60 seconds, so the pace climbs steeply as the machine fills up.
|
|
2823
3481
|
// The stride is spread over this runner's poses, and a frame never comes faster than a display shows it.
|
|
2824
|
-
let gap = load < 5 ? 0.8 : max(1.0 / 60, (100 - load) / 60 / Double(
|
|
3482
|
+
let gap = load < 5 ? 0.8 : max(1.0 / 60, (100 - load) / 60 / Double(GAL.count))
|
|
2825
3483
|
DispatchQueue.main.asyncAfter(deadline: .now() + gap) { [weak self] in self?.animate() }
|
|
2826
3484
|
}
|
|
2827
3485
|
func poll() {
|
|
@@ -2947,20 +3605,21 @@ if let prefix = selftest {
|
|
|
2947
3605
|
fitCheck("STATUS")
|
|
2948
3606
|
render(PanelView(model: main.model, prefs: Prefs(), nav: Nav(), book: RuleBook(), still: true), "\(prefix)-panel-dark.png")
|
|
2949
3607
|
render(PanelView(model: main.model, prefs: Prefs(), nav: Nav(), book: RuleBook(), still: true), "\(prefix)-panel-light.png", dark: false)
|
|
2950
|
-
|
|
2951
|
-
let
|
|
2952
|
-
let
|
|
2953
|
-
|
|
2954
|
-
NSColor(white: 0.14, alpha: 1).setFill(); NSRect(x: 0, y: 0, width: RW * k * CGFloat(n), height: RH * k).fill()
|
|
2955
|
-
for row in
|
|
3608
|
+
// every species: the eight running frames and one at rest, white on the dark bar
|
|
3609
|
+
let n = GAL.count + 1, k: CGFloat = 4, rows = SPECIES.count
|
|
3610
|
+
let RW = runner(SPECIES[0], frame: 0, idle: true).size.width, RH = runner(SPECIES[0], frame: 0, idle: true).size.height
|
|
3611
|
+
let sheet = NSImage(size: NSSize(width: RW * k * CGFloat(n), height: RH * k * CGFloat(rows)), flipped: false) { _ in
|
|
3612
|
+
NSColor(white: 0.14, alpha: 1).setFill(); NSRect(x: 0, y: 0, width: RW * k * CGFloat(n), height: RH * k * CGFloat(rows)).fill()
|
|
3613
|
+
for (row, sp) in SPECIES.enumerated() {
|
|
2956
3614
|
for i in 0..<n {
|
|
2957
|
-
let im = runner(frame: i
|
|
2958
|
-
let tinted = NSImage(size: im.size, flipped: false) { r in im.draw(in: r);
|
|
2959
|
-
tinted.draw(in: NSRect(x: CGFloat(i) * RW * k, y:
|
|
3615
|
+
let im = runner(sp, frame: i % GAL.count, idle: i == GAL.count)
|
|
3616
|
+
let tinted = NSImage(size: im.size, flipped: false) { r in im.draw(in: r); NSColor.white.set(); r.fill(using: .sourceAtop); return true }
|
|
3617
|
+
tinted.draw(in: NSRect(x: CGFloat(i) * RW * k, y: CGFloat(rows - 1 - row) * RH * k, width: RW * k, height: RH * k))
|
|
2960
3618
|
}
|
|
2961
3619
|
}
|
|
2962
3620
|
return true
|
|
2963
3621
|
}
|
|
3622
|
+
print("RUNNER species \(SPECIES.count) | drawn now: \(runnerSpecies(main.model.snap?.animal?.grade).id) (grade \(main.model.snap?.animal?.grade ?? "none"))")
|
|
2964
3623
|
png(sheet, "\(prefix)-runner.png")
|
|
2965
3624
|
liveShot(main.hosting, "\(prefix)-panel-live.png")
|
|
2966
3625
|
if let b = main.item.button { liveShot(b, "\(prefix)-item-live.png", forceDark: true) } // the menu bar item itself, warning mark included
|
|
@@ -3088,6 +3747,8 @@ func dashboardTest(_ prefix: String) {
|
|
|
3088
3747
|
DispatchQueue.main.asyncAfter(deadline: .now() + 4.0) {
|
|
3089
3748
|
let m = main.model
|
|
3090
3749
|
print("DASHBOARD window \(main.dash.map { "\(Int($0.frame.width))x\(Int($0.frame.height)) visible \($0.isVisible)" } ?? "none") | panel closed \(!main.isOpen) | asked for detail \(m.wantDetail) | sessions \(m.snap?.sessions.count ?? 0) with detail \(m.snap?.sessions.filter { $0.detail != nil }.count ?? 0)")
|
|
3750
|
+
if let icon = NSApp.applicationIconImage { png(icon, "\(prefix)-dock.png") }
|
|
3751
|
+
print("DOCK icon drawn for grade \(main.dockGrade ?? "none") (species \(runnerSpecies(main.dockGrade).id))")
|
|
3091
3752
|
print("DOCK regular app while the dashboard is open: \(NSApp.activationPolicy() == .regular) | icon set \(NSApp.applicationIconImage != nil) | menu \(NSApp.mainMenu != nil) | reopen handler \(NSApp.delegate is App)")
|
|
3092
3753
|
print("STARTED BY " + (m.parentSession.isEmpty ? "none" : m.parentSession.map { c, up in "\(m.snap?.sessions.first { $0.pid == c }?.name ?? "\(c)") <- \(m.snap?.sessions.first { $0.pid == up }?.name ?? "\(up)")" }.sorted().joined(separator: " | ")))
|
|
3093
3754
|
print("PHASE " + (m.snap?.sessions ?? []).map { s in "\(s.name ?? s.agent) \(m.phase(s)) [" + m.working(s, max: 3).map { "\($0.name) cpu \(pct1($0.w.cpu * 100)) gpu \(pct1($0.w.gpu * 100)) \(memText($0.w.mem))" }.joined(separator: "; ") + "]" }.joined(separator: " | "))
|
|
@@ -3110,6 +3771,8 @@ func dashboardTest(_ prefix: String) {
|
|
|
3110
3771
|
print("DASHBOARD history samples \(m.samples.count) per-session \(m.hist.values.map { $0.count }.sorted())")
|
|
3111
3772
|
if let v = main.dash?.contentView { liveShot(v, "\(prefix)-dashboard-live.png") }
|
|
3112
3773
|
print("LEFTOVER lines \(m.leftoverItems.count) | never cleaned (apps, virtual machines, databases): \(m.leftoverItems.filter { m.leftoverShared.contains($0.id) }.map { $0.name }.joined(separator: ", "))")
|
|
3774
|
+
// which session each line would reopen, and the folder that session worked in (the id itself is not printed)
|
|
3775
|
+
print("LEFTOVER sessions " + m.leftoverItems.map { it in "\(it.name)=" + (m.leftoverSession[it.id].map { sessionCwd($0).map { ($0 as NSString).lastPathComponent } ?? "no transcript" } ?? "none") }.joined(separator: ", "))
|
|
3113
3776
|
if let target = selftestClean {
|
|
3114
3777
|
let hit = m.leftoverItems.first { $0.name == target }
|
|
3115
3778
|
print("CLEAN target '\(target)': \(hit.map { "\($0.n) process(es)" } ?? "not listed") | protected \(m.leftoverShared.contains(target))")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sprag-cli",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.134.0",
|
|
4
4
|
"description": "The delegation layer for Claude Code and Codex: each task goes to the model and effort that fits it, down to cheaper models for lookups and up to higher effort when a cheaper run would miss, backed by public replay cases, with a live statusline and team rules for Pro and Enterprise.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|