Last active
March 31, 2016 08:50
-
-
Save kakajika/12288807ef40e7a2bfec7ba9ad929c06 to your computer and use it in GitHub Desktop.
Example script of PaperSwift
This file contains hidden or 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 PaperSwift | |
| let ExampleScript1 = { (paper: PaperView) in | |
| var center: CGPoint | |
| var width: CGFloat | |
| var height: CGFloat | |
| var pathHeight: CGFloat | |
| let points = 8 | |
| let path = paper.Path() | |
| path.fillColor = UIColor.darkGrayColor() | |
| func initializePath() { | |
| width = paper.bounds.width | |
| height = paper.bounds.height | |
| pathHeight = height / 2 | |
| center = [width / 2, height / 2] | |
| path.moveTo([0, height]) | |
| for i in 1..<points { | |
| path.lineTo([width / CGFloat(points) * CGFloat(i), center.y]) | |
| } | |
| path.lineTo([width, height]) | |
| path.fullySelected = true | |
| } | |
| initializePath() | |
| paper.onFrame { event in | |
| pathHeight += (center.y / 2.0 - pathHeight) / 10.0 | |
| for i in 1..<points { | |
| let sinSeed = CGFloat(event.count) + CGFloat(i + i % 10) * 100.0 | |
| let sinHeight = sin(sinSeed / 200.0) * pathHeight | |
| let yPos = sin(sinSeed / 100.0) * sinHeight + center.y | |
| path.segments[i].point.y = yPos | |
| } | |
| path.smooth(.Continuous) | |
| } | |
| paper.onResize { event in | |
| initializePath() | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment