Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #$ LINK = true
- #$ LIBRARIES(macOS) = libpng libjpeg zlib
- uses Bitmap
- # Generate 3/4 pit edge tiles
- # Some side tiles may not tile seamlessly if the dropped side is too close to the bottom and gets truncated.
- # These are easy to spot. Just keep generating new tiles until you get enough good side tiles.
- routine rogo_edges
- local edges = Bitmap( 6*100, 6*100, Color.BLACK )
- forEach (i in 1..4)
- generate_top_edge( XY(0,16), XY(99,16), 8, Bitmap(100,100,Color.BLACK) ).blit( edges, XY(i*100,0) )
- generate_bottom_edge( XY(0,99-16), XY(99,99-16), 8, Bitmap(100,100,Color.BLACK) ).blit( edges, XY(i*100,5*100) )
- generate_left_edge( XY(16,0), XY(16,99), 8, Bitmap(100,100,Color.BLACK) ).blit( edges, XY(0,i*100) )
- generate_right_edge( XY(99-16,0), XY(99-16,99), 8, Bitmap(100,100,Color.BLACK) ).blit( edges, XY(5*100,i*100) )
- endForEach
- edges.save_as_png( File("Edges.png") )
- println "Generated Edges.png"
- endRoutine
- routine generate_top_edge( left:XY, right:XY, max_variance:Int32, bitmap:Bitmap )->Bitmap
- left = left.floor
- right = right.floor
- local w = Int32(right.x - left.x)
- if (w > 10)
- local xv = Random.int32( -max_variance, max_variance )
- local yv = Random.int32( -max_variance, max_variance )
- local mid = (((left + right) / 2) + XY(xv,yv)).floor
- generate_top_edge( left, mid, max_variance/2, bitmap )
- generate_top_edge( mid, right, max_variance/2, bitmap )
- else
- local gen = BresenhamLineGenerator(left,right)
- forEach (pt in gen)
- local color = select{ left.y<=right.y:Color.LIGHT_GRAY || Color.GRAY }
- bitmap.draw( Line(pt,pt+XY(0,24)), color )
- bitmap.draw( Line(pt.xv,pt), Color.WHITE )
- endForEach
- endIf
- return bitmap
- endRoutine
- routine generate_bottom_edge( left:XY, right:XY, max_variance:Int32, bitmap:Bitmap )->Bitmap
- left = left.floor
- right = right.floor
- local w = Int32(right.x - left.x)
- if (w > 10)
- local xv = Random.int32( -max_variance, max_variance )
- local yv = Random.int32( -max_variance, max_variance )
- local mid = (((left + right) / 2) + XY(xv,yv)).floor
- generate_bottom_edge( left, mid, max_variance/2, bitmap )
- generate_bottom_edge( mid, right, max_variance/2, bitmap )
- else
- local gen = BresenhamLineGenerator(left,right)
- forEach (pt in gen)
- bitmap.draw( Line(pt,pt.xv+XY(0,99)), Color.WHITE )
- endForEach
- endIf
- return bitmap
- endRoutine
- routine generate_left_edge( top:XY, bottom:XY, max_variance:Int32, bitmap:Bitmap )->Bitmap
- top = top.floor
- bottom = bottom.floor
- local h = Int32(bottom.y - top.y)
- if (h > 10)
- local xv = Random.int32( -max_variance, max_variance )
- local yv = Random.int32( -max_variance, max_variance )
- local mid = (((top + bottom) / 2) + XY(xv,yv)).floor
- generate_left_edge( top, mid, max_variance/2, bitmap )
- generate_left_edge( mid, bottom, max_variance/2, bitmap )
- else
- local gen = BresenhamLineGenerator(top,bottom)
- forEach (pt in gen)
- bitmap.draw( Line(pt,pt+XY(0,24)), Color.GRAY )
- bitmap.draw( Line(pt.yv,pt), Color.WHITE )
- endForEach
- endIf
- return bitmap
- endRoutine
- routine generate_right_edge( top:XY, bottom:XY, max_variance:Int32, bitmap:Bitmap )->Bitmap
- top = top.floor
- bottom = bottom.floor
- local h = Int32(bottom.y - top.y)
- if (h > 10)
- local xv = Random.int32( -max_variance, max_variance )
- local yv = Random.int32( -max_variance, max_variance )
- local mid = (((top + bottom) / 2) + XY(xv,yv)).floor
- generate_right_edge( top, mid, max_variance/2, bitmap )
- generate_right_edge( mid, bottom, max_variance/2, bitmap )
- else
- local gen = BresenhamLineGenerator(top,bottom)
- forEach (pt in gen)
- bitmap.draw( Line(pt,pt+XY(0,24)), Color.LIGHT_GRAY )
- bitmap.draw( Line(pt,XY(99,pt.y)), Color.WHITE )
- endForEach
- endIf
- return bitmap
- endRoutine
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement