Guest User

STREAM_IMAGE Example for TIS-100

a guest
Jun 19th, 2015
2,677
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.20 KB | None | 0 0
  1. function get_name()
  2.     return "STREAM_IMAGE EXAMPLE"
  3. end
  4.  
  5. function get_description()
  6.     return { "READ AN X VALUE FROM IN", "READ A Y VALUE FROM IN", "PLOT A WHITE POINT AT THAT COORDINATE" }
  7. end
  8.  
  9. function get_streams()
  10.     -- Initialize the image grid to all zeros (black):
  11.     image = {}
  12.     for i = 1,30*18 do
  13.         image[i] = 0
  14.     end
  15.    
  16.     -- Generate and plot 19 coordinate pairs:
  17.     -- NOTE: Arrays in Lua start at 1, which is actually quite a nuisance to work with if you're at all
  18.     --       used to arrays that start at 0 and the tricks that you can do to index them. It also doesn't
  19.     --       help that for loops are inclusive on both ends! Kind of makes me wish I implemented custom
  20.     --       levels in a real programming language like TIS-ASM...
  21.     input = {}
  22.     for i = 0,18 do
  23.         x = math.random(0,29)
  24.         y = math.random(0,17)
  25.         input[i*2+1] = x
  26.         input[i*2+2] = y
  27.         image[1+x+y*30] = 3
  28.     end
  29.    
  30.     return {
  31.         { STREAM_INPUT, "IN", 1, input },
  32.         { STREAM_IMAGE, "", 2, image },
  33.     }
  34. end
  35.  
  36. function get_layout()
  37.     return {
  38.         TILE_COMPUTE,   TILE_COMPUTE,   TILE_COMPUTE,   TILE_COMPUTE,
  39.         TILE_COMPUTE,   TILE_COMPUTE,   TILE_COMPUTE,   TILE_COMPUTE,
  40.         TILE_COMPUTE,   TILE_COMPUTE,   TILE_COMPUTE,   TILE_COMPUTE,
  41.     }
  42. end
Advertisement
Add Comment
Please, Sign In to add comment