Skip to content

Instantly share code, notes, and snippets.

@bitwit
Created December 19, 2020 19:40
Show Gist options
  • Save bitwit/987ec26a3d39926c78029c5ee969b74b to your computer and use it in GitHub Desktop.
Save bitwit/987ec26a3d39926c78029c5ee969b74b to your computer and use it in GitHub Desktop.
Conservation of Mass Jump
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