Advertisement
Guest User

Untitled

a guest
Jun 11th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. precalc = Timer()
  2. Smooth2D ON
  3. path$="media/map.bmp"
  4. img=LoadImage(path)
  5. imgw = ImageWidth(img)
  6. imgh = ImageHeight(img)
  7. DeleteImage img
  8. SCREEN imgw, imgh
  9. img=LoadImage(path)
  10. Dim bump(imgw-1,imgh-1,2) As Float
  11. Dim gs(imgw-1,imgh-1)
  12. Dim ldir(imgw*2, imgh*2, 2) As Float
  13. Dim cols(imgw-1,imgh-1, 2)
  14.  
  15. For i = 0 To imgw-1//lasketaan harmaasävy(=korkeus)taulu
  16.     For j = 0 To imgh-1
  17.         PickImageColor img, i, j
  18.         rr = getRGB(1)
  19.         gg = getRGB(2)
  20.         bb = getRGB(3)
  21.         gs(i,j)=(rr+gg+bb)/3.0
  22.         cols(i, j, 0) = rr
  23.         cols(i, j, 1) = gg
  24.         cols(i, j, 2) = bb
  25.     Next j
  26. Next i
  27.  
  28. For i=0 To imgw-1//lasketaan normaalitaulu
  29.     For j=0 To imgh-1
  30.         bump(i,j,0)=gs(i,j)-gs(i+1,j)//ristitulo
  31.         bump(i,j,1)=gs(i,j)-gs(i,j+1)
  32.         bump(i,j,2)=1.0
  33.         l#=Sqrt(bump(i,j,0)^2+bump(i,j,1)^2+bump(i,j,2)^2)//normalisointi
  34.         bump(i,j,0)=bump(i,j,0)/l
  35.         bump(i,j,1)=bump(i,j,1)/l
  36.         bump(i,j,2)=bump(i,j,2)/l
  37.     Next j
  38. Next i
  39.  
  40. For i = 0 To imgw*2//lasketaan valotaulu
  41.     For j = 0 To imgh*2
  42.         mx# = imgw-i
  43.         my# = imgh-j
  44.         mz# = 80.0
  45.         ml# = Sqrt(mx*mx+my*my+mz*mz)*(4+Distance(mx, my, 0, 0))^1.2
  46.         ldir(i, j, 0)=mx/ml
  47.         ldir(i, j, 1)=my/ml
  48.         ldir(i, j, 2)=mz/ml
  49.     Next j
  50. Next i
  51. Color 0, 0, 0
  52.  
  53. precalc = Timer() - precalc
  54.  
  55. Repeat
  56.     mmx = MouseX()//imgw/2.0+(imgw/4.0)*Sin(Timer()*.03)
  57.     mmy = MouseY()//imgh/2.0+(imgh/4.0)*Cos(Timer()*.02)
  58.     mox = Max(0, Min(imgw, imgw-mmx))
  59.     moy = Max(0, Min(imgh, imgh-mmy))
  60.     frame = (frame + 1) Mod 4
  61.     xframe = frame Mod 2
  62.     yframe = (frame/2) Mod 2
  63.     Lock
  64.         For i = xframe To imgw-2 Step 2
  65.             For j = yframe Mod 2 To imgh-2 Step 2
  66.                 imox = i+mox
  67.                 jmoy = j+moy
  68.                 c# = Min(1.0, Max(.0, .1+120.0*(ldir(imox, jmoy,0)*bump(i,j,0)+ldir(imox, jmoy,1)*bump(i,j,1)+ldir(imox, jmoy,2)*bump(i,j,2))))
  69.                 PutPixel2 i, j, int(cols(i, j, 0)*c Shl 16+cols(i,j,1)*c Shl 8+cols(i,j,2)*c)
  70.             Next j
  71.         Next i
  72.     Unlock
  73.     SetWindow ""+FPS() + " FPS, "+precalc+"ms precalc"
  74.     DrawScreen OFF
  75. Forever
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement