Skip to content

Instantly share code, notes, and snippets.

@owenbutler
Created February 6, 2023 10:33
Show Gist options
  • Select an option

  • Save owenbutler/abb41c1fca3a1bd56f670577650c2aff to your computer and use it in GitHub Desktop.

Select an option

Save owenbutler/abb41c1fca3a1bd56f670577650c2aff to your computer and use it in GitHub Desktop.
noninteractive line visualisation using dragonruby
def tick args
front_buffer, back_buffer = prepare_buffers args
tc = args.state.tick_count
w = 1280
h = 720
yoffset = (w - h) / 2
args.outputs[back_buffer].lines << [
{
x: sin_range(100, w), y: cos_range(60, h) + yoffset,
x2: sin_range(120, w), y2: cos_range(40, h) + yoffset,
r: sin_range(100, 256), g: sin_range(70, 256), b: sin_range(40, 256),
},
{
x: sin_range(60, w), y: cos_range(100, h) + yoffset,
x2: sin_range(50, w), y2: cos_range(140, h) + yoffset,
r: sin_range(40, 256), g: sin_range(90, 256), b: sin_range(120, 256),
},
]
# zoom = sin_range(200, 20)
zoom = 2
zw = w - zoom * 2
zh = w - zoom * 2
args.outputs[front_buffer].sprites << {
x: 0, y: 0, w: w, h: w, source_x: zoom, source_y: zoom, source_w: zw, source_h: zh, path: back_buffer, angle: Math::cos(tc / 500), a: 155,
}
args.outputs.sprites << { x: 0, y: 0, w: w, h: h, source_x: 0, source_y: yoffset, source_w: w, source_h: h, path: front_buffer }
end
def sin_range tc_scale, range
half = range / 2
Math::sin(Kernel::tick_count / tc_scale) * half + half
end
def cos_range tc_scale, range
half = range / 2
Math::cos(Kernel::tick_count / tc_scale) * half + half
end
def prepare_buffers args
args.outputs[:s1].clear_before_render = false
args.outputs[:s1].width = 1280
args.outputs[:s1].height = 1280
args.outputs[:s2].clear_before_render = false
args.outputs[:s2].width = 1280
args.outputs[:s2].height = 1280
if args.tick_count.even?
return :s1, :s2
else
return :s2, :s1
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment