Advertisement
Guest User

Untitled

a guest
May 18th, 2017
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.51 KB | None | 0 0
  1. require "scripts/perlin"
  2.  
  3. t=perlinGenerator:new();
  4. t:generateLookup();
  5. t.res=0.5;
  6. t.oct=10;
  7. t.zoom=100;
  8.  
  9. n=0
  10. m=0
  11. tpt.set_pause(1);
  12. function elemPick(x)
  13.     elem=0
  14.     if(x>0.67)then
  15.         elem=tpt.element("SNOW")
  16.     elseif(x>0.6)then
  17.         elem=tpt.element("STNE")
  18.     elseif(x>0.43)then
  19.         elem=tpt.element("PLNT")
  20.     elseif(x>0.4)then
  21.         elem=tpt.element("SAND")
  22.     else
  23.         elem=tpt.element("WATR")
  24.     end
  25.     return(elem)
  26. end
  27.  
  28. function river(x,y)
  29.     posx=x;
  30.     posy=y;
  31.     for i=0,200 do
  32.         val=t:perlinOctave(posx/zoom,posy/zoom,oct,res);
  33.         print(val,posx,posy)
  34.         repeat
  35.             posxn=posx+math.floor(math.random(-1,2))
  36.             posyn=posy+math.floor(math.random(-1,2))
  37.             nval=0.0;
  38.             nval=t:perlinOctave(posxn/zoom,posyn/zoom,oct,res)
  39.         until(nval<=val)
  40.         sim.createLine(posx,posy,posxn,posyn,0,0,tpt.element("WATR"),0,1,1);
  41.         posx=posxn;
  42.         posy=posyn;
  43.     end
  44. end
  45.  
  46. function shade(x,y)
  47.     mx=t:perlinOctave(x-1,y)-t:perlinOctave(x,y);
  48.     my=t:perlinOctave(x,y-1)-t:perlinOctave(x,y);
  49.     if math.max(mx,my)==mx then
  50.         col=0
  51.     else
  52.         col=20
  53.     end
  54.     if(math.max(math.abs(mx),math.max(math.abs(my)))==mx)then
  55.         sf=math.abs(mx)*255*10
  56.     else
  57.         sf=math.abs(my)*255*10
  58.     end
  59.    
  60.     sim.decoBox(m,n,m,n,col,col,col,math.abs(sf));
  61. end
  62.  
  63. function genMap()
  64.     while(n<382)do
  65.         while(m<611)do     
  66.             num=(t:perlinOctave(m,n)+1)/2;
  67.             if(num>0)then
  68.                
  69.                 index=tpt.create(m,n,elemPick(num));
  70.                 if(num>0.4)then
  71.                     shade(m,n)
  72.                 end
  73.                 --sim.decoBox(m,n,m,n,num*255,num*255,num*255);
  74.             end
  75.             m=m+1;
  76.         end
  77.         n=n+1;
  78.         m=0;
  79.     end
  80.     n=0;
  81. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement