SHARE
TWEET

Untitled

a guest Oct 18th, 2019 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #$ LINK             = true
  2. #$ LIBRARIES(macOS) = libpng libjpeg zlib
  3.  
  4. uses Bitmap
  5.  
  6. # Generate 3/4 pit edge tiles
  7. # Some side tiles may not tile seamlessly if the dropped side is too close to the bottom and gets truncated.
  8. # These are easy to spot. Just keep generating new tiles until you get enough good side tiles.
  9.  
  10. routine rogo_edges
  11.   local edges = Bitmap( 6*100, 6*100, Color.BLACK )
  12.   forEach (i in 1..4)
  13.     generate_top_edge( XY(0,16), XY(99,16), 8, Bitmap(100,100,Color.BLACK) ).blit( edges, XY(i*100,0) )
  14.     generate_bottom_edge( XY(0,99-16), XY(99,99-16), 8, Bitmap(100,100,Color.BLACK) ).blit( edges, XY(i*100,5*100) )
  15.     generate_left_edge( XY(16,0), XY(16,99), 8, Bitmap(100,100,Color.BLACK) ).blit( edges, XY(0,i*100) )
  16.     generate_right_edge( XY(99-16,0), XY(99-16,99), 8, Bitmap(100,100,Color.BLACK) ).blit( edges, XY(5*100,i*100) )
  17.   endForEach
  18.   edges.save_as_png( File("Edges.png") )
  19.   println "Generated Edges.png"
  20. endRoutine
  21.  
  22. routine generate_top_edge( left:XY, right:XY, max_variance:Int32, bitmap:Bitmap )->Bitmap
  23.   left = left.floor
  24.   right = right.floor
  25.   local w = Int32(right.x - left.x)
  26.   if (w > 10)
  27.     local xv = Random.int32( -max_variance, max_variance )
  28.     local yv = Random.int32( -max_variance, max_variance )
  29.     local mid = (((left + right) / 2) + XY(xv,yv)).floor
  30.     generate_top_edge( left, mid, max_variance/2, bitmap )
  31.     generate_top_edge( mid, right, max_variance/2, bitmap )
  32.   else
  33.     local gen = BresenhamLineGenerator(left,right)
  34.     forEach (pt in gen)
  35.       local color = select{ left.y<=right.y:Color.LIGHT_GRAY || Color.GRAY }
  36.       bitmap.draw( Line(pt,pt+XY(0,24)), color )
  37.       bitmap.draw( Line(pt.xv,pt), Color.WHITE )
  38.     endForEach
  39.   endIf
  40.   return bitmap
  41. endRoutine
  42.  
  43. routine generate_bottom_edge( left:XY, right:XY, max_variance:Int32, bitmap:Bitmap )->Bitmap
  44.   left = left.floor
  45.   right = right.floor
  46.   local w = Int32(right.x - left.x)
  47.   if (w > 10)
  48.     local xv = Random.int32( -max_variance, max_variance )
  49.     local yv = Random.int32( -max_variance, max_variance )
  50.     local mid = (((left + right) / 2) + XY(xv,yv)).floor
  51.     generate_bottom_edge( left, mid, max_variance/2, bitmap )
  52.     generate_bottom_edge( mid, right, max_variance/2, bitmap )
  53.   else
  54.     local gen = BresenhamLineGenerator(left,right)
  55.     forEach (pt in gen)
  56.       bitmap.draw( Line(pt,pt.xv+XY(0,99)), Color.WHITE )
  57.     endForEach
  58.   endIf
  59.   return bitmap
  60. endRoutine
  61.  
  62. routine generate_left_edge( top:XY, bottom:XY, max_variance:Int32, bitmap:Bitmap )->Bitmap
  63.   top = top.floor
  64.   bottom = bottom.floor
  65.   local h = Int32(bottom.y - top.y)
  66.   if (h > 10)
  67.     local xv = Random.int32( -max_variance, max_variance )
  68.     local yv = Random.int32( -max_variance, max_variance )
  69.     local mid = (((top + bottom) / 2) + XY(xv,yv)).floor
  70.     generate_left_edge( top, mid, max_variance/2, bitmap )
  71.     generate_left_edge( mid, bottom, max_variance/2, bitmap )
  72.   else
  73.     local gen = BresenhamLineGenerator(top,bottom)
  74.     forEach (pt in gen)
  75.       bitmap.draw( Line(pt,pt+XY(0,24)), Color.GRAY )
  76.       bitmap.draw( Line(pt.yv,pt), Color.WHITE )
  77.     endForEach
  78.   endIf
  79.   return bitmap
  80. endRoutine
  81.  
  82. routine generate_right_edge( top:XY, bottom:XY, max_variance:Int32, bitmap:Bitmap )->Bitmap
  83.   top = top.floor
  84.   bottom = bottom.floor
  85.   local h = Int32(bottom.y - top.y)
  86.   if (h > 10)
  87.     local xv = Random.int32( -max_variance, max_variance )
  88.     local yv = Random.int32( -max_variance, max_variance )
  89.     local mid = (((top + bottom) / 2) + XY(xv,yv)).floor
  90.     generate_right_edge( top, mid, max_variance/2, bitmap )
  91.     generate_right_edge( mid, bottom, max_variance/2, bitmap )
  92.   else
  93.     local gen = BresenhamLineGenerator(top,bottom)
  94.     forEach (pt in gen)
  95.       bitmap.draw( Line(pt,pt+XY(0,24)), Color.LIGHT_GRAY )
  96.       bitmap.draw( Line(pt,XY(99,pt.y)), Color.WHITE )
  97.     endForEach
  98.   endIf
  99.   return bitmap
  100. endRoutine
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top