Skip to content

Instantly share code, notes, and snippets.

@eonist
Last active July 24, 2017 22:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eonist/b625aa8b3dff8b9ea9d9baad355132f7 to your computer and use it in GitHub Desktop.
Save eonist/b625aa8b3dff8b9ea9d9baad355132f7 to your computer and use it in GitHub Desktop.
Test Animator
/**
*
*/
func zoomBackAndForthAnimTest(){
//Setup window 200x300,white
let winRect = CGRect(0,0,200,300)
window.size = winRect.size
window.contentView = InteractiveView2()
window.title = ""
StyleManager.addStyle("#bg{fill:white;}")
window.contentView?.addSubview(Section(window.size.w,window.size.h,nil,"bg"))
//circle, 70-radius,centered
let startRect:CGRect = {
let size:CGSize = CGSize(70,70)
let p:CGPoint = Align.alignmentPoint(size, winRect.size, Alignment.centerCenter, Alignment.centerCenter)
return CGRect(p,size)
}()
let startColor:NSColor = .gray
let startFillet:CGFloat = 20
//roundRect, 150x150, Fillet:25, centered
let endRect:CGRect = {
let size:CGSize = CGSize(150,150)
let p:CGPoint = Align.alignmentPoint(size, winRect.size, Alignment.centerCenter, Alignment.centerCenter)
return CGRect(p,size)
}()
let endColor:NSColor = .black
let endFillet:CGFloat = 35
let roundRect:RoundRectGraphic = {
let roundRect = RoundRectGraphic(0,0,startRect.w,startRect.h,Fillet(startFillet),FillStyle( startColor.interpolate(endColor, 0)),nil)
window.contentView?.addSubview(roundRect.graphic)
roundRect.draw()
roundRect.graphic.layer?.position = startRect.origin
return roundRect
}()
/*Elastic anim to roundRect state*/
let anim = Animator2.init(initValues:(dur:0.8,from:0,to:1), easing:Easing.elastic.easeOut) { value in
disableAnim {
Swift.print("value: " + "\(value)")
/*Fillet*/
let fillet:Fillet = Fillet(startFillet.interpolate(endFillet, value))
roundRect.fillet = fillet
/*Color*/
let color = startColor.interpolate(endColor, value)
roundRect.graphic.fillStyle = FillStyle(color)
/*Size*/
let newSize = startRect.size.interpolate(endRect.size, value)
roundRect.size = newSize
/*Position*/
let newP = startRect.origin.interpolate(endRect.origin, value)
roundRect.graphic.layer?.position = newP
/*Draw it all*/
roundRect.draw()
}
}
anim.completed = {
bgSleep(1){/*delay anim for 1 secs*/
anim.initValues = (dur:0.8,from:1,to:0)/*reverse*/
anim.currentFrameCount = 0/*reset*/
anim.completed = {}/*reset*/
anim.start()/*start the reverse anim*/
}
}
bgSleep(30){/*delay anim for 2 secs*/
anim.start()
}
//reverse
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment