This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import SwiftUI | |
import AVFoundation | |
struct SystemSoundWheelPicker: View { | |
@State private var sounds: [SystemSoundID] = [] | |
@State private var playingID = -1 | |
var body: some View { | |
Picker("", selection: $playingID) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import AVFoundation | |
struct TestView: View { | |
var body: some View { | |
Button("Play1") { | |
AudioServicesPlaySystemSound(1000) | |
} | |
Divider() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Observable final class Sound: Identifiable { | |
var id: SystemSoundID | |
var duration: Double | |
var playing: Bool | |
var valid: Bool { self.duration > 0.01 } | |
init(_ id: Int, _ duration: Double, _ playing: Bool) { | |
self.id = SystemSoundID(id) | |
self.duration = duration |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
@Observable final class ScheduledTimer { | |
var elapsed = TimeInterval.zero | |
private var timer: Timer? | |
func start() { | |
timer = Timer.scheduledTimer(withTimeInterval: 0.001, repeats: true) { _ in | |
self.elapsed += 0.001 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct TestView: View { | |
var body: some View { | |
VStack { | |
Text("top") | |
Text("bottom") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
// inspiered by | |
// lifegame/swift/lifegame.swift at master · tex2e/lifegame | |
// https://github.com/tex2e/lifegame/blob/master/swift/lifegame.swift | |
@Observable final class LifeGame { | |
var field: [[Int]] = [] | |
var generation = 0 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let d2: [[String]] = [ | |
// x (col) → | |
["あ", "い", "う", "え", "お"], | |
["か", "き", "く", "け", "こ"], | |
["さ", "し", "す", "せ", "そ"] | |
] | |
print(d2) | |
// [["あ", "い", "う", "え", "お"], ["か", "き", "く", "け", "こ"], ["さ", "し", "す", "せ", "そ"]] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Array where Element: Collection, Element.Index == Int { | |
func showTable() { | |
transposed() | |
.map { $0.map { "\($0)" } } | |
.map { | |
let max = $0.map { $0.countAsHalfWidth }.max()! | |
return $0.map { $0.padding(length: max) } | |
} | |
.transposed() | |
.map { "| " + $0.joined(separator: " | ") + " |" } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
@Observable final class Pong { | |
var squares: [Square] = [] | |
var balls: [Ball] = [] | |
var dayCount = 0 | |
var nightCount = 0 | |
var generation = 0 | |
private var cols = 0 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Collection where Element: Collection, | |
Self.Index == Int, Element.Index == Int { | |
func transposed1() -> [[Element.Element]] { | |
let cols = 0 ..< (self.first?.count ?? 0) | |
let rows = 0 ..< self.count | |
var result: [[Element.Element]] = [] | |
for col in cols { | |
var newRow: [Element.Element] = [] | |
for row in rows { |