Struct glitter::image_data::Pixels [] [src]

pub struct Pixels { /* fields omitted */ }

A (heap-allocated) 2D image composed of a list of pixels.

Example

// Draw a red circle with a 50px radius in a 100px * 100px black image.
extern crate glitter;

let width = 100;
let height = 100;
let radius = 50.0;

let (center_x, center_y) = (width as f32/2.0, height as f32/2.0);

let mut pixels = glitter::Pixels::new(width, height);
for x in 0..width {
    for y in 0..height {
        let dx = center_x - x as f32;
        let dy = center_y - y as f32;
        let distance = (dx*dx + dy*dy).sqrt();

        let color = if distance < radius {
            // The point is within the circle, so it should be red
            glitter::Pixel::rgb(0xFF0000)
        }
        else {
            // The point is outside the circle, so it should be black
            glitter::Pixel::rgb(0x000000)
        };
        pixels[y][x] = color;
    }
}

Methods

impl Pixels
[src]

[src]

Create a new image with the desired width and height. Pixels are initialized with Pixel::default().

Trait Implementations

impl Clone for Pixels
[src]

[src]

Returns a copy of the value. Read more

1.0.0
[src]

Performs copy-assignment from source. Read more

impl Index<usize> for Pixels
[src]

The returned type after indexing.

[src]

Performs the indexing (container[index]) operation.

impl IndexMut<usize> for Pixels
[src]

[src]

Performs the mutable indexing (container[index]) operation.

impl Image2d for Pixels
[src]

[src]

Get the width of the image, in texels.

[src]

Get the height of the image, in texels.

[src]

Get the format of the image data that is returned by the texel_bytes method. Read more

[src]

Get the raw texel data of the image data, as a u8 slice.

impl<'a, I, P> From<I> for Pixels where
    I: GenericImage<Pixel = P>,
    P: Pixel<Subpixel = u8>, 
[src]

[src]

Performs the conversion.