Created
December 14, 2020 20:13
-
-
Save kellylougheed/c3f1d4b4ab471255112c88b1774c4862 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ContentView.swift | |
// Snowglobe | |
// | |
// Created by Kelly Lougheed on 12/14/20. | |
// | |
import SwiftUI | |
struct ContentView: View { | |
let numParticles: Int = 200 | |
var body: some View { | |
ZStack { | |
Color.black.ignoresSafeArea() | |
ForEach(0..<numParticles) { index in | |
Particle() | |
} | |
} | |
} | |
} | |
struct Particle: View { | |
@State private var onFloor: Bool = false | |
var scaleNum: CGFloat = CGFloat.random(in: 3...8) | |
var animation = Animation.linear(duration: Double.random(in: 1...5)).repeatForever(autoreverses: false) | |
var body: some View { | |
GeometryReader { geo in | |
Circle() | |
.fill(Color.white) | |
.frame(width: scaleNum, height: scaleNum) | |
.offset(x: 0, y: onFloor ? geo.size.height : CGFloat(0)) | |
.position(x: CGFloat(Int.random(in: 0...Int(geo.size.width)))) | |
.blur(radius: 1) | |
.onAppear() { | |
withAnimation(animation) { | |
onFloor.toggle() | |
} | |
} | |
} | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment