Commit d975a3105ed507c302d33d0894600ad51ab3f7c1

Authored by Anthex
1 parent a44804db

fix mapping from values to images, now works with steps/emitters that are out of…

… bounds compared to the initial situation
Showing 2 changed files with 21 additions and 9 deletions   Show diff stats
structure.py
... ... @@ -281,13 +281,14 @@ def NLateration(data, step=.1, xSize=0.0, ySize=0.0, zSize=0.0):
281 281 '''
282 282 minLoc = Location()
283 283 minDist = 0.0
  284 + revStep = ceil(1/step)
284 285 #gifArray = []
285 286 for k in data:
286 287 minDist += abs(k[0].distanceTo(Location()) - k[1])
287 288 xSize = k[0].x if k[0].x > xSize else xSize
288 289 ySize = k[0].y if k[0].y > ySize else ySize
289 290 zSize = k[0].z if k[0].z > zSize else zSize
290   - imageArray=[[] for i in range(0,floor(zSize*10))]
  291 + imageArray=[[] for i in range(0,floor(zSize*revStep))]
291 292 for k in arange(0,xSize,step):
292 293 for l in arange(0,ySize,step):
293 294 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):
298 299 minDist = d
299 300 minLoc = Location(round(k,2),round(l,2),round(m,2))
300 301 d = (max(1-d/10.0, 0))**2
301   - imageArray[floor(l*10)].append((250-floor(360-d*360), 255, floor(50+d*200)))
302   - return (minLoc, minDist, imageArray[0], floor(ySize/step), floor(xSize/step), imageArray)
  302 + imageArray[floor(m*revStep)].append((265-floor(360-d*360), 255, floor(50+d*200)))
  303 + return (minLoc, minDist, imageArray[0], floor(xSize*revStep), floor(ySize*revStep), imageArray)
... ...
visuals.py
... ... @@ -2,24 +2,35 @@ from structure import NLateration, Location
2 2 from math import floor, sqrt
3 3 from PIL import Image, ImageDraw
4 4  
5   -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)]
6   -NLat_result = NLateration(dataset)
  5 +global_step=.05
  6 +dataset = [(Location(.5,.5,.5), 3.0), (Location(4.0,.0,.0), 2.0), (Location(4.0,5.0,5.0), 4.2)]
  7 +NLat_result = NLateration(dataset, step=global_step)
7 8 W,H = NLat_result[3], NLat_result[4]
8 9 frames = []
9 10 dummy = [0 for _ in range(len(NLat_result[5][0]))]
10 11  
11 12 def createFrame(x,y,nbr):
12   - img = Image.new("HSV",(x,y))
  13 + img = Image.new("HSV",(y,x))
13 14 img.putdata(NLat_result[5][nbr])
14 15 return img
15 16  
  17 +
16 18 def exportGif():
17 19 for i in range(len(NLat_result[5])):
18 20 newFrame = createFrame(W,H,i)
  21 + newFrame = newFrame.resize((W*10,H*10), Image.BICUBIC)
  22 + draw = ImageDraw.Draw(newFrame)
  23 + draw.text(text="z="+str(round(i*global_step,2)), xy=(0,0))
  24 + frames.append(newFrame)
  25 +
  26 + for i in range(len(NLat_result[5])):
  27 + newFrame = createFrame(W,H,len(NLat_result[5])-i-1)
19 28 newFrame = newFrame.resize((W*10,H*10), Image.ANTIALIAS)
20 29 draw = ImageDraw.Draw(newFrame)
21   - draw.text(text="z="+str(i), xy=(0,0))
  30 + draw.text(text="z="+str(round(((len(NLat_result[5])-i-1)*global_step),2)), xy=(0,0))
22 31 frames.append(newFrame)
23   -
24   - frames[0].save("out.gif", format="GIF", append_images=frames[1:], save_all=True, duration=100, loop=0)
  32 +
  33 + frames[0].save("out.gif", format="GIF", append_images=frames[1:], save_all=True, duration=20, loop=0)
25 34 print("gif exported")
  35 +
  36 +exportGif()
26 37 \ No newline at end of file
... ...