Discord

Preparing your files

Please wait until the download is ready.

Luka's Scripting Utilities

Luka's Scripting Utilities

by Luka S.J.

A pack full of various scripting utilities to ease your development!

v4.1.135,194
Download144 KB

Bitmap Drawing

Sprites::Bitmap is a Bitmap subclass with higher-level drawing helpers for
text, shapes, masking and colour work. It can be created with the usual bitmap
arguments (a size or a file path) and accepts a configuration block.

bmp = Sprites::Bitmap.new("Graphics/Pictures/panel")
bmp.render_text("Hello", x: 8, y: 8, base: Color.white, outline: true)

It tracks the path it was loaded from (bitmap.path).

Text

  • bitmap.set_font(name:, size:, bold: false) set the font for subsequent text rendering
  • bitmap.render_text(text, x:, y:, align: :left, base: Color.white, shadow: Color.dark_gray, outline: false) draw a single line of text with shadow / optional outline; align is :left, :center or :right
  • bitmap.render_text_ex(text, x:, y:, width:, lines:, line_height: 32, base: Color.white, shadow: Color.dark_gray) draw word-wrapped text within a bounded box of lines lines

Shapes

  • bitmap.draw_circle(color, radius:, hollow: false) draw a filled (or, with hollow: true, outlined) circle

Colour & masking

  • bitmap.mask!(mask = nil, offset_x: 0, offset_y: 0) apply a mask using the alpha channel of another image — the mask may be a Bitmap, a Sprite, or a file-path String
  • bitmap.swap_colors(bmp) remap colours using a map bitmap whose first row lists source colours and second row lists target colours
  • bitmap.apply_tone(tone) apply a Tone directly to the pixel data (via the tone's lookup table)
  • bitmap.tolerance?(pixel, target) whether a pixel matches a target colour within tolerance
  • bitmap.finished? always true (bitmaps have no inherent animation; provided for interface parity)

Polygon rendering

Bitmaps::Polygon is a Bitmap subclass that draws a filled polygon from a
list of vertices using an optimised scanline fill. Create it with a size, add
vertices, then render.

poly = Bitmaps::Polygon.new(128, 128)
5.times { |i| poly.calc_vertex(percent: 1.0, angle: i * 72) }   # a pentagon
poly.render(Color.new(255, 80, 80))
  • polygon.add_vertex(x:, y:) add a vertex at an absolute point
  • polygon.calc_vertex(percent:, angle:) add a vertex by polar coordinates — percent of the bitmap radius at angle degrees from centre
  • polygon.render(color = Color.black) fill the polygon (needs at least 3 vertices)