Skip to content

Instantly share code, notes, and snippets.

@oeloeloel
oeloeloel / main.rb
Last active August 30, 2024 14:13
DragonRuby Button Experiment (low responsibility three-state button)
# A small POC experiment with buttons (it doesn't attempt to solve all the problems)
# the button method implements behaviour for a three-state button
# it accounts for button "layers" that can be formed from multiple primitives
# it doesn't impose other constraints on the dev, so the dev is free to make
# the buttons any way they like. This code shows:
# • A button made from a basic rect and label (with a bonus arbitrary rect for the active state)
# • A resizable button with rounded ends and a 2 pixel outline (1 label, 6 sprites)
def tick args
args.outputs.background_color = {r: 88, g: 124, b: 204}
@oeloeloel
oeloeloel / main.rb
Last active June 22, 2023 14:44
Visualisation: DragonRuby built-in spline function
$gtk.reset
SPLINE = [
[0.0, 0.99, 0.99, 1.0]
]
def tick args
# duration of movement
args.state.duration = 4.seconds
@oeloeloel
oeloeloel / main.rb
Created March 26, 2023 16:27
buffer pixel array data to persist across ticks
# buffer pixel array data to persist across ticks
def tick args
dimension = 100 # keep it small and let the GPU scale it when rendering the sprite.
if args.tick_count.zero?
# Set up our "parray" pixel array and fill it with black pixels.
args.pixel_array(:parray).width = dimension
args.pixel_array(:parray).height = dimension
args.pixel_array(:parray).pixels.fill(0xFFFFFFFF, 0, dimension * dimension) # black, full alpha
@oeloeloel
oeloeloel / main.rb
Last active January 28, 2023 00:10
1nvader
def tick(args)
args.state.game_state ||= 'playing'
args.state.player ||= {
x: 100, y: 40, w: 80, h: 80, angle: 90,
path: 'sprites/circle/blue.png'
}
args.state.player_bullet ||= {
x: 130, y: 800, w: 20, h: 20,
path: 'sprites/triangle/equilateral/blue.png'
}
@oeloeloel
oeloeloel / main.rb
Created August 3, 2021 18:09
Modification of KFischer's Array Splat Performance Test
class AnObject
attr_reader :a, :b, :c, :d, :e, :f
def initialize
@a = 1
@b = 1
@c = 1
@d = 1
@e = 1
@f = 1
end
@oeloeloel
oeloeloel / main.rb
Last active July 6, 2021 18:15
Supersampling for even rotation of odd sized sprites
# supersampling for fancy sprite rotation
# solves uneven rotation of odd-sized sprites
# using an upscaled render target
def tick(args)
args.state.size ||= 7 # width/height of sprite (odd)
args.state.upsample ||= 8 # 2 minimum, 8 is better
args.state.path ||= 'sprites/rotate5.png' # path to sprite
args.state.upsample_size ||= args.state.size * args.state.upsample
@oeloeloel
oeloeloel / main.rb
Last active July 2, 2021 20:41
Remove specified background colour from sprite/spritesheet
# cromakey no chromakey
# removes a specified background colour from a spritesheet
# by making it transparent and exports it as a new file.
# change these values then run in DragonRuby
# path to spritesheet
INPUT_FILE = '/sprites/chroma-test-input.png'
# path to export file
OUTPUT_FILE = '/sprites/chroma-test-output.png'
@oeloeloel
oeloeloel / main.rb
Created April 3, 2021 05:05
Breakout made quickly
$gtk.reset
def tick args
defaults args
handle_input args
calc args
render args
end
def handle_input args
@oeloeloel
oeloeloel / ext.c
Last active November 26, 2021 07:11
DragonRuby Pixel Arrays with C Extensions. Quick and Dirty example.
/*
DragonRuby C Extension Pixel Array
Written by @Akzidenz-Grotesk (with help from @AlexDenisov & @Kenneth | CANICVS)
Demonstrates some quick and pretty dirty image filters
Loads image files into Pixel Array
Performs image manipulation every tick
Returns a modified 100x100 pixel image to DragonRuby
*/
#ifndef NULL
@oeloeloel
oeloeloel / main.rb
Created October 2, 2020 18:40
Bresenham Circle in DragonRuby
# Bresenham circle for DragonRuby (basic)
RED = [255, 0, 0]
def put_pixel(args, x, y, c)
args.outputs.solids << [x, y, 1, 1, *c]
end
def drawCircle(args, xc, yc, x, y)
put_pixel(args, xc + x, yc + y, RED)