Skip to content

Commit

Permalink
normalize layer, removed code
Browse files Browse the repository at this point in the history
  • Loading branch information
fogleman committed Dec 12, 2015
1 parent b342bf9 commit f0ec1f4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 21 deletions.
15 changes: 15 additions & 0 deletions layers.py
Expand Up @@ -20,6 +20,8 @@ def threshold(self, threshold):
return Threshold(self, threshold)
def clamp(self, lo=0, hi=1):
return Clamp(self, lo, hi)
def normalize(self, lo, hi, new_lo, new_hi):
return Normalize(self, lo, hi, new_lo, new_hi)
def filter_points(self, points, lo, hi):
return [(x, y) for x, y in points if lo <= self.get(x, y) < hi]
def alpha_shape(self, points, lo, hi, alpha):
Expand Down Expand Up @@ -111,6 +113,19 @@ def get(self, x, y):
v = max(v, self.lo)
return v

class Normalize(Layer):
def __init__(self, layer, lo, hi, new_lo, new_hi):
self.layer = layer
self.lo = lo
self.hi = hi
self.new_lo = new_lo
self.new_hi = new_hi
def get(self, x, y):
v = self.layer.get(x, y)
p = (v - self.lo) / (self.hi - self.lo)
v = self.new_lo + p * (self.new_hi - self.new_lo)
return v

class Distance(Layer):
def __init__(self, x, y, maximum):
self.x = x
Expand Down
25 changes: 4 additions & 21 deletions main.py
Expand Up @@ -29,23 +29,14 @@ def render_shape(dc, shape):
dc.line_to(x, y)
dc.close_path()

def render_water_symbol(dc, x, y):
r = 4
e = math.pi / 4
for dx in [-r, r]:
dc.new_sub_path()
dc.arc_negative(dx + x + r, y, r, math.pi, math.pi / 2 - e)
dc.new_sub_path()
dc.arc(dx + x - r, y, r, 0, math.pi / 2 + e)

def render_mark_symbol(dc, x, y):
def render_mark(dc, x, y):
n = 8
dc.move_to(x - n, y - n)
dc.line_to(x + n, y + n)
dc.move_to(x - n, y + n)
dc.line_to(x + n, y - n)

def render_compass_symbol(dc):
def render_compass(dc):
w, h = 4, 32
dc.line_to(-w, 0)
dc.line_to(0, h)
Expand Down Expand Up @@ -137,14 +128,6 @@ def render(seed=None):
dc.set_source_rgb(*c.rgb)
render_shape(dc, shape)
dc.fill()
# land outline
# dc.save()
# dc.set_source_rgb(*Color('#BDD4DE').rgb)
# for _ in range(5):
# render_shape(dc, shape1.buffer(2))
# dc.fill()
# dc.translate(0, 1)
# dc.restore()
# height
dc.save()
dc.set_source_rgb(*Color('#CFC291').rgb)
Expand Down Expand Up @@ -173,14 +156,14 @@ def render(seed=None):
dc.set_dash([])
# mark
dc.set_source_rgb(*Color('#DC3522').rgb)
render_mark_symbol(dc, *mark)
render_mark(dc, *mark)
dc.set_line_width(4)
dc.stroke()
# compass
dc.save()
dc.translate(48, height - 64)
dc.rotate(random.random() * math.pi / 4 - math.pi / 8)
render_compass_symbol(dc)
render_compass(dc)
dc.restore()
return surface

Expand Down

0 comments on commit f0ec1f4

Please sign in to comment.