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 / MyFlowLayout.swift
Last active June 3, 2024 04:39
改行を考慮した FlowLayout
import SwiftUI
struct FlowLayoutSampleView: View {
@State var width: CGFloat = 180
let tags: [String] = [
"Objective-C",
"Swift",
// "SwiftSwiftSwiftSwiftSwiftSwiftSwiftSwift",
// "SwiftSwiftSwiftSwiftSwiftSwiftSwiftSwiftSwiftSwiftSwiftSwiftSwiftSwiftSwiftSwiftSwiftSwiftSwiftSwiftSwiftSwiftSwiftSwiftSwift",
@Koshimizu-Takehito
Koshimizu-Takehito / CustomGridLayout.swift
Last active June 2, 2024 14:42
グリッドのマスと隙間に View を配置する Layout プロトコルのサンプル実装
import SwiftUI
enum CustomGridItem: LayoutValueKey, Hashable {
enum Bar: Hashable {
case vertical
case horizontal
}
case cell
case bar(Bar)
static var defaultValue: Self = .cell
@Koshimizu-Takehito
Koshimizu-Takehito / App.swift
Last active May 25, 2024 11:19
Hacker Text Effect - SwiftUI - iOS 16 & iOS 17
import SwiftUI
@main
struct App: SwiftUI.App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
@Koshimizu-Takehito
Koshimizu-Takehito / ContentView.swift
Created May 19, 2024 13:48
スクロール位置に応じてY軸回転
import SwiftUI
struct ContentView: View {
@State private var containerFrame: CGRect = .zero
private var colors = [[Color]](repeating: .rainbow(count: 50), count: 300)
.flatMap { $0 }
.enumerated()
.map { $0 }
var body: some View {
@Koshimizu-Takehito
Koshimizu-Takehito / ContentView.swift
Created May 11, 2024 09:59
グラデーションアニメーション
import SwiftUI
extension [Color] {
static func rainbow(hue: Double = 0, count: Int) -> Self {
(0..<count).map { i in
var value = hue + Double(i) / Double(count)
value -= floor(value)
return Color(hue: value, saturation: 1/4, brightness: 1)
}
}
import SwiftUI
struct ContentView: View {
@State var mode = EditMode.inactive
var body: some View {
NavigationStack {
VStack {
ForEach(1..<12) { offset in
FooView(count: 12, offset: offset)
#include <metal_stdlib>
using namespace metal;
namespace JuliaSet {
/// HSV -> RGB
half3 hsv2rgb(half3 c) {
half3 rgb = clamp(abs(fmod(c.x * 6.0 + half3(0.0, 4.0, 2.0), 6.0) - 3.0) - 1.0, 0.0, 1.0);
return c.z * mix(half3(1.0), rgb, c.y);
}
import SwiftUI
struct SqureFlowView: View {
@StateObject private var holder = SquresHolder()
var body: some View {
TimelineView(.animation) { timeline in
Canvas { context, size in
holder.update(at: timeline.date, in: size)
for item in holder.squre {
#include <metal_stdlib>
using namespace metal;
namespace SmoothMin2d {
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) {
import SwiftUI
struct LoadingView: View {
@State var theta: Double = 0
let radius: Double = 60
var body: some View {
ZStack {
ForEach(0..<8) { index in
let offset = ((2 * .pi) * Double(index)) / 8