Skip to content

Instantly share code, notes, and snippets.

@gourneau
Created February 25, 2013 20:23
Show Gist options
  • Select an option

  • Save gourneau/5032953 to your computer and use it in GitHub Desktop.

Select an option

Save gourneau/5032953 to your computer and use it in GitHub Desktop.
import random
class shorter_float(float):
"""A float which returns only 3 digits after the decimal"""
def __repr__(self):
return "%0.3f" % self
ires = 100.0 # Inverse resolution
left = -100
right = 101
def ctrans(e):
return e/ires
def r2(x,y):
return ctrans(x)**2 + ctrans(y)**2
def printM(mat):
for row in mat:
r = map(shorter_float, row)
for i in r:
t = i * 50
#t = t - random.randint(0, int(t/3))
print t,
print ""
hsph = [ [1 - r2(x, y) if r2(x, y) <= 1 else 0 for x in range(left,right)] for y in range(left,right)]
printM(hsph)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment