Skip to content

Instantly share code, notes, and snippets.

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

takehito Koshimizu-Takehito

🏝️
View GitHub Profile
@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 {
@Koshimizu-Takehito
Koshimizu-Takehito / SolarSystem.swift
Created March 8, 2025 14:49
地動説っぽいアニメーション
import SwiftUI
struct ContentView: View {
@State var start: Date = .now
var body: some View {
TimelineView(.animation) { context in
let progress = context.date.timeIntervalSince(start) / 10
ZStack {
Sphere(color: .red).frame(width: 30)
@Koshimizu-Takehito
Koshimizu-Takehito / CountdownView.swift
Last active June 15, 2025 19:39
カウントダウンアニメーション
import SwiftUI
// https://x.com/TAAT626/status/1895841081365053901
// https://gist.github.com/TAATHub/8f9e7d987c82ef0eea62d2e420d51144
struct CountdownView: View {
@State private var counter = Counter()
var body: some View {
let radius = 120.0
ZStack {
@Koshimizu-Takehito
Koshimizu-Takehito / InfiniteScrollView.swift
Last active June 15, 2025 19:39
ページング無しの循環スクロールビュー
import SwiftUI
// MARK: - ContentView
struct ContentView: View {
private var items: [Int] = (1...5).map(\.self)
@State private var numberOfDisplays = 5
@State private var showsIndicator = false
@State private var viewId = UUID()
@Koshimizu-Takehito
Koshimizu-Takehito / HPicker.swift
Last active July 8, 2025 12:23
水平方向のピッカー
import SwiftUI
struct HPicker<SelectionValue, Content>: View where SelectionValue: Hashable, Content: View {
private var items: [SelectionValue]
private var numberOfDisplays: Int
private var content: (SelectionValue) -> Content
@Binding private var selection: SelectionValue?
@State private var contentOffset: Double = 0
@State private var itemWidth: Double = 100.0
#include <metal_stdlib>
using namespace metal;
float smoothMin(float x1, float x2, float k) {
float h = clamp(0.5 - 0.5 * (x2 - x1) / k, 0.0, 1.0);
return mix(x1, x2, h) - k * h * (1.0 - h);
}
float circleSDF(float2 point, float2 center, float radius) {
return length(point - center) - radius;
#include <metal_stdlib>
using namespace metal;
float smoothMin(float x1, float x2, float k) {
float h = clamp(0.5 - 0.5 * (x2 - x1) / k, 0.0, 1.0);
return mix(x1, x2, h) - k * h * (1.0 - h);
}
float circleSDF(float2 point, float2 center, float radius) {
return length(point - center) - radius;