Skip to content

Instantly share code, notes, and snippets.

@dakerfp
Created August 4, 2021 20:42
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 dakerfp/eee96584d25a43da02bf1f9552915767 to your computer and use it in GitHub Desktop.
Save dakerfp/eee96584d25a43da02bf1f9552915767 to your computer and use it in GitHub Desktop.
# Mold #50 - Wizard Tower
# Mold #55 - Bell tower
# Mold #65 - Ruined tower
# Mold #60 - Prison tower
# Mold #63 - Octagon Tower
# Mold #226 - Wooden Beam
# #245 - Slate Shingle Roof
# #259 - Rubble Bridge
import math
def inches_to_cm(inches):
return inches * 2.54
def feet_to_inches(ft):
return 12 * ft
def perimeter(w, h):
return 2 * w + 2 * h
def mult(a, m):
return tuple(ax * m for ax in a)
def cover_area_with_tiles(covered_size, tile_size):
w, h = tile_size
tw, th = covered_size
return (math.ceil(tw / w), math.ceil(th / h))
warcry_size = (22, 30)
# Mold #50 - Wizard Tower
# Mold #55 - Bell tower
# Mold #65 - Ruined tower
# Mold #60 - Prison tower
# Mold #63 - Octagon Tower
# Mold #226 - Wooden Beam
# #245 - Slate Shingle Roof
# #259 - Rubble Bridge
import math
def inches_to_cm(inches):
return inches * 2.54
def feet_to_inches(ft):
return 12 * ft
def perimeter(w, h):
return 2 * w + 2 * h
def mult(a, m):
return tuple(ax * m for ax in a)
def tiles_area(tiles, tile_size):
return tiles[0] * tile_size[0] * tiles[1] * tile_size[1]
def rotate(size):
return size[1], size[0]
def cover_area_with_tiles(covered_size, tile_size):
w, h = tile_size
tw, th = covered_size
return (math.ceil(tw / w), math.ceil(th / h))
def area(size):
return size[0] * size[1]
warcry_size = (22, 30)
warhammer_size = mult(warcry_size, 2)
warhammer_area = area(warhammer_size)
warhammer_perimeter = perimeter(*warhammer_size)
import cairo
WIDTH, HEIGHT = 512, 512
def draw_background(ctx):
ctx.set_source_rgb(0.1, 0.8, 0.1)
ctx.rectangle(0, 0, WIDTH, HEIGHT)
ctx.fill()
ctx.set_source_rgb(0.1, 1.0, 0.1)
draw_grid(ctx, (10, 10), (64, 64))
def draw_grid(ctx, tile_size, tiling):
w, h = tile_size
for x in range(tiling[0]):
for y in range(tiling[1]):
ctx.rectangle(x * w, y * h, w, h)
ctx.stroke()
surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, WIDTH, HEIGHT)
ctx = cairo.Context(surface)
draw_background(ctx)
ctx.scale(2.5, 2.5)
class Model(object):
def __init__(self, id, pos, base=1):
self.id = id
self.pos = pos
self.base = base
def draw(self, ctx):
ctx.arc(self.pos[0], self.pos[1], self.base, 0, 2 * math.pi)
ctx.fill()
team_a = [Model(1, (10, 10)), Model(2, (10, 14))]
team_b = [Model(101, (80, 10))]
def draw_team(team, color=(0.8, 0.1, 0.1)):
ctx.set_source_rgb(*color)
for model in team:
print(model)
model.draw(ctx)
draw_team(team_a)
draw_team(team_b, color=(0.1, 0.1, 0.8))
surface.write_to_png("wargame.png")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment