blob: 2baefa9e0546777d67db688ac93f573d3f3a711b [file] [log] [blame]
James Kuszmaul6271cf72019-09-18 20:10:08 -07001#include <emscripten/emscripten.h>
2#include <emscripten/html5.h>
3
4#include <iostream>
5
6#include "frc971/analysis/plotting/webgl2_plotter.h"
7#include "frc971/analysis/plotting/webgl2_animator.h"
8
9float rand1() {
10 return static_cast<float>(rand()) / RAND_MAX;
11}
12
13int main() {
14 // Note that the animation_state must last until Redraw stops being called,
15 // which we cannot provide any bound on. As such, we don't currently destroy
16 // the memory until the webpage is closed.
17 frc971::plotting::Animator *animation_state =
18 new frc971::plotting::Animator("#canvas");
19 // Generate a bunch of lines with random y-values and evenly spaced x-values,
20 // such that each line takes up a set amount of space in the y-space. If
21 // that's unclear, then try running this and seeing what it looks like.
22 constexpr size_t kNLines = 30;
23 for (int jj = 0; jj < kNLines; ++jj) {
24 frc971::plotting::Line *line = animation_state->plotter()->AddLine();
25 // Randomly generate a color to use; each of r/g/b are between 0 and 1.
26 line->SetColor({.r = rand1(), .g = rand1(), .b = rand1()});
27 std::vector<Eigen::Vector2d> points;
28 constexpr size_t kNPoints = 100000;
29 for (int ii = 0; ii < kNPoints; ++ii) {
30 const float x = static_cast<float>(ii) / kNPoints;
31 points.emplace_back(x, std::sin(x + jj));
32 }
33 line->SetPoints(points);
34 }
35}