Skip to content

Instantly share code, notes, and snippets.

@amirrajan
Created January 27, 2026 06:43
Show Gist options
  • Select an option

  • Save amirrajan/44174e1f903fdec41a565fa94cade2d5 to your computer and use it in GitHub Desktop.

Select an option

Save amirrajan/44174e1f903fdec41a565fa94cade2d5 to your computer and use it in GitHub Desktop.
DragonRuby Game Toolkit - custom blend modes -> ring progress bar
BLENDOPERATION_ADD = 0x1
BLENDOPERATION_SUBTRACT = 0x2
BLENDOPERATION_REV_SUBTRACT = 0x3
BLENDOPERATION_MINIMUM = 0x4
BLENDOPERATION_MAXIMUM = 0x5
BLENDFACTOR_ZERO = 0x1
BLENDFACTOR_ONE = 0x2
BLENDFACTOR_SRC_COLOR = 0x3
BLENDFACTOR_ONE_MINUS_SRC_COLOR = 0x4
BLENDFACTOR_SRC_ALPHA = 0x5
BLENDFACTOR_ONE_MINUS_SRC_ALPHA = 0x6
BLENDFACTOR_DST_COLOR = 0x7
BLENDFACTOR_ONE_MINUS_DST_COLOR = 0x8
BLENDFACTOR_DST_ALPHA = 0x9
BLENDFACTOR_ONE_MINUS_DST_ALPHA = 0xA
# color_out = color_src * src_color_factor [color_operation] color_dst * dst_color_factor
# alpha_out = alpha_src * src_alpha_factor [alpha_operation] alpha_dst * dst_alpha_factor
def compose_blendmode(src_color_factor, dst_color_factor, color_operation, src_alpha_factor, dst_alpha_factor, alpha_operation)
(color_operation << 0) |
(src_color_factor << 4) |
(dst_color_factor << 8) |
(alpha_operation << 16) |
(src_alpha_factor << 20) |
(dst_alpha_factor << 24)
end
HOLE_PUNCH_BLENDMODE = compose_blendmode(BLENDFACTOR_ZERO,
BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
BLENDOPERATION_ADD,
BLENDFACTOR_ZERO,
BLENDFACTOR_ONE_MINUS_SRC_ALPHA,
BLENDOPERATION_ADD)
def boot args
args.state = {}
end
def tick args
args.outputs.background_color = [30, 30, 30]
args.outputs[:ring].set w: 512, h: 512, background_color: [0, 0, 0, 0]
args.outputs[:ring].primitives << { x: 256, y: 256, w: 512, h: 512, path: "sprites/solid-circle.png", anchor_x: 0.5, anchor_y: 0.5, r: 0, g: 128, b: 128 }
args.outputs[:ring].primitives << { x: 256,
y: 256,
w: 506,
h: 506,
path: "sprites/solid-circle.png",
anchor_x: 0.5,
anchor_y: 0.5,
blendmode: HOLE_PUNCH_BLENDMODE }
args.state.angle ||= 0
args.state.quadrent_1 ||= {
x: 512,
y: 256,
w: 256,
h: 256,
anchor_x: 1.0,
anchor_y: 0.0,
}
if args.state.angle <= 90
args.state.quadrent_1.w = (256 - 256 * args.state.angle.vector_y).clamp(128, 256)
args.state.quadrent_1.h = (256 * args.state.angle.vector_x)
end
args.state.quadrent_2 = {
x: 256,
y: 0,
w: 256,
h: 256,
r: 80, g: 0, b: 0
}
if args.state.angle > 90 && args.state.angle <= 180
args.state.quadrent_2.w = (256 * (args.state.angle - 90).vector_x)
args.state.quadrent_2.h = (256 - 256 * (args.state.angle - 90).vector_y).clamp(128, 256)
end
args.state.quadrent_3 = {
x: 0,
y: 256,
w: 256,
h: 256,
r: 0, g: 80, b: 0,
anchor_y: 1.0,
}
if args.state.angle > 180 && args.state.angle <= 270
args.state.quadrent_3.w = (256 - 256 * (args.state.angle - 180).vector_y).clamp(128, 256)
args.state.quadrent_3.h = (256 * (args.state.angle - 180).vector_x)
end
args.state.quadrent_4 = {
x: 256,
y: 512,
w: 256,
h: 256,
r: 0, g: 0, b: 80,
anchor_y: 1.0,
anchor_x: 1.0,
}
if args.state.angle > 270 && args.state.angle <= 360
args.state.quadrent_4.w = (256 * (args.state.angle - 270).vector_x)
args.state.quadrent_4.h = (256 - 256 * (args.state.angle - 270).vector_y).clamp(128, 256)
end
args.state.angle += 0.5
if args.state.angle <= 90
args.outputs[:ring].primitives << { **args.state.quadrent_1,
path: :solid,
blendmode: HOLE_PUNCH_BLENDMODE }
end
if args.state.angle <= 180
args.outputs[:ring].primitives << { **args.state.quadrent_2,
path: :solid,
blendmode: HOLE_PUNCH_BLENDMODE }
end
if args.state.angle <= 270
args.outputs[:ring].primitives << { **args.state.quadrent_3,
path: :solid,
blendmode: HOLE_PUNCH_BLENDMODE }
end
if args.state.angle <= 360
args.outputs[:ring].primitives << { **args.state.quadrent_4,
path: :solid,
blendmode: HOLE_PUNCH_BLENDMODE }
end
args.outputs<< { x: 640, y: 360, w: 512, h: 512, path: :ring, anchor_x: 0.5, anchor_y: 0.5 }
end
GTK.reset
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment