Skip to content

Instantly share code, notes, and snippets.

@Matt54
Matt54 / AnimatingMaskedMeshView.swift
Created June 13, 2024 12:21
An animating mesh gradient view with an animating mask
import SwiftUI
struct AnimatingMaskedMeshView: View {
let referenceDate: Date = .now
@State private var mainPosition: CGPoint = .zero
@State private var positions: [CGPoint] = []
private let blurRadius = 20.0
private let alphaThreshold = 0.875
@stzn
stzn / The Swift Concurrency Migration Guide Data Race Safety.md
Last active July 5, 2024 21:33
Data Race Safety in The Swift Concurrency Migration Guide

データ競合安全

Swiftの基本的な概念について学び、データ競合のない並行コードを実現する方法を知りましょう。

原文 https://github.com/apple/swift-migration-guide/blob/main/Guide.docc/DataRaceSafety.md
更新日 2024/7/6(翻訳を最後に更新した日付)
ここまで反映 https://github.com/apple/swift-migration-guide/commit/24e31ffc589fefb42f08877878e689eb29b1644b

従来、可変状態(mutable state)は、細心の注意を払い、実行時の同期によって手動で保護する必要がありました。

@Koshimizu-Takehito
Koshimizu-Takehito / 33869900928a99144c822c901d370352e539a895ed12420a0cc7080b866f0b75.swift
Last active December 30, 2024 20:52
Hacker Text Effect - SwiftUI - iOS 16 & iOS 17
import SwiftUI
struct ContentView: View {
@State var trigger = 0
@State var text = sampeles[0]
var body: some View {
VStack(alignment: .leading, spacing: 12) {
HackerTextEffectView(
text: text,
//
// SignatureAnimation.swift
// OpenSwiftUIAnimations
//
// Created by Amos Gyamfi on 11.5.2024.
//
import SwiftUI
struct SignatureAnimation: View {
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)
}
}
#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) {
@sebjvidal
sebjvidal / ViewController.swift
Created April 30, 2024 15:50
Apple Journal Calendar UI Demo
//
// ViewController.swift
// Journal-Calendar-Demo
//
// Created by Seb Vidal on 30/04/2024.
//
import UIKit
class ViewController: UIViewController {
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