Skip to content

Added lines method, draws lines between points given

Jeremy Soller requested to merge ca1ek:master into master

Created by: ca1ek

I added a method to add lines between given points.

It accepts a reference to an array of [i32; 2]. It draws line following each point one by one.

[[10, 10], [20, 20]] draws one line from 10, 10 to 20, 20
[[10, 10], [20, 20], [30, 10]] draws two lines, from 10, 10 to 20, 20, and from 20, 20 to 30, 10
etc.

Test code

extern crate orbclient;

use orbclient::window::Window;
use orbclient::color::Color;

fn main() {
    let mut window = Window::new(20, 20, 640, 480, &"Hello!").unwrap();
    let mut counter = 0.0; 
    loop {
        window.set(Color::rgb(0,0,0));
        window.lines(&[[0, 10 + counter as i32],
                       [50, 200 + (counter*0.5) as i32],
                       [200, 200 - counter as i32],
                       [300, 100 + counter as i32]], Color::rgb(255, 0, 0));
        window.sync();
        counter += 0.05;
    }
}

Merge request reports