Skip to content

Instantly share code, notes, and snippets.

@carlynorama
Created December 9, 2022 18:53
Embed
What would you like to do?
Function that takes an array of Points (a Type with (x,y) ) and creates an ASCII representation.
func drawPoints(array:[P], width:Int, height:Int) -> String {
var outterArray:[[String]] = []
for _ in (0..<width) {
outterArray.append((Array(repeating: ".", count:height)))
}
for point in array {
outterArray[point.y][point.x] = "#"
}
//[Y][X]
outterArray[0][0] = "s"
let strings = outterArray
.map({ $0.joined(separator: "")})
.reversed()
.joined(separator: "\n")
print(strings)
return strings
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment