Skip to content

Instantly share code, notes, and snippets.

View Koshimizu-Takehito's full-sized avatar
🏝️

takehito Koshimizu-Takehito

🏝️
View GitHub Profile
import SwiftUI
struct ContentView: View {
var body: some View {
TextShape(sample)
.fill(.orange)
.stroke(.blue, lineWidth: 2)
}
var sample: AttributedString {
@Koshimizu-Takehito
Koshimizu-Takehito / VisualEffect3.swift
Created April 12, 2025 10:59
visualEffectモディファイア
import SwiftUI
struct ContentView: View {
var body: some View {
GeometryReader { geometry in
let scrollViewFrame = geometry.frame(in: .local)
ScrollView {
ForEach(0..<1000) { offset in
RowContent(offset: offset, scrollViewFrame: scrollViewFrame)
}
@Koshimizu-Takehito
Koshimizu-Takehito / MazeGenerator.swift
Last active April 12, 2025 05:23
迷路生成ロジック
import Combine
import Foundation
// MARK: - MazeGenerator (Model)
/// An actor that generates a maze using a depth-first search (DFS) based approach.
/// 深さ優先探索 (DFS) ベースのアルゴリズムを用いて迷路を生成する。
///
/// This actor provides an async stream of snapshots (`MazeGenerator.Snapshot`) so that observers
/// can track the maze's state and generation progress in real time.
@Koshimizu-Takehito
Koshimizu-Takehito / nvironmentValuesSample2.swift
Created March 29, 2025 08:44
EnvironmentValuesが大域変数ではないことを示すサンプルコード2
import SwiftUI
extension EnvironmentValues {
@Entry var customStringValue = "Goodbye, world!"
}
struct ContentView: View {
var body: some View {
RepRepresentable()
.environment(\.customStringValue, "Hello, world!")
@Koshimizu-Takehito
Koshimizu-Takehito / EnvironmentValuesSample1.swift
Created March 29, 2025 08:42
EnvironmentValuesが大域変数ではないことを示すサンプルコード
import SwiftUI
extension EnvironmentValues {
@Entry var myColor = Color.blue
}
struct ScreenX: View {
@Environment(\.myColor) var myColor: Color
var body: some View {
@Koshimizu-Takehito
Koshimizu-Takehito / FocusState.swift
Created March 28, 2025 01:59
FocusStateのサンプル
import SwiftUI
// MARK: - ContentView
struct ContentView: View {
var body: some View {
MyForm()
.frame(maxHeight: .infinity, alignment: .top)
.padding()
.padding(.top)
@Koshimizu-Takehito
Koshimizu-Takehito / Polygon.swift
Last active March 21, 2025 02:34
多角形のグラデーション塗りつぶし
import SwiftUI
struct ContentView: View {
@State var vertex = 6
@State var roundness: Double = 0.5
var body: some View {
ZStack {
Polygon(vertex: vertex, roundness: roundness)
.fill(gradient)
@Koshimizu-Takehito
Koshimizu-Takehito / CollisionAnimation.swift
Created March 15, 2025 08:53
壁にぶつかったら色が変わるやつ
import SwiftUI
struct ContentView: View {
var body: some View {
CollisionAnimationView(speed: .init(dx: 100, dy: 140))
}
}
struct CollisionAnimationView: View {
var speed: CGVector
@Koshimizu-Takehito
Koshimizu-Takehito / SolarSystemView2.swift
Last active March 14, 2025 07:53
地動説と天動説のアニメーション
import SwiftUI
struct Star: Hashable, Identifiable {
var id = UUID()
var color: Color
var speed: Double
static var sun: Star {
Star(color: .red.mix(with: .orange, by: 0.2), speed: 1)
}
@Koshimizu-Takehito
Koshimizu-Takehito / ContentView.swift
Created March 9, 2025 09:24
表示中のピクセルデータからボタンの色を切り替える
import SwiftUI
struct ContentView: View {
@State private var image = UIImage()
@State private var buttonRect = CGRect()
@State private var isBrightBackground = false
@State private var viewID = UUID()
var body: some View {
NavigationStack {