Skip to content

Instantly share code, notes, and snippets.

@carlynorama
Created December 9, 2022 18:53
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 carlynorama/4a6228ebc423c8f68e900c885e74887b to your computer and use it in GitHub Desktop.
Save carlynorama/4a6228ebc423c8f68e900c885e74887b to your computer and use it in GitHub Desktop.
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