I am still very new to Snap!. I would like to graph the values of the micro:bit that I showed you in another topic. But I want that to do in a live graph that keeps scrolling, like in the Gif below.
Does anyone have a bit of example code I could use to make this work?
That was one of the problems with mine. It couldn't do more than one graph since the forever loops were included and would continuously clear the screen and redraw the line.
my example uses a fixed size buffer, so it doesn't accumulate all the data it gets all the time. That's the "complicated" part of the code, I think. If you just wish to always plot a moving window of the last n values you can use this little custom block:
(just remember to initialize the "a list of numbers" variable to be a list).
Here's a little trick you can use to keep the "a list of numbers" from growing, because eventually it might overflow the memory of the receiving client (that's the "complicated" buffer part of my example). Just always set the list to its last n items, and then add the latest one. That way it'll always stay the same size:
command draws a single line of values evenly distributed horizontally across the entire stage. If you want to draw several lines in different colors, you can keep a list of sublists and do something like this:
(I've updated the project with these examples, so you can play with them and reuse it)