Skip to content

Instantly share code, notes, and snippets.

@Koshimizu-Takehito
Koshimizu-Takehito / SpiralShader.metal
Last active February 11, 2025 23:41
シェーダー関数で螺旋
#include <metal_stdlib>
using namespace metal;
[[ stitchable ]] half4 spiral(
float2 position,
half4 color,
float4 box,
float scale
) {
position = position - box.zw/2;
@Koshimizu-Takehito
Koshimizu-Takehito / Spiral.swift
Created December 31, 2024 06:08
アルキメデスのらせん
import SwiftUI
struct ContentView: View {
@State var start = Date()
var body: some View {
TimelineView(.animation) { context in
let time = context.date.timeIntervalSince(start) / 120
let rotation = 0.8 + 0.2 * abs((cos(.pi * time) + 1.0) / 2.0)
Canvas { context, size in
@Koshimizu-Takehito
Koshimizu-Takehito / TileAnimation.swift
Created November 29, 2024 07:43
アニメーション素振り
import SwiftUI
// MARK: - Model
@MainActor
@Observable
final class Model {
var rotations: [[Int]]
init(row: Int, column: Int) {
rotations = (0..<row).map { _ in
import SwiftUI
struct ContentView: View {
@StateObject private var viewModel = RectsViewModel()
var body: some View {
GeometryReader { geometry in
TimelineView(.animation) { timeline in
Canvas {context, size in
let rects = viewModel.rects
@Koshimizu-Takehito
Koshimizu-Takehito / DynamicTypeSize.swift
Created October 20, 2024 10:19
ダイナミックタイプを利用した場合の標準フォントのスケール
import SwiftUI
#Preview {
@Previewable @State var value: Double = 3.0
VStack {
SampleView()
.environment(\.dynamicTypeSize, .allCases[Int(value)])
.frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .trailing)
.contentTransition(.numericText())
Text("\(DynamicTypeSize.allCases[Int(value)])")
import SwiftUI
struct ContentView: View {
@Environment(\.colorScheme) var scheme
private let date = Date()
private let colors = [Color.green, .pink, .blue, .orange, .purple]
private let titles = ["NEON", "GLOW", "LIGHT", "SHINE", "BRIGHT"]
var body: some View {
TimelineView(.animation) { context in
import SwiftUI
// MARK: - RinganimationScreen
/// A screen that displays three animated concentric progress rings.
/// Each ring rotates at a different speed and animates continuously using `TimelineView`.
struct RinganimationScreen: View {
let startTime: Date = .now
var body: some View {
import SwiftUI
struct Card: Identifiable, Hashable {
let id = UUID()
let creditID = UUID()
let colors: [Color]
let name: String
let number: String
}
@Matt54
Matt54 / PointLightsInsideContainerView.swift
Last active July 21, 2024 13:17
RealityKit extruded container view made of reflective and transparent materials. Points lights animate inside with their positions represented as spheres.
import RealityKit
import SwiftUI
struct PointLightsInsideContainerView: View {
@State private var rootEntity: Entity?
@State private var timer: Timer?
@State private var spherePositions: [String: SIMD3<Float>] = [:]
@State private var sphereTargetPositions: [String: SIMD3<Float>] = [:]
@State private var rotationAngle: Float = 0