<commit_before>extern crate piston;
extern crate graphics;
extern crate glutin_window;
extern crate opengl_graphics;
extern crate box2d;

use piston::window::WindowSettings;
use piston::event_loop::*;
use piston::input::*;
use glutin_window::GlutinWindow as Window;
use opengl_graphics::{GlGraphics, OpenGL};
use box2d::b2;

pub struct App {
    gl: GlGraphics, // OpenGL drawing backend.
    world: b2::World,
}

impl App {
    fn render(&mut self, args: &RenderArgs) {
        use graphics::*;

        const GREEN: [f32; 4] = [0.0, 1.0, 0.0, 1.0];
        const RED: [f32; 4] = [1.0, 0.0, 0.0, 1.0];

        let ref world = self.world;
        self.gl.draw(args.viewport(), |c, gl| {
            clear(GREEN, gl);

            for (_, b) in world.bodies() {
                let ref body = (*b.borrow());
                let body_type = body.body_type();
                let fixtures = body.fixtures();
                // let position = body.position;
            }
        });
        //         let square = rectangle::square(0.0, 0.0, 50.0);
        // let rotation = self.rotation;
        // let (x, y) = ((args.width / 2) as f64, (args.height / 2) as f64);

        // let transform = c.transform
        // .trans(x, y)
        // .rot_rad(rotation)
        // .trans(-25.0, -25.0);
        //
        // Draw a box rotating around the middle of the screen.
        // rectangle(RED, square, transform, gl);
        // });
        //
    }

    fn update(&mut self, args: &UpdateArgs) {
        // Rotate 2 radians per second.
        self.world.step(args.dt as f32, 8, 3);
    }
}

fn new_world() -> b2::World {
    let mut world = b2::World::new(&b2::Vec2 { x: 0.0, y: 2.0 });

    let mut b_def = b2::BodyDef::new();
    b_def.body_type = b2::BodyType::Static;
    b_def.position = b2::Vec2 { x: 0., y: -10. };

    let mut ground_box = b2::PolygonShape::new();
    ground_box.set_as_box(20., 1.);

    let ground_handle = world.create_body(&b_def);
    world.get_body_mut(ground_handle)
         .create_fast_fixture(&ground_box, 0.);

    let mut b_def = b2::BodyDef::new();
    b_def.body_type = b2::BodyType::Dynamic;
    b_def.position = b2::Vec2 { x: -20., y: 20. };<commit_msg>Drawing simple bodies with gl<commit_after>extern crate piston;
extern crate graphics;
extern crate glutin_window;
extern crate opengl_graphics;
extern crate box2d;

use piston::window::WindowSettings;
use piston::event_loop::*;
use piston::input::*;
use glutin_window::GlutinWindow as Window;
use opengl_graphics::{GlGraphics, OpenGL};
use box2d::b2;

pub struct App {
    gl: GlGraphics,
    world: b2::World,
}

impl App {
    fn render(&mut self, args: &RenderArgs) {
        use graphics::*;

        const GREEN: [f32; 4] = [0.0, 1.0, 0.0, 1.0];
        const RED: [f32; 4] = [1.0, 0.0, 0.0, 1.0];
        const BLACK: [f32; 4] = [0.0, 0.0, 0.0, 1.0];

        let ref world = self.world;
        self.gl.draw(args.viewport(), |c, gl| {
            clear(GREEN, gl);

            for (_, b) in world.bodies() {
                let body = b.borrow();
                let position = (*body).position();
                let angle = (*body).angle();

                let transform = c.transform
                                 .trans((args.width as f64 * 0.5), (args.height as f64 * 0.5))
                                 .scale(2.0, 2.0)
                                 .trans(position.x as f64, position.y as f64)
                                 .rot_deg(angle as f64);

                let square = rectangle::square(0.0, 0.0, 50.0);

                for (_, f) in body.fixtures() {
                    let fixture = f.borrow();
                    let shape = (*fixture).shape();

                    match *shape {
                        b2::UnknownShape::Circle(ref s) => {
                            let p = s.position();
                            let r = s.radius() as f64;
                            let extent = rectangle::square(p.x as f64 - r / 2.0,
                                                           p.y as f64 - r / 2.0,
                                                           r);
                            Ellipse::new(RED).draw(extent, default_draw_state(), transform, gl);
                        }
                        b2::UnknownShape::Polygon(ref s) => {
                            rectangle(BLACK, square, transform, gl);
                        }
                        _ => (),
                    }

                }
            }
        });
        //         let square = rectangle::square(0.0, 0.0, 50.0);
        // let rotation = self.rotation;
        // let (x, y) = ((args.width / 2) as f64, (args.height / 2) as f64);

        // let transform = c.transform
        // .trans(x, y)
        // .rot_rad(rotation)
        // .trans(-25.0, -25.0);
        //
        // Draw a box rotating around the middle of the screen.
        //
        // });
        //
    }

    fn update(&mut self, args: &UpdateArgs) {
        // Rotate 2 radians per second.
        self.world.step(args.dt as f32, 8, 3);
    }
}

fn new_world() -> b2::World {
    let mut world = b2::World::new(&b2::Vec2 { x: 0.0, y: 2.0 });

    let mut b_def = b2::BodyDef::new();
    b_def.body_type = b2::BodyType::Static;
    b_def.position = b2::Vec2 { x: 0., y: -10. };

    let mut ground_box = b2::PolygonShape::new();
    ground_box.set_as_box(20., 1.);

    let ground_handle = world.create_body(&b_def);
    world.get_body_mut(ground_handle)
         .create_fast_fixture(&ground_box, 0.);

    let mut b_def = b2::BodyDef::new();
    b_def.body_type = b2::BodyType::Dynamic;
    b_def.position = b2::Vec2 { x: -20., y: 20. };
{'fraction_non_alphanumeric': 0.1511134676564157, 'fraction_numerical': 0.036055143160127257, 'mean_word_length': 1.6006433823529411, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3541789', 'n_tokens_mistral': 1989, 'n_tokens_neox': 1827, 'n_words': 461}