Skip to content

Instantly share code, notes, and snippets.

@amirrajan
Last active April 6, 2025 07:14
Show Gist options
  • Save amirrajan/c5c75254ff72bf48e907750193a42a28 to your computer and use it in GitHub Desktop.
Save amirrajan/c5c75254ff72bf48e907750193a42a28 to your computer and use it in GitHub Desktop.
DragonRuby Game Toolkit - Beakers with liquids
def beaker_prefab outputs, id:, x:, y:, tip_angle:;
base_angle = 90
outputs[id].w = 296
outputs[id].h = 80
outputs[id].background_color = [0, 0, 0]
diff_angle = base_angle + tip_angle
outputs[id].primitives << { x: 8, y: 8, w: 296 - 16, h: 80 - 16, path: :solid, r: 60, g: 60, b: 60 }
outputs[id].primitives << { x: 296 - 32, y: 0, w: 32, h: 80, path: :solid, r: 180, g: 180, b: 180 }
liquid_angle = tip_angle.clamp(-90, 0)
liquid_angle = liquid_angle - 10 * tip_angle.vector_y
outputs[id].primitives << { x: 80 * 3, y: 40, w: 10, h: 80, anchor_y: 0.5, path: :solid, r: 180, g: 0, b: 0, angle: -liquid_angle }
outputs[id].primitives << { x: 80 * 2, y: 40, w: 10, h: 80, anchor_y: 0.5, path: :solid, r: 0, g: 180, b: 0, angle: -liquid_angle }
outputs[id].primitives << { x: 80 * 1, y: 40, w: 10, h: 80, anchor_y: 0.5, path: :solid, r: 0, g: 0, b: 180, angle: -liquid_angle }
outputs[id].primitives << { x: 80 * 0, y: 40, w: 10, h: 80, anchor_y: 0.5, path: :solid, r: 180, g: 0, b: 0, angle: -liquid_angle }
label_style = { x: 0, y: 0, r: 255, g: 255, b: 255, size_px: 20, anchor_x: 0 }
outputs[id].labels << { text: "base: #{base_angle}", anchor_y: -3.0, **label_style }
outputs[id].labels << { text: "tip: #{tip_angle}", anchor_y: -2.0, **label_style }
outputs[id].labels << { text: "diff: #{diff_angle}", anchor_y: -1.0, **label_style }
outputs[id].labels << { text: "liquid(x,y): #{liquid_angle.vector_x.to_sf}, #{liquid_angle.vector_y.to_sf}", anchor_y: -0.0, **label_style }
{ x: x, y: y, h: 80, w: 296, path: id, anchor_x: 0.5, anchor_y: 0.5, angle: base_angle + tip_angle }
end
def tick args
args.outputs.primitives << beaker_prefab(args.outputs, id: :container_1, x: 190, y: 480, tip_angle: 0)
args.outputs.primitives << beaker_prefab(args.outputs, id: :container_2, x: 500, y: 480, tip_angle: -15)
args.outputs.primitives << beaker_prefab(args.outputs, id: :container_3, x: 810, y: 480, tip_angle: -30)
args.outputs.primitives << beaker_prefab(args.outputs, id: :container_4, x: 1090, y: 480, tip_angle: -45)
args.outputs.primitives << beaker_prefab(args.outputs, id: :container_5, x: 190, y: 180, tip_angle: -60)
args.outputs.primitives << beaker_prefab(args.outputs, id: :container_6, x: 500, y: 180, tip_angle: -75)
args.outputs.primitives << beaker_prefab(args.outputs, id: :container_7, x: 810, y: 180, tip_angle: -90)
args.outputs.primitives << beaker_prefab(args.outputs, id: :container_8, x: 1120, y: 180, tip_angle: -105)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment