-
-
Save jonelf/c5adac26bba63c376b0a to your computer and use it in GitHub Desktop.
| for line in 0...32 { | |
| println("".join((0...78).map { (col: Int) -> String in | |
| var x = 0.0, y = x, i = 0 | |
| do { | |
| x = x * x - y * y + Double(col) / 20.0 - 2.3 | |
| y = 2 * x * y + Double(line) / 10.0 - 1.5 | |
| i++ | |
| } while (x * x + y * y) < 4 && i < 78 | |
| return "\(UnicodeScalar(0x1f35b + i))" | |
| }) | |
| ) | |
| } |
In Swift 2.2.1
for line in 0...32 {
print((0...78).map { (col: Int) -> String in
var x = 0.0, y = x, i = 0
repeat {
x = x * x - y * y + Double(col) / 20.0 - 2.3
y = 2 * x * y + Double(line) / 10.0 - 1.5
i = i + 1
} while (x * x + y * y) < 4 && i < 78
return "\(UnicodeScalar(0x1f35b + i))"
}.joinWithSeparator(""))
}
In Swift 3.0
for line in 0...32 {
print((0...65).map { (col: Int) -> String in
var x = 0.0, y = x, i = 0
repeat {
x = x * x - y * y + Double(col) / 20.0 - 2.1
y = 2 * x * y + Double(line) / 10.0 - 1.5
i = i + 1
} while (x * x + y * y) < 4 && i < 78
return "\(UnicodeScalar(0x1f35b + i))"
}.joined(separator: ""))
}
https://swiftlang.ng.bluemix.net/#/repl/5759332a83847baf29642974
for line in 0...42 {
print((0...65).map { (col: Int) -> String in
var x = 0.0, y = x, i = 0
repeat {
x = x * x - y * y + Double(col) / 20.0 - 2.1
y = 2 * x * y + Double(line) / 13.0 - 1.5
i = i + 1
} while (x * x + y * y) < 4 && i < 78
return String(UnicodeScalar(i + 0x1f35b)!)
}.joined(separator: ""))
}
This one works in Swift 5.9.2. Save and run with xcrun swift filename.swift
Open a big macOS terminal and run
echo 'for l in 0...42{print((0...65).map{(col: Int)->String in var x=0.0,y=x,i=0;repeat{x=x*x-y*y+Double(col)/20.0-2.1;y=2*x*y+Double(l)/13.0-1.5;i=i+1}while(x*x+y*y)<4&&i<78;return String(UnicodeScalar(i+0x1f35b)!)}.joined(separator:""))}'|swift
The above is not working in swift-driver version: 1.120.5 Apple Swift version 6.1.2 (swiftlang-6.1.2.1.2 clang-1700.0.13.5).
You have to add repl like this
echo 'for l in 0...42{print((0...65).map{(col: Int)->String in var x=0.0,y=x,i=0;repeat{x=x*x-y*y+Double(col)/20.0-2.1;y=2*x*y+Double(l)/13.0-1.5;i=i+1}while(x*x+y*y)<4&&i<78;return String(UnicodeScalar(i+0x1f35b)!)}.joined(separator:""))}'|swift repl

https://twitter.com/jonelf/status/580007606481215488
http://swiftstub.com/198900712/