Advertisement
benn-1956

Image Parsing

Feb 23rd, 2024
1,144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
GDScript 0.81 KB | Gaming | 0 0
  1. extends Node
  2.  
  3. var bit : int = 0
  4. var img = Image.load_from_file("res://lvl.png")
  5.  
  6.  
  7.  
  8. func _ready():
  9.     print_debug("this is a test")
  10.     Gen_Lvl()
  11.  
  12. func check_pxl(x,y):
  13.     if !img.get_pixel(x,y): #check self
  14.         bit = 0
  15.         if !img.get_pixel(x,y + 1): # check for pixel up
  16.             bit += 1
  17.             bit <<= 1
  18.         else:
  19.             bit <<= 1
  20.         if !img.get_pixel(x,y -1): # check for pixel down
  21.             bit += 1
  22.             bit <<= 1
  23.         else:
  24.             bit <<= 1
  25.         if !img.get_pixel(x - 1,y): # check for pixel left
  26.             bit += 1
  27.             bit <<= 1
  28.         else:
  29.             bit <<= 1
  30.         if !img.get_pixel(x + 1,y): # check for pixel right
  31.             bit += 1
  32.         return bit
  33.        
  34. func Gen_Lvl():
  35.     var img_size = img.get_size()
  36.     print(img_size)
  37.     for x in img_size.x:
  38.         for y in img_size.y:
  39.             var data = check_pxl(x,y)
  40.             if data != null:
  41.                 print("at ", x, ",", y, " bit is ", data)
  42.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement