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 / 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 March 5, 2025 10:01
カウントダウンアニメーション
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 March 3, 2025 07:53
ページング無しの循環スクロールビュー
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 March 1, 2025 07:31
水平方向のピッカー
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;
import SwiftUI
struct ContentView: View {
var body: some View {
WavingText()
.foregroundStyle(.white)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color(hue: 220/360, saturation: 0.3, brightness: 0.9))
}
}
import SwiftUI
struct ContentView: View {
private var title: String {
Item.sample.title
}
private var message: String {
Item.sample.message
}
import SwiftUI
struct ContentView: View {
@State var isExpanded = [true] + Array(repeating: false, count: PageItem.samples.count)
var body: some View {
ZStack {
ForEach(1..<isExpanded.count, id: \.self) { offset in
let item = PageItem.samples[(offset-1) % PageItem.samples.count]
PageView(
import SwiftUI
struct ContentView: View {
@State var isExpanded = [true] + Array(repeating: false, count: 10)
var body: some View {
ZStack {
ForEach(1..<isExpanded.count, id: \.self) { offset in
CircleView(
color: .color(offset: offset),