Last active
July 6, 2026 21:20
-
-
Save KonnorRogers/c56f4fadcbb406b49bf22a5bb8c6767a to your computer and use it in GitHub Desktop.
rotating mask
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| module Main | |
| def tick args | |
| # ./samples/07_advanced_rendering/12_blend_modes_additive_modulo/app/main.rb | |
| # Sample app shows how to use blend modes to create a masking layer | |
| # Special thanks to akzidenz@discord (https://akzidenz.itch.io/) for providing this sample app | |
| # | |
| # blendmode reference: | |
| # 1: alpha blending (default) | |
| # 2: additive blending | |
| # 4: modulo blending | |
| # 8: multiply blending | |
| # create a render target to represent the masking layer | |
| args.outputs[:mask].w = 1280 | |
| args.outputs[:mask].h = 720 | |
| speed = 2 # degrees per tick | |
| angle = Kernel.tick_count * speed | |
| args.outputs[:mask].sprites << { | |
| x: 0, y: 0, w: 1280, h: 720, | |
| path: :solid, | |
| r: 0, g: 0, b: 0 # <-- important (black color) | |
| } | |
| args.outputs[:mask].sprites << { | |
| x: Grid.w / 2, | |
| y: Grid.h / 2, | |
| w: 240, h: 240, | |
| anchor_x: 0.5, | |
| anchor_y: 0.5, | |
| path: :solid, # use a proper mask if you want to rotate anything other than a square. | |
| r: 255, | |
| g: 255, | |
| b: 255, | |
| a: 255, | |
| angle: angle, | |
| blendmode: 2, # <-- important (2 means additive blending) | |
| } | |
| # render background to reveal | |
| args.outputs.sprites << { x: 0, | |
| y: 0, | |
| w: 1280, | |
| h: 720, | |
| path: 'sprites/bg.png' } | |
| # render masking layer over the bg to reveal | |
| args.outputs.sprites << { | |
| x: 0, y: 0, w: 1280, h: 720, | |
| path: :mask, | |
| blendmode: 4 # <-- important (4 means modulo blending) | |
| } | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment