File: animation_example.rs

package info (click to toggle)
rust-gnuplot 0.0.39-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 532 kB
  • sloc: makefile: 2
file content (29 lines) | stat: -rw-r--r-- 567 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// This file is released into Public Domain.
use gnuplot::*;
use std::thread::sleep;
use std::time::Duration;

fn main()
{
	println!("This is a silly example of doing an animation... Ctrl-C to quit.");
	let mut fg = Figure::new();
	let mut x = vec![];
	for i in 0..100i32
	{
		x.push(i as f32 * 0.1 - 5.0);
	}

	let mut t = 0.0;
	loop
	{
		fg.clear_axes();
		fg.axes2d().set_y_range(Fix(-1.0), Fix(1.0)).lines(
			x.iter(),
			x.iter().map(|&x| (x + t).sin()),
			&[],
		);
		t += 0.1;
		fg.show_and_keep_running().unwrap();
		sleep(Duration::from_millis(500));
	}
}