Created
June 13, 2019 07:51
-
-
Save brimelow/087d3ce7ac070e8358bde8d0d877ea31 to your computer and use it in GitHub Desktop.
Random 100 Circles Animation in SwiftUI
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 | |
// DrawingGroup | |
// | |
// Created by Lee Brimelow on 6/12/19. | |
// Copyright © 2019 Lee Brimelow. All rights reserved. | |
// | |
import SwiftUI | |
struct ContentView : View { | |
@State var scale: CGFloat = 1 | |
var body: some View { | |
ZStack { | |
ForEach((1...100)) { _ in | |
Circle() | |
.strokeBorder(Color(red: .random(in: 0...1), | |
green: .random(in: 0...1), | |
blue: .random(in: 0...1)), | |
lineWidth: .random(in: 1...20)) | |
.blendMode(.colorDodge) | |
.animation(Animation.fluidSpring() | |
.repeatForever() | |
.speed(.random(in: 0.05...0.9)) | |
.delay(.random(in: 0...2)) | |
) | |
.scaleEffect(self.scale * .random(in: 0.1...3)) | |
.frame(width: .random(in: 20...100), | |
height: CGFloat.random(in: 20...100), | |
alignment: .center) | |
.position(CGPoint(x: .random(in: 0...1112), | |
y: .random(in: 0...834))) | |
} | |
}.onAppear { | |
self.scale = 1.2 | |
} | |
.frame(width: 1112, height: 834, alignment: .center) | |
.drawingGroup(opaque: false, colorMode: .linear) | |
} | |
} | |
#if DEBUG | |
struct ContentView_Previews : PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment