Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cargo fmt; cargo clippy #350

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 31 additions & 15 deletions examples/async_test.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
extern crate piston;
extern crate graphics;
extern crate opengl_graphics;
extern crate piston;
extern crate sdl2_window;

use opengl_graphics::*;
use piston::event_loop::*;
use piston::input::*;
use piston::window::WindowSettings;
use piston::window::Window;
use piston::window::WindowSettings;
use piston::Size;
use opengl_graphics::*;
use sdl2_window::Sdl2Window;

use futures::stream::FuturesUnordered;
Expand All @@ -30,7 +30,12 @@ async fn main() {
let n = 100_000;
let size = window.size();
let mut ps: Vec<[f64; 2]> = (0..n)
.map(|_| [rand::random::<f64>() * size.width, rand::random::<f64>() * size.height])
.map(|_| {
[
rand::random::<f64>() * size.width,
rand::random::<f64>() * size.height,
]
})
.collect();
let mut task: FuturesUnordered<_> = FuturesUnordered::new();
let mut cursor = [0.0, 0.0];
Expand All @@ -46,16 +51,23 @@ async fn main() {
gl.draw(args.viewport(), |c, g| {
clear([1.0; 4], g);
for pos in &ps {
Rectangle::new([1.0, 0.0, 0.0, 0.05])
.draw([pos[0], pos[1], 2.0, 2.0], &c.draw_state, c.transform, g);
Rectangle::new([1.0, 0.0, 0.0, 0.05]).draw(
[pos[0], pos[1], 2.0, 2.0],
&c.draw_state,
c.transform,
g,
);
}
});
}

if let Some(args) = e.update_args() {
time += args.dt;
let size = window.size();
task.extend(ps.into_iter().map(|pos| update(time, args.dt, cursor, pos, size)));
task.extend(
ps.into_iter()
.map(|pos| update(time, args.dt, cursor, pos, size)),
);
ps = vec![];
}

Expand All @@ -71,16 +83,20 @@ async fn update(time: f64, dt: f64, cursor: [f64; 2], pos: [f64; 2], size: Size)

let dir = [pos[0] - cursor[0], pos[1] - cursor[1]];
let dir_len = (dir[0] * dir[0] + dir[1] * dir[1]).sqrt();
let dir_len = if dir_len <= 0.001 {1.0} else {dir_len};
let trigger = if (0.1 * (dir_len + time)).sin() < 0.1 {0.1} else {-0.1};
let dir_len = if dir_len <= 0.001 { 1.0 } else { dir_len };
let trigger = if (0.1 * (dir_len + time)).sin() < 0.1 {
0.1
} else {
-0.1
};
let speed = 10.0;

pos[0] += speed * dt * (
2.0 * rand::random::<f64>() - 1.0 + trigger * rand::random::<f64>() * dir[0] / dir_len
);
pos[1] += speed * dt * (
2.0 * rand::random::<f64>() - 1.0 + trigger * rand::random::<f64>() * dir[1] / dir_len
);
pos[0] += speed
* dt
* (2.0 * rand::random::<f64>() - 1.0 + trigger * rand::random::<f64>() * dir[0] / dir_len);
pos[1] += speed
* dt
* (2.0 * rand::random::<f64>() - 1.0 + trigger * rand::random::<f64>() * dir[1] / dir_len);
if pos[0] <= 0.0 || pos[0] >= size.width {
pos[0] = old_pos[0];
}
Expand Down
45 changes: 27 additions & 18 deletions examples/colored_image_test.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
extern crate piston;
extern crate graphics;
extern crate opengl_graphics;
extern crate piston;
extern crate sdl2_window;

use std::path::Path;
use opengl_graphics::*;
use piston::event_loop::*;
use piston::input::*;
use piston::window::WindowSettings;
use opengl_graphics::*;
use sdl2_window::Sdl2Window;
use std::path::Path;

fn main() {
let opengl = OpenGL::V3_2;
let mut window: Sdl2Window = WindowSettings::new("opengl_graphics: colored_image_test", [300, 300])
.exit_on_esc(true)
.graphics_api(opengl)
.build()
.unwrap();
let mut window: Sdl2Window =
WindowSettings::new("opengl_graphics: colored_image_test", [300, 300])
.exit_on_esc(true)
.graphics_api(opengl)
.build()
.unwrap();

let rust_logo = Texture::from_path(&Path::new("./assets/rust-white.png"),
&TextureSettings::new()).unwrap();
let rust_logo = Texture::from_path(
Path::new("./assets/rust-white.png"),
&TextureSettings::new(),
)
.unwrap();
let mut gl = GlGraphics::new(opengl);
let mut events = Events::new(EventSettings::new());
while let Some(e) = events.next(&mut window) {
Expand All @@ -34,17 +38,24 @@ fn main() {
let tr = |p: [f64; 2]| [tx(transform, p[0], p[1]), ty(transform, p[0], p[1])];

clear([1.0; 4], g);
Rectangle::new([1.0, 0.0, 0.0, 1.0])
.draw([0.0, 0.0, 100.0, 100.0], &c.draw_state, c.transform, g);
Rectangle::new([0.0, 1.0, 0.0, 0.3])
.draw([50.0, 50.0, 100.0, 100.0], &c.draw_state, c.transform, g);
Rectangle::new([1.0, 0.0, 0.0, 1.0]).draw(
[0.0, 0.0, 100.0, 100.0],
&c.draw_state,
c.transform,
g,
);
Rectangle::new([0.0, 1.0, 0.0, 0.3]).draw(
[50.0, 50.0, 100.0, 100.0],
&c.draw_state,
c.transform,
g,
);
g.tri_list_uv_c(&c.draw_state, &rust_logo, |f| {
(f)(
&[
tr([0.0, 0.0]),
tr([300.0, 0.0]),
tr([0.0, 300.0]),

tr([300.0, 0.0]),
tr([0.0, 300.0]),
tr([300.0, 300.0]),
Expand All @@ -53,7 +64,6 @@ fn main() {
[0.0, 0.0],
[1.0, 0.0],
[0.0, 1.0],

[1.0, 0.0],
[0.0, 1.0],
[1.0, 1.0],
Expand All @@ -62,11 +72,10 @@ fn main() {
[1.0, 0.0, 0.0, 1.0],
[0.0, 1.0, 0.0, 1.0],
[0.0, 0.0, 1.0, 1.0],

[0.0, 00.0, 0.0, 1.0],
[0.0, 00.0, 0.0, 1.0],
[0.0, 00.0, 0.0, 1.0],
]
],
)
});
});
Expand Down
60 changes: 40 additions & 20 deletions examples/draw_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ extern crate opengl_graphics;
extern crate piston;
extern crate sdl2_window;

use std::path::Path;
use graphics::draw_state::Blend;
use opengl_graphics::{GlGraphics, Texture, TextureSettings};
use piston::event_loop::*;
use piston::input::*;
use piston::window::WindowSettings;
use sdl2_window::{Sdl2Window, OpenGL};
use graphics::draw_state::Blend;
use sdl2_window::{OpenGL, Sdl2Window};
use std::path::Path;

fn main() {
println!("Press A to change blending");
Expand All @@ -24,10 +24,16 @@ fn main() {
.unwrap();

let mut clip_inside = true;
let blends = [Blend::Alpha, Blend::Add, Blend::Invert, Blend::Multiply, Blend::Lighter];
let blends = [
Blend::Alpha,
Blend::Add,
Blend::Invert,
Blend::Multiply,
Blend::Lighter,
];
let mut blend = 0;
let rust_logo = Texture::from_path(&Path::new("./assets/rust.png"),
&TextureSettings::new()).unwrap();
let rust_logo =
Texture::from_path(Path::new("./assets/rust.png"), &TextureSettings::new()).unwrap();
let mut gl = GlGraphics::new(opengl);
let mut events = Events::new(EventSettings::new().lazy(true));
while let Some(e) = events.next(&mut window) {
Expand All @@ -36,29 +42,43 @@ fn main() {

gl.draw(args.viewport(), |c, g| {
clear([0.8, 0.8, 0.8, 1.0], g);
Rectangle::new([1.0, 0.0, 0.0, 1.0])
.draw([0.0, 0.0, 100.0, 100.0], &c.draw_state, c.transform, g);
Rectangle::new([1.0, 0.0, 0.0, 1.0]).draw(
[0.0, 0.0, 100.0, 100.0],
&c.draw_state,
c.transform,
g,
);

let draw_state = c.draw_state.blend(blends[blend]);
Rectangle::new([0.5, 1.0, 0.0, 0.3])
.draw([50.0, 50.0, 100.0, 100.0], &draw_state, c.transform, g);
Rectangle::new([0.5, 1.0, 0.0, 0.3]).draw(
[50.0, 50.0, 100.0, 100.0],
&draw_state,
c.transform,
g,
);

let transform = c.transform.trans(100.0, 100.0);
// Clip rectangle from upper left corner.
let clipped = c.draw_state.scissor([100, 100, 100, 100]);
Image::new().draw(&rust_logo, &clipped, transform, g);

let transform = c.transform.trans(200.0, 200.0);
Ellipse::new([1.0, 0.0, 0.0, 1.0])
.draw([0.0, 0.0, 50.0, 50.0], &DrawState::new_clip(), transform, g);
Image::new().draw(&rust_logo,
&if clip_inside {
DrawState::new_inside()
} else {
DrawState::new_outside()
},
transform,
g);
Ellipse::new([1.0, 0.0, 0.0, 1.0]).draw(
[0.0, 0.0, 50.0, 50.0],
&DrawState::new_clip(),
transform,
g,
);
Image::new().draw(
&rust_logo,
&if clip_inside {
DrawState::new_inside()
} else {
DrawState::new_outside()
},
transform,
g,
);
});
}

Expand Down
2 changes: 0 additions & 2 deletions examples/glow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ fn main() {}
/// ```
#[cfg(feature = "glow")]
fn main() {


#[cfg(not(target_arch = "wasm32"))]
let (gl, window, event_loop) = {
unsafe {
Expand Down
12 changes: 7 additions & 5 deletions examples/hello_world.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
extern crate piston;
extern crate graphics;
extern crate opengl_graphics;
extern crate piston;
extern crate sdl2_window;

use opengl_graphics::GlyphCache;
use opengl_graphics::*;
use piston::event_loop::*;
use piston::input::*;
use piston::window::WindowSettings;
use opengl_graphics::*;
use opengl_graphics::GlyphCache;
use sdl2_window::Sdl2Window;

fn main() {
Expand All @@ -18,7 +18,8 @@ fn main() {
.build()
.unwrap();

let mut glyphs = GlyphCache::new("assets/FiraSans-Regular.ttf", (), TextureSettings::new()).unwrap();
let mut glyphs =
GlyphCache::new("assets/FiraSans-Regular.ttf", (), TextureSettings::new()).unwrap();
let mut gl = GlGraphics::new(opengl);
let mut events = Events::new(EventSettings::new());
while let Some(e) = events.next(&mut window) {
Expand All @@ -30,7 +31,8 @@ fn main() {

clear([0.0, 0.0, 0.0, 1.0], g);
text::Text::new_color([0.0, 1.0, 0.0, 1.0], 32)
.draw("Hello world!", &mut glyphs, &c.draw_state, transform, g).unwrap();
.draw("Hello world!", &mut glyphs, &c.draw_state, transform, g)
.unwrap();
});
}
}
Expand Down
26 changes: 17 additions & 9 deletions examples/image_test.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
extern crate piston;
extern crate graphics;
extern crate opengl_graphics;
extern crate piston;
extern crate sdl2_window;

use std::path::Path;
use opengl_graphics::*;
use piston::event_loop::*;
use piston::input::*;
use piston::window::WindowSettings;
use opengl_graphics::*;
use sdl2_window::Sdl2Window;
use std::path::Path;

fn main() {
let opengl = OpenGL::V3_2;
Expand All @@ -18,8 +18,8 @@ fn main() {
.build()
.unwrap();

let rust_logo = Texture::from_path(&Path::new("./assets/rust.png"),
&TextureSettings::new()).unwrap();
let rust_logo =
Texture::from_path(Path::new("./assets/rust.png"), &TextureSettings::new()).unwrap();
let mut gl = GlGraphics::new(opengl);
let mut events = Events::new(EventSettings::new());
while let Some(e) = events.next(&mut window) {
Expand All @@ -30,10 +30,18 @@ fn main() {
let transform = c.transform.trans(100.0, 100.0);

clear([1.0; 4], g);
Rectangle::new([1.0, 0.0, 0.0, 1.0])
.draw([0.0, 0.0, 100.0, 100.0], &c.draw_state, c.transform, g);
Rectangle::new([0.0, 1.0, 0.0, 0.3])
.draw([50.0, 50.0, 100.0, 100.0], &c.draw_state, c.transform, g);
Rectangle::new([1.0, 0.0, 0.0, 1.0]).draw(
[0.0, 0.0, 100.0, 100.0],
&c.draw_state,
c.transform,
g,
);
Rectangle::new([0.0, 1.0, 0.0, 0.3]).draw(
[50.0, 50.0, 100.0, 100.0],
&c.draw_state,
c.transform,
g,
);
image(&rust_logo, transform, g);
});
}
Expand Down
Loading