Permalink
Browse files

Add webdemo gif

  • Loading branch information...
s-macke committed Sep 25, 2017
1 parent 6db11b4 commit 51229224747515e1935435db017512aa5ce400a0
Showing with 77 additions and 50 deletions.
  1. BIN images/webdemo.gif
  2. +64 −47 tools/animations/anim.py
  3. +0 −3 tools/animations/run.sh
  4. +13 −0 tools/animations/runwebdemo.sh
BIN +1.58 MB images/webdemo.gif
Binary file not shown.
@@ -3,17 +3,20 @@
import numpy as np

# -----------------------------------------------------
colorimg = Image.open("../../maps/C1W.png")
colormap = colorimg.load()

heightimg = Image.open("../../maps/D1.png")
heightmap = heightimg.load()
def Init(width, height, colorfilename, heightfilename):
global colorimg, colormap, heightimg, heightmap, pal, screen, screenmap
colorimg = Image.open("../../maps/" + colorfilename)
colormap = colorimg.load()

# the colormap uses a color palette
pal = colorimg.palette.getdata()[1];
heightimg = Image.open("../../maps/" + heightfilename)
heightmap = heightimg.load()

screen = Image.new("RGB", (512+512+700, 512))
screenmap = screen.load()
# the colormap uses a color palette
pal = colorimg.palette.getdata()[1];

screen = Image.new("RGB", (width, height))
screenmap = screen.load()

# -----------------------------------------------------

@@ -26,10 +29,16 @@ def __init__(self, x=0, y=0):

def DrawVerticalLine(x, ytop, ybottom, c):
if (ytop >= ybottom): return
if (ytop < 0): y = 0
if (ytop < 0): ytop = 0

rgb = (pal[c*3+2]<< 16) | (pal[c*3+1] << 8) | pal[c*3+0]
for j in range(math.floor(ytop), math.floor(ybottom)):
screenmap[x+1024, j] = rgb
if screen.width != 700:
for j in range(math.floor(ytop), math.floor(ybottom)):
screenmap[x+1024, j] = rgb
else:
for j in range(math.floor(ytop), math.floor(ybottom)):
screenmap[x, j] = rgb


# -----------------------------------------------------

@@ -55,10 +64,11 @@ def Horline(p1, p2, offset, scale, horizon, pmap):
yi = math.floor(p1.y) & 1023
xmap = (math.floor(p1.x) - pmap.x+256)
ymap = (math.floor(p1.y) - pmap.y+256)
if (xmap<512) and (ymap<512):
if (xmap>=0) and (ymap>=0):
screenmap[xmap, ymap] = 0xFFFFFF
screenmap[xmap+512, ymap] = 0xFFFFFF
if screen.width != 700:
if (xmap<512) and (ymap<512):
if (xmap>=0) and (ymap>=0):
screenmap[xmap, ymap] = 0xFFFFFF
screenmap[xmap+512, ymap] = 0xFFFFFF
DrawVerticalLine(i, (heightmap[xi, yi]+offset)*scale+horizon, 511, colormap[xi, yi])
p1.x += dx
p1.y += dy
@@ -77,17 +87,18 @@ def HorlineHidden(p1, p2, offset, scale, horizon, pmap):
yi = math.floor(p1.y) & 1023
xmap = (math.floor(p1.x) - pmap.x+256)
ymap = (math.floor(p1.y) - pmap.y+256)
if (xmap<512) and (ymap<512):
if (xmap>=0) and (ymap>=0):
screenmap[xmap, ymap] = 0xFFFFFF
screenmap[xmap+512, ymap] = 0xFFFFFF
if screen.width != 700:
if (xmap<512) and (ymap<512):
if (xmap>=0) and (ymap>=0):
screenmap[xmap, ymap] = 0xFFFFFF
screenmap[xmap+512, ymap] = 0xFFFFFF
heightonscreen = (heightmap[xi, yi] + offset) * scale + horizon
DrawVerticalLine(i, heightonscreen, hidden[i], colormap[xi, yi])
if heightonscreen < hidden[i]:
hidden[i] = heightonscreen
p1.x += dx
p1.y += dy
Store()
# Store()

# -----------------------------------------------------

@@ -99,22 +110,27 @@ def Rotate(p, phi):
# -----------------------------------------------------

