Sorceress

bilinear thing

Jan 12th, 2019
809
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SCREEN _NEWIMAGE(640, 480, 32)
  2. DIM c(32, 24) AS SINGLE
  3.  
  4. FOR x = 0 TO 31
  5.   FOR y = 0 TO 23
  6.     c(x, y) = RND
  7.   NEXT
  8. NEXT
  9.  
  10. m = 20: m1 = m - 1
  11.  
  12.  
  13. 'nearest neighbour
  14. FOR x = 0 TO 639: ix = x \ m
  15.   FOR y = 0 TO 479: iy = y \ m
  16.     i = c(ix, iy) * 255
  17.     PSET (x, y), _RGB(i, i, 255 - i)
  18.   NEXT
  19. NEXT
  20. SLEEP
  21.  
  22. 'bilinear
  23. FOR x = 0 TO 639: ix = x \ m: rx = x / m - ix: ix1 = (ix + 1) MOD 32: rx1 = 1 - rx
  24.   FOR y = 0 TO 479: iy = y \ m: ry = y / m - iy: iy1 = (iy + 1) MOD 24: ry1 = 1 - ry
  25.     c00 = c(ix, iy) * 255
  26.     c10 = c(ix1, iy) * 255
  27.     c01 = c(ix, iy1) * 255
  28.     c11 = c(ix1, iy1) * 255
  29.     i = (c00 * rx1 + c10 * rx) * ry1 + (c01 * rx1 + c11 * rx) * ry
  30.     PSET (x, y), _RGB(i, i, 255 - i)
  31.   NEXT
  32. NEXT
  33. SLEEP
  34.  
  35. 'cosine
  36. FOR x = 0 TO 639: ix = x \ m: rx = cs(x / m - ix): ix1 = (ix + 1) MOD 32: rx1 = 1 - rx
  37.   FOR y = 0 TO 479: iy = y \ m: ry = cs(y / m - iy): iy1 = (iy + 1) MOD 24: ry1 = 1 - ry
  38.     c00 = c(ix, iy) * 255
  39.     c10 = c(ix1, iy) * 255
  40.     c01 = c(ix, iy1) * 255
  41.     c11 = c(ix1, iy1) * 255
  42.     i = (c00 * rx1 + c10 * rx) * ry1 + (c01 * rx1 + c11 * rx) * ry
  43.     PSET (x, y), _RGB(i, i, 255 - i)
  44.   NEXT
  45. NEXT
  46. SLEEP
  47.  
  48. 'smoothstep
  49. FOR x = 0 TO 639: ix = x \ m: rx = sm(x / m - ix): ix1 = (ix + 1) MOD 32: rx1 = 1 - rx
  50.   FOR y = 0 TO 479: iy = y \ m: ry = sm(y / m - iy): iy1 = (iy + 1) MOD 24: ry1 = 1 - ry
  51.     c00 = c(ix, iy) * 255
  52.     c10 = c(ix1, iy) * 255
  53.     c01 = c(ix, iy1) * 255
  54.     c11 = c(ix1, iy1) * 255
  55.     i = (c00 * rx1 + c10 * rx) * ry1 + (c01 * rx1 + c11 * rx) * ry
  56.     PSET (x, y), _RGB(i, i, 255 - i)
  57.   NEXT
  58. NEXT
  59. SLEEP
  60.  
  61. 'the smoothstep function
  62. FUNCTION sm (t)
  63.   sm = t * t * (3 - 2 * t)
  64. END FUNCTION
  65.  
  66. ' the "cosine" function
  67. FUNCTION cs (t)
  68.   cs = SIN(t * 1.5707963): cs = cs * cs
  69. END FUNCTION
RAW Paste Data