The box in the sample screenshot was generated using:
args.outputs.primitives << striped_box(100, 100, 400, 200, 10, {}, {r: 255})| def striped_box(x, y, w, h, spacing=10, border_extra={}, line_extra={}) | |
| primitives = [] | |
| border_box = { | |
| x: x, | |
| y: y, | |
| w: w, | |
| h: h, | |
| } | |
| primitives << border_box.merge(primitive_marker: :border).merge(border_extra) | |
| top_corner_x = x | |
| top_corner_y = y + h # DR inverted Y | |
| # TODO the spacing/2 is a cheat to make sure we cover the entire box, | |
| # but also is why we need the 'next if's inside the loop below. | |
| # can they be removed? | |
| 1.upto(border_box[:w]/(spacing/2)).each do |line_index| | |
| y1 = top_corner_y | |
| x1 = top_corner_x + (line_index * spacing) | |
| if x1 > border_box[:x] + border_box[:w] | |
| x1 = border_box[:x] + border_box[:w] | |
| y1 = top_corner_y - (spacing * (line_index - (border_box[:w]/spacing))) | |
| end | |
| x2 = top_corner_x | |
| y2 = top_corner_y - line_index * spacing | |
| if y2 < y | |
| y2 = y | |
| x2 = top_corner_x + (spacing * (line_index - (border_box[:h]/spacing))) | |
| end | |
| next if x2 > border_box[:x] + border_box[:w] | |
| # there's a single offset corner that crops up, we need to ban it | |
| next if y1 < border_box[:y] + 1 | |
| primitives << { | |
| primitive_marker: :line, | |
| x: x1 - 1, | |
| y: y1, | |
| x2: x2, | |
| y2: y2 + 1, | |
| }.merge(line_extra) | |
| end | |
| primitives | |
| end |
The box in the sample screenshot was generated using:
args.outputs.primitives << striped_box(100, 100, 400, 200, 10, {}, {r: 255})
here's an example using render targets:
CleanShot.2023-10-12.at.19.19.49-converted.mp4