extern crate gunpowder_treason as gt;
extern crate rand;

use rand::random;

fn main() {
    // let cent = 0.393701;
    let mut drawing = gt::svg(9.0, 12.0);

    let xs: Vec<Vec<f64>> = (1..9).map(|_: u32| {
        (0..(random::<u32>() % 8) + 4).map(|_: u32| {
            (random::<f64>() * 0.3 + 0.3) * 0.2
        }).collect()
    }).collect();

    for (x, rs) in xs.iter().enumerate() {
        let max = rs.len();
        let tot = (max - 1) as f64;
        let dy = 10.0 / tot;
        let mut ry = 1.0;
        let r2 = rs.clone();
        for (y, c) in rs.iter().enumerate() {
            let rx = 1.0 + x as f64;
            eprintln!("{}, {}, {}, {}", x, y, c, ry);
            drawing.add(gt::circle(
                (rx, 1.0 + dy * y as f64),
                *c,
            ));
            if y != max - 1 {
                let cn = r2[y + 1];
                drawing.add(gt::line(rx, ry + c).to(rx, ry + dy - cn));
            }
            ry += dy;
        }
    }

    if let Err(e) = drawing.output("planets") {
        eprintln!("{}", e);
    };
}
