Skip to content

Instantly share code, notes, and snippets.

@nielpattin
Last active May 26, 2023 04:20
Show Gist options
  • Save nielpattin/b0b19b0eaa5c4014959d5209effdbc8a to your computer and use it in GitHub Desktop.
Save nielpattin/b0b19b0eaa5c4014959d5209effdbc8a to your computer and use it in GitHub Desktop.
A gdscript that use _draw() with @tool and timer and history variable to draw a line from left to right that remember last line instead of remove and draw a new line every _draw() call
@tool
extends Control
var history := [
Vector2(10, 10),
Vector2(10, 500),
Vector2(20, 10),
Vector2(20, 500),
]
var count = 0
func _draw():
if history.size() >= 500:
history.resize(4)
count = 0
var points = PackedVector2Array()
for value in history:
points.push_back(value)
if points.size() > 1:
draw_multiline(points, Color(1, 0, 0), 3)
await Engine.get_main_loop().create_timer(0.001).timeout
history.append_array([history[count] + Vector2(10, 0), history[count+1] + Vector2(10, 0)])
count +=2
#I think this like recursive(it's call _draw())
queue_redraw()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment