DragonRuby Game Toolkit
Postcarts

Creating DragonRuby Postcarts

Postcarts are tiny DragonRuby programs that fit within 300 characters. They're a creative challenge that combines programming and art!

Getting Started

Every postcart starts with the TICK block - this is where your animation code goes:

TICK { |args|
  # Your code here
}

Essential Functions

Drawing

The postcart canvas is 160x90 pixels

  • sld!(x, y) - Draw a 1x1 pixel at (x,y)
  • sld!(x, y, w, h) - Draw a rectangle
  • sld!(x, y, [r,g,b]) - Draw a colored pixel
  • sld!(x, y, w, h, [r,g,b]) - Draw a colored rectangle
  • slds! - Batch draw multiple shapes: slds!([x1,y1], [x2,y2,w,h], [x3,y3,[r,g,b]])

Colors

  • bg!(r,g,b) - Set background color
  • color(n) - Use predefined palette color (0-31)
  • pal - Access the full color palette

Math Helpers

  • sin(degrees) / cos(degrees) - Trig functions using degrees
  • sin_r(radians) / cos_r(radians) - Trig functions using radians
  • tc - Get current tick count (useful for animations)

Canvas Control

  • scene!(w, h, scale) - Set canvas size and scale
  • no_clr! - Disable auto-clearing (for trails effect)
  • pixels! - Switch to pixel rendering mode

Example Tweetcart

TICK{
  bg! 0
  64.times{|i|
    x=Math.sin(i*15+tc)*20+80
    y=Math.cos(i*15+tc)*20+45
    sld! x,y,[255,i*4,255-i*4]
  }
}

This creates a colorful spinning circle animation!

Tips for 300-Character Limit

  • Remove unnecessary spaces and newlines
  • Use short variable names
  • Chain methods when possible
  • Use the tc shorthand for tick count
  • Leverage the predefined color palette with color(n)