Skip to content

Instantly share code, notes, and snippets.

@Yardanico
Last active July 27, 2017 15:43
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 Yardanico/e6ec6f6a865adc9ea7192b51ec8ccd51 to your computer and use it in GitHub Desktop.
Save Yardanico/e6ec6f6a865adc9ea7192b51ec8ccd51 to your computer and use it in GitHub Desktop.
import nigui, streams
app.init()
type
ColorId = range[0..15]
# https://www.reddit.com/r/place/comments/62z2uu/rplace_archive_update_and_boardbitmap_description/
proc toRgb(c: ColorId): Color =
case c
of 0: rgb(255, 255, 255)
of 1: rgb(228, 228, 228)
of 2: rgb(136, 136, 136)
of 3: rgb(34, 34, 34)
of 4: rgb(255, 167, 209)
of 5: rgb(229, 0, 0)
of 6: rgb(229, 149, 0)
of 7: rgb(160, 106, 66)
of 8: rgb(229, 217, 0)
of 9: rgb(148, 224, 68)
of 10: rgb(2, 190, 1)
of 11: rgb(0, 211, 211)
of 12: rgb(0, 131, 199)
of 13: rgb(0, 0, 234)
of 14: rgb(207, 110, 228)
of 15: rgb(130, 0, 128)
# File from https://www.reddit.com/r/place/comments/6396u5/rplace_archive_update/
let data = newFileStream("diffs.bin", fmRead)
var resultImage = newImage()
resultImage.resize(1000, 1000)
var pixels: array[1000, array[1000, ColorId]]
while not data.atEnd:
let
timestamp = data.readInt32()
x = data.readInt32()
y = data.readInt32()
color = data.readInt32()
pixels[x][y] = color
data.close()
for x, data in pixels:
for y, color in data:
resultImage.canvas.setPixel(x, y, color.toRgb)
resultImage.saveToPngFile("out.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment