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
| # Reference: https://www.stat.auckland.ac.nz/~paul/Reports/GraphicsEngine/compositing/compositing.html | |
| # Porter-Duff "Compositing Digital Images" paper. | |
| # https://keithp.com/~keithp/porterduff/p253-porter.pdf | |
| # https://www.w3.org/TR/compositing-1/#porterduffcompositingoperators | |
| COLORS = { | |
| # blue: { r: 104, g: 199, b: 232, a: 255 }, | |
| # yellow: { r: 255, g: 220, b: 1, a: 255 }, | |
| blue: { r: 0, g: 0, b: 255, a: 255 }, | |
| red: { r: 255, g: 0, b: 0, a: 255 } | |
| } |
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
| class Tree { | |
| constructor (rootNode) { | |
| this.rootNode = rootNode | |
| } | |
| } | |
| // Removed parents simply becuse they make a circular dependency, and we never need to read upwards. | |
| class TreeNode { | |
| constructor ({ | |
| value, |
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
| ARG NODE_VERSION="22" | |
| # base image to use for docker-compose | |
| FROM node:${NODE_VERSION} AS builder | |
| # This needs to happen _inside_ of the FROM to be in "context" | |
| ARG PG_MAJOR_VERSION="16" | |
| # Install system dependencies. | |
| RUN apt update -y && \ |
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
| # > 256 locals. | |
| def tick(args) | |
| # This is the most common. Easiest way around it is to split up locals into separate methods as the 256 limit is per "block" | |
| l_0 = nil; l_1 = nil; l_2 = nil; | |
| end | |
| # > 256 globals. | |
| $var1 = nil | |
| $var2 = nil |
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
| class FileWatcher | |
| # This can get potentially deep if you have a lot of files or directories. Consider a fiber if its taking up too much time. | |
| def self.list_files_recursive(directory, max_iterations_for_fiber: 100, fiber: false) | |
| idx = 0 | |
| files = [] | |
| all_files = [] | |
| # Seed with full paths so we never lose directory context. `.reverse_each` makes `.pop()` yield entries in listing order. This is like the old "list_files_recursive" which actually used recursion, but by using a loop we can yield to a fiber on potentially large directories. | |
| DR.list_files(directory).reverse_each do |f| | |
| files << File.join(directory, f) |
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 |
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
| <div flow-controller="counter"> | |
| <button flow-action="click->counter#decrement">-</button> | |
| <span flow-text="context.count">0</span> | |
| <button flow-action="click->counter#increment">+</button> | |
| </div> | |
| <button flow-action="#decrement">-</button> | |
| <span flow-text="context.count">0</span> | |
| <button flow-action="#increment">+</button> |
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
| # one-time setup | |
| @glow_dirs ||= 16.times.map do |i| | |
| a = i * Math::PI * 2 / 16 | |
| [Math.cos(a), Math.sin(a)] | |
| end | |
| @glow_mask_blend ||= Numeric.compose_blendmode( | |
| BLENDFACTOR_ZERO, BLENDFACTOR_SRC_ALPHA, BLENDOPERATION_ADD, | |
| BLENDFACTOR_ZERO, BLENDFACTOR_SRC_ALPHA, BLENDOPERATION_ADD | |
| ) | |
| @glow_hole_punch ||= Numeric.compose_blendmode( |
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
| def calc_car dt = 1 | |
| target_speed = if state.engine == :high | |
| state.high_speed | |
| else | |
| state.low_speed | |
| end | |
| state.speed *= (0.98 * dt) if steering_at_limit? | |
| if auto_break? |
NewerOlder