Skip to content

Instantly share code, notes, and snippets.

@vaiorabbit
Created August 23, 2026 13:39
Show Gist options
  • Select an option

  • Save vaiorabbit/825d5c6be60c5f4df0c9936a8e3437f8 to your computer and use it in GitHub Desktop.

Select an option

Save vaiorabbit/825d5c6be60c5f4df0c9936a8e3437f8 to your computer and use it in GitHub Desktop.
$num = 3000
$range = 12
$ax = Array.new($num, 1280.0/2)
$ay = Array.new($num, 800.0/2)
def app_setup()
App.background(App.gray(51))
end
def app_update(vg, t)
# Shift all elements 1 place to the left
$ax.rotate!
$ay.rotate!
$ax[$num-1] = $ax[$num-2]
$ay[$num-1] = $ay[$num-2]
# Put a new value at the end of the array
$ax[$num-1] += Random.rand(-$range..$range)
$ay[$num-1] += Random.rand(-$range..$range)
# Constrain all points to the screen
$ax[$num-1] = $ax[$num-1].clamp(0, 1280)
$ay[$num-1] = $ay[$num-1].clamp(0, 800)
# Draw a line connecting the points
NanoVG.nvgStrokeWidth(vg, 2.0)
(1...$num).each do |i|
gray = (i.to_f / $num * 204.0 + 51).to_i
NanoVG.nvgBeginPath(vg)
NanoVG.nvgMoveTo(vg, $ax[i - 1], $ay[i - 1])
NanoVG.nvgLineTo(vg, $ax[i], $ay[i])
NanoVG.nvgStrokeColor(vg, NanoVG.nvgRGBA(gray, gray, gray, gray))
NanoVG.nvgStroke(vg)
end
end
def app_cleanup()
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment