From d975a3105ed507c302d33d0894600ad51ab3f7c1 Mon Sep 17 00:00:00 2001 From: Anthex Date: Sat, 27 Apr 2019 03:40:10 +0200 Subject: [PATCH] fix mapping from values to images, now works with steps/emitters that are out of bounds compared to the initial situation --- structure.py | 7 ++++--- visuals.py | 23 +++++++++++++++++------ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/structure.py b/structure.py index b6e7e64..3213396 100644 --- a/structure.py +++ b/structure.py @@ -281,13 +281,14 @@ def NLateration(data, step=.1, xSize=0.0, ySize=0.0, zSize=0.0): ''' minLoc = Location() minDist = 0.0 + revStep = ceil(1/step) #gifArray = [] for k in data: minDist += abs(k[0].distanceTo(Location()) - k[1]) xSize = k[0].x if k[0].x > xSize else xSize ySize = k[0].y if k[0].y > ySize else ySize zSize = k[0].z if k[0].z > zSize else zSize - imageArray=[[] for i in range(0,floor(zSize*10))] + imageArray=[[] for i in range(0,floor(zSize*revStep))] for k in arange(0,xSize,step): for l in arange(0,ySize,step): for m in arange(0,zSize,step): @@ -298,5 +299,5 @@ def NLateration(data, step=.1, xSize=0.0, ySize=0.0, zSize=0.0): minDist = d minLoc = Location(round(k,2),round(l,2),round(m,2)) d = (max(1-d/10.0, 0))**2 - imageArray[floor(l*10)].append((250-floor(360-d*360), 255, floor(50+d*200))) - return (minLoc, minDist, imageArray[0], floor(ySize/step), floor(xSize/step), imageArray) + imageArray[floor(m*revStep)].append((265-floor(360-d*360), 255, floor(50+d*200))) + return (minLoc, minDist, imageArray[0], floor(xSize*revStep), floor(ySize*revStep), imageArray) diff --git a/visuals.py b/visuals.py index 70e3d62..b6b6d22 100644 --- a/visuals.py +++ b/visuals.py @@ -2,24 +2,35 @@ from structure import NLateration, Location from math import floor, sqrt from PIL import Image, ImageDraw -dataset = [(Location(.5,.5,.5), 3.0), (Location(4.0,.0,.0), 2.0), (Location(4.0,5.0,5.0), 4.2), (Location(3.0,3.0,3.0), 2.5)] -NLat_result = NLateration(dataset) +global_step=.05 +dataset = [(Location(.5,.5,.5), 3.0), (Location(4.0,.0,.0), 2.0), (Location(4.0,5.0,5.0), 4.2)] +NLat_result = NLateration(dataset, step=global_step) W,H = NLat_result[3], NLat_result[4] frames = [] dummy = [0 for _ in range(len(NLat_result[5][0]))] def createFrame(x,y,nbr): - img = Image.new("HSV",(x,y)) + img = Image.new("HSV",(y,x)) img.putdata(NLat_result[5][nbr]) return img + def exportGif(): for i in range(len(NLat_result[5])): newFrame = createFrame(W,H,i) + newFrame = newFrame.resize((W*10,H*10), Image.BICUBIC) + draw = ImageDraw.Draw(newFrame) + draw.text(text="z="+str(round(i*global_step,2)), xy=(0,0)) + frames.append(newFrame) + + for i in range(len(NLat_result[5])): + newFrame = createFrame(W,H,len(NLat_result[5])-i-1) newFrame = newFrame.resize((W*10,H*10), Image.ANTIALIAS) draw = ImageDraw.Draw(newFrame) - draw.text(text="z="+str(i), xy=(0,0)) + draw.text(text="z="+str(round(((len(NLat_result[5])-i-1)*global_step),2)), xy=(0,0)) frames.append(newFrame) - - frames[0].save("out.gif", format="GIF", append_images=frames[1:], save_all=True, duration=100, loop=0) + + frames[0].save("out.gif", format="GIF", append_images=frames[1:], save_all=True, duration=20, loop=0) print("gif exported") + +exportGif() \ No newline at end of file -- libgit2 0.21.4