def ClearAndDrawMaps(pmap):
for j in range(0, 512):
for i in range(0, 512):
h = heightmap[(i+pmap.x-256) & 1023, (j+pmap.y-256) & 1023]
c = colormap[(i+pmap.x-256) & 1023, (j+pmap.y-256) & 1023]
screenmap[i, j] = (pal[c*3+2]<< 16) | (pal[c*3+1] << 8) | pal[c*3+0]
screenmap[i+512, j] = (h<<16) | (h << 8) | h

for j in range(0, 512):
for i in range(0, 700):
screenmap[i+1024, j] = 0xffa366
if screen.width == 700:
for j in range(0, 512):
for i in range(0, 700):
screenmap[i, j] = 0xffa366
else:
for j in range(0, 512):
for i in range(0, 512):
h = heightmap[(i+pmap.x-256) & 1023, (j+pmap.y-256) & 1023]
c = colormap[(i+pmap.x-256) & 1023, (j+pmap.y-256) & 1023]
screenmap[i, j] = (pal[c*3+2]<< 16) | (pal[c*3+1] << 8) | pal[c*3+0]
screenmap[i+512, j] = (h<<16) | (h << 8) | h

for j in range(0, 512):
for i in range(0, 700):
screenmap[i+1024, j] = 0xffa366

# -----------------------------------------------------

def DrawBackToFront(p, phi, height, pmap):
def DrawBackToFront(p, phi, height, distance, pmap):
ClearAndDrawMaps(pmap)
for z in range(240, 1, -2):
for z in range(distance, 1, -2):
pl = Point(-z, -z)
pr = Point( z, -z)
pl = Rotate(pl, phi)
@@ -126,41 +142,42 @@ def DrawBackToFront(p, phi, height, pmap):

# -----------------------------------------------------

def DrawFrontToBack(p, phi, height, pmap):
def DrawFrontToBack(p, phi, height, distance, pmap):
ClearAndDrawMaps(pmap)
dz = 1
z = 10
z = 5

for i in range(0, 700):
hidden[i] = 512
hidden[i] = 511

while z < 400:
while z < distance:
pl = Point(-z, -z)
pr = Point( z, -z)
pl = Rotate(pl, phi)
pr = Rotate(pr, phi)
HorlineHidden(
Point(p.x + pl.x, p.y + pl.y),
Point(p.x + pr.x, p.y + pr.y),
-height, -1./z*240., +120, pmap)
-height, -1./z*240., +100, pmap)
z += dz
dz += 0.2
#dz += 0.1

# -----------------------------------------------------

#Init(512+512+700, 512, "C1W.png", "D1.png")

#DrawBackToFront(Point(230, 0), 0, 50, Point(230, 0))
DrawFrontToBack(Point(230, 0), 0, 50, Point(230, 0))

#for i in range(0, 40):
# print(i)
# paint((250, 500 - i*10), 0, 45)
# Store.n=1
# Store()
#DrawBackToFront(Point(230, 0), 0, 50, 240, Point(230, 0))
#DrawFrontToBack(Point(230, 0), 0, 50, 400, Point(230, 0))

#for i in range(0, 360, 10):
# print(i)
# Draw(Point(590, 175), i/180.*3.141592, 50, Point(590, 175))
# DrawFrontToBack(Point(590, 175), i/180.*3.141592, 50, 240, Point(590, 175))
# Store.n=1
# Store()

Init(700, 512, "C7W.png", "D7.png")
for i in range(0, 64):
print(i)
DrawFrontToBack(Point(670, 500 - i*16), 0, 120, 800, Point(670, 500 - i*16))
Store.n=1
Store()
@@ -10,7 +10,4 @@ echo anim
python anim.py

echo convert
#convert images/out*.png -layers OptimizeFrame -delay 100 -loop 0 out.gif
#gifsicle out.gif > outoptim.gif

gifsicle --colors 256 --optimize=2 --delay=10 --loop images/*.gif > anim.gif
@@ -0,0 +1,13 @@
set -e

mkdir -p images

echo delete
rm -f images/*.png
rm -f images/*.gif

echo anim
python anim.py

echo convert
gifsicle --optimize=3 --scale=0.5 --delay=5 --loop images/*.gif > anim.gif

0 comments on commit 5122922

Please sign in to comment.