Created
December 19, 2020 19:40
-
-
Save bitwit/987ec26a3d39926c78029c5ee969b74b to your computer and use it in GitHub Desktop.
Conservation of Mass Jump
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
import UIKit | |
import PlaygroundSupport | |
import SwiftUI | |
struct ContentView: View { | |
var jumpAmount: CGFloat { | |
CGFloat(-time * time + time) | |
} | |
var scaleX: CGFloat { 1/scaleY } | |
var scaleY: CGFloat { | |
minScale + (jumpAmount * ((1 + maxScale) - minScale)) | |
} | |
var translateY: CGFloat { -translateYAmount * jumpAmount } | |
@State var time: Double = 0 | |
var minScale: CGFloat = 1 | |
var maxScale: CGFloat = 0.5 | |
var translateYAmount: CGFloat = 200 | |
var body: some View { | |
Text("😃") | |
.font(.largeTitle) | |
.scaleEffect(.init(width: scaleX, height: scaleY)) | |
.offset(x: 0, y: translateY) | |
.animation(Animation | |
.linear(duration: 0.3) | |
.repeatForever(autoreverses: true) | |
) | |
.onAppear { | |
self.time = 0.5 | |
} | |
} | |
} | |
PlaygroundPage.current.liveView = UIHostingController(rootView: ContentView().frame(width: 320, height: 480)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment