Skip to content

Instantly share code, notes, and snippets.

@edy555
Created September 16, 2014 15:35
Show Gist options
  • Select an option

  • Save edy555/7930e9073ecf50ab3e2d to your computer and use it in GitHub Desktop.

Select an option

Save edy555/7930e9073ecf50ab3e2d to your computer and use it in GitHub Desktop.
Generate rainbow shape as voxel in json for VoxelEditor https://github.com/perfume-dev/VoxelEditor
#!/usr/bin/env python
import json
import colorsys
import math
def hsv(h, s, v):
r, g, b = colorsys.hsv_to_rgb(h, s, v)
return (int(r*255)*256 + int(g*255))*256 + int(b*255)
arr = []
z = 0
for x in range(0, 80):
for y in range(0, 40):
r = math.sqrt((x - 40)**2 + (y+1)**2)
if r < 31 or r > 40:
continue
h = (39 - r) / 10
if h < 0:
h = 0
v = {
"color": hsv(h, 1, 1),
"d": 10,
"h": 1,
"id": 0,
"w": 1,
"x": x,
"y": y,
"z": z
}
arr.append(v)
voxel = {"metadata": "",
"updatedAt": 1410876497,
"version": 1,
"voxels": arr
}
print json.dumps(voxel, sort_keys=True, indent=4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment