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 / Mosaic.metal
Last active February 11, 2025 23:43
シェーダー関数でモザイク
#include <metal_stdlib>
#include <SwiftUI/SwiftUI.h>
using namespace metal;
[[ stitchable ]] half4 mosaic(
float2 position,
SwiftUI::Layer layer,
float scale
) {
position = floor(position / scale) * scale;
@Koshimizu-Takehito
Koshimizu-Takehito / Tile.metal
Created January 12, 2025 06:10
シェーダー関数でタイル
#include <metal_stdlib>
using namespace metal;
[[ stitchable ]] half4 tile(float2 position, half4 color, float4 box, float scale) {
position = position - box.zw/2;
position = position / (10 * scale);
int2 xy = int2(floor(position)) % 2;
if ((xy.x + xy.y) % 2) {
return half4(0.0, 0.0, 0.0, 1.0);
} else {
@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 / SieveOfEratosthenes.swift
Last active January 1, 2025 13:48
素数のアルキメデスの螺旋
import SwiftUI
struct ContentView: View {
private static let primeNumbers = sieveOfEratosthenes(upTo: 1000000)
@State private var scale = 1.0
@State private var start = Date()
var body: some View {
TimelineView(.animation) { context in
let time = context.date.timeIntervalSince(start)
@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 / f11f86.swift
Last active December 31, 2024 02:52
Task.sleep は現在のスレッドをブロックしない
import SwiftUI
import Observation
@Observable
@MainActor
final class ContentViewModel {
var isLoading = false
var colors: [Color] = Array(repeating: Color.random(), count: 10)
func fetch() {
import SwiftUI
// MARK: - ContentView
// https://x.com/okazz_/status/1870807939944243631
struct ContentView: View {
@State private var progress: Double = 0
var body: some View {
MyGroup {
@Koshimizu-Takehito
Koshimizu-Takehito / e9f7494f05735157ed0db9280ad18c426eac6a7ea6826e3502caf34597a91c63.swift
Last active December 30, 2024 20:57
上のHStackの幅に下のViewの幅を揃える
import SwiftUI
struct ContentView: View {
@State var isInfinityWidth = false
@State var isFixedSize = false
var body: some View {
Form {
Section {
Toggle("maxWidth: .infinity", isOn: $isInfinityWidth.animation())
@Koshimizu-Takehito
Koshimizu-Takehito / AuthCodeInput.swift
Created December 15, 2024 10:25
認証コード入力っぽいUI
import SwiftUI
struct ContentView: View {
@State private var digits: [Int] = []
var body: some View {
AuthCodeInput(digits: $digits, count: 6)
.padding()
.ignoresSafeArea(.keyboard)
.onChange(of: digits) { _, digits in
@Koshimizu-Takehito
Koshimizu-Takehito / TileAnimation2.swift
Created November 30, 2024 08:41
アニメーション素振り2
import SwiftUI
// MARK: - Model
@MainActor
@Observable
final class Model {
var rotations: [[Int]]
var positions: [IndexPath]
init(row: Int, column: Int) {