Sketch

Struct Sketch 

Source
pub struct Sketch<S: State> {
Show 16 fields pub width: usize, pub height: usize, pub is_looping: bool, pub frame_count: u32, pub delta_time: f32, pub mouse_x: f32, pub mouse_y: f32, pub mouse_is_pressed: bool, pub mouse_button: MouseButton, pub draw_method: Option<fn(&mut Self)>, pub setup_method: Option<fn(&mut Self)>, pub mouse_pressed_method: Option<fn(&mut Self)>, pub mouse_released_method: Option<fn(&mut Self)>, pub key_pressed_method: Option<fn(&mut Self, Key)>, pub key_released_method: Option<fn(&mut Self, Key)>, pub state: S, /* private fields */
}

Fields§

§width: usize§height: usize§is_looping: bool§frame_count: u32§delta_time: f32§mouse_x: f32§mouse_y: f32§mouse_is_pressed: bool§mouse_button: MouseButton§draw_method: Option<fn(&mut Self)>§setup_method: Option<fn(&mut Self)>§mouse_pressed_method: Option<fn(&mut Self)>§mouse_released_method: Option<fn(&mut Self)>§key_pressed_method: Option<fn(&mut Self, Key)>§key_released_method: Option<fn(&mut Self, Key)>§state: S

Implementations§

Source§

impl<S: State> Sketch<S>

Source

pub fn from_size(width: usize, height: usize, state: S) -> Sketch<S>

Initializes a Sketch

Source

pub fn run(&mut self)

main loop of the Sketch

Source

pub fn name(&mut self, name: &str)

Changes the name of the window

Source

pub fn key_is_down(&self, key: Key) -> bool

Checks if the key: Key is currently pressed

Source

pub fn no_loop(&mut self)

Stops the animation loop

Source

pub fn framerate(&mut self, fps: usize)

Sets the framerate limit of the window

Source

pub fn fill(&mut self, color: u32)

Sets the current fill color

Source

pub fn no_fill(&mut self)

Removes current fill color, drawn shapes will be hollow

Source

pub fn stroke(&mut self, color: u32)

Sets the current stroke color

Source

pub fn no_stroke(&mut self)

Removes the current stroke color, drawn shapes will not have an outline

Source

pub fn stroke_weight(&mut self, weight: i8)

Sets the thickness of the outline

Source

pub fn stroke_mode(&mut self, mode: StrokeMode)

Changes the current stroke mode, see StrokeMode

Source

pub fn fill_pixel(&mut self, x: i32, y: i32)

Applies current fill color to pixel at x,y

Source

pub fn stroke_pixel(&mut self, x: i32, y: i32)

Applies current stroke color to pixel at x,y

Source

pub fn rect(&mut self, x: i32, y: i32, w: i32, h: i32)

Draws a rectangle at x,y with side lengths w,h

Source

pub fn triangle(&mut self, x0: i32, y0: i32, x1: i32, y1: i32, x2: i32, y2: i32)

Draws a triangle between points x0,y0 x1,y1 and x2,y2

Source

pub fn circle(&mut self, x: i32, y: i32, r: i32)

Draws a circle at x,y with radius r

Source

pub fn background(&mut self, color: u32)

Fills the window with given color

Source

pub fn save(&mut self, file_path: &str)

Saves a png screenshot of the window

Source

pub fn image( &mut self, image_buffer: ImageBuffer<Rgb<u8>, Vec<u8>>, x: i32, y: i32, )

Source

pub fn line(&mut self, x0: i32, y0: i32, x1: i32, y1: i32)

Draws a line between points x0,y0 and x1,y1

Source

pub fn begin_shape(&mut self, shape_type: ShapeType)

Indicates the start of a shape construction

Source

pub fn vertex(&mut self, x: i32, y: i32)

Add a vertex to current shape construction

Source

pub fn begin_hole(&mut self)

Indicate start of a hole within the current shape construction

Source

pub fn end_shape(&mut self)

Indicate the end of the current shape construction and render constructed shape

Source

pub fn font(&mut self, font: FontMode)

Source

pub fn text(&mut self, string: &str, x: i32, y: i32)

Auto Trait Implementations§

§

impl<S> Freeze for Sketch<S>
where S: Freeze,

§

impl<S> !RefUnwindSafe for Sketch<S>

§

impl<S> !Send for Sketch<S>

§

impl<S> !Sync for Sketch<S>

§

impl<S> Unpin for Sketch<S>
where S: Unpin,

§

impl<S> !UnwindSafe for Sketch<S>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V