Struct gemini_engine::elements::geometry::Rect
source · pub struct Rect {
pub pos: Vec2D,
pub size: Vec2D,
pub fill_char: ColChar,
/* private fields */
}
Expand description
The Rect
takes a position and size, and returns a rectangle at that position with the given width and size when blit to a [View
]
Fields§
§pos: Vec2D
§size: Vec2D
§fill_char: ColChar
Implementations§
source§impl Rect
impl Rect
sourcepub fn new(pos: Vec2D, size: Vec2D, fill_char: ColChar) -> Self
pub fn new(pos: Vec2D, size: Vec2D, fill_char: ColChar) -> Self
Examples found in repository?
examples/multi-movement.rs (line 21)
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
fn main() {
let mut view = View::new(50, 12, ColChar::BACKGROUND);
let mut blocks = vec![
Rect::new(Vec2D::new(0, 0), BLOCK_SIZE, FILL_CHAR),
Rect::new(Vec2D::new(0, 2), BLOCK_SIZE, FILL_CHAR),
Rect::new(Vec2D::new(0, 4), BLOCK_SIZE, FILL_CHAR),
Rect::new(Vec2D::new(0, 6), BLOCK_SIZE, FILL_CHAR),
Rect::new(Vec2D::new(0, 8), BLOCK_SIZE, FILL_CHAR),
Rect::new(Vec2D::new(0, 10), BLOCK_SIZE, FILL_CHAR),
];
let mut i = 0;
fps_gameloop!(
{
i += 1;
for j in 0..blocks.len() {
if i % 2_u32.pow(j as u32) == 0 {
blocks[j].pos.x += 1;
}
}
},
{
view.clear();
for block in &blocks {
view.blit(block, Wrapping::Wrap);
}
view.display_render().unwrap();
if blocks.iter().all(|b| b.pos.x % view.width as isize == 0) {
thread::sleep(Duration::from_secs(2));
};
},
200.0
);
}
Trait Implementations§
source§impl ViewElement for Rect
impl ViewElement for Rect
source§fn active_pixels(&self) -> Vec<Point>
fn active_pixels(&self) -> Vec<Point>
Return a vector of every coordinate where a pixel should be placed and its respective
ColChar
. If your whole object is a solid colour, consider using utils::points_to_pixels()
which will add the same ColChar
to every point and can then be used as this function’s outputAuto Trait Implementations§
impl RefUnwindSafe for Rect
impl Send for Rect
impl Sync for Rect
impl Unpin for Rect
impl UnwindSafe for Rect
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more