Shapes - TBTerra/pictor GitHub Wiki

Draw Shape Functions

These commands are used to draw shapes and sprites to the screen, such as pixels, boxes, circles or the whole screen.


Commands

void pictorDrawPixel(const point Pos, const uint16_t Colour);

Draws a single pixel with a specified colour at the specified position.

Parameters:

  1. Pos - Point structure to pixel's intended location.
  2. Colour - Colour for the pixel as a 656-RGB encoded colour.

void pictorDrawLine(point A, point B, const uint16_t Colour);

Draws a straight line with a specified colour between the points A and B.

Parameters:

  1. A - Point structure, the intended location of an endpoint of the line.
  2. B - Point structure, the intended location of the other endpoint.
  3. Colour - Colour for the area as a 656-RGB encoded colour.

void pictorDrawBox(point A, point B, const uint16_t Colour);

Draws a solid box with a specified colour between the points A and B.

Parameters:

  1. A - Point structure the intended location of a corner of the area.
  2. B - Point structure the intended location of the opposite corner of the area.
  3. Colour - Colour for the area as a 656-RGB encoded colour.

void pictorDrawAll(const uint16_t Colour);

Fills the screen with the specified colour.

Parameters:

  1. Colour - Colour for the screen as a 656-RGB encoded colour.

void pictorDrawSpritePartial(const sprite * Sprite, const point Pos, const uint8_t Scale, point X1, point X2);

Draw part of a sprite selected by X1 and X2.

Parameters:

  1. Sprite - Pointer to the sprite array to be written to the screen.
  2. Pos - Point structure to the top-left corner of the sprite's intended location.
  3. Scale - Integer size scale (Note: A scale of 1 produces a pixel to pixel representation of the stored sprite).
  4. X1 - Point structure between the top-left of the total sprite and the top-left corner to be drawn.
  5. X2 - Point structure between the top-left of the total sprite and the bottom-right corner to be drawn.

void pictorDrawSpriteType(const sprite * Sprite, const point Pos, const uint8_t type, const uint8_t Scale);

Draws a Sprite of type Type, top left aligned at Pos scaled by Scale.

Parameters:

  1. Sprite - Pointer to the sprite array to be written to the screen.
  2. Pos - Point structure to the top-left corner of the sprite's intended location.
  3. type - Integer type number, from the available sprite types.
  4. Scale - Integer size scale (Note: A scale of 1 produces a pixel to pixel representation of the stored sprite

Sprite types:

  • 0 - full colour in memory
  • 1 - full colour in PROGMEM
  • 2 - 1bit in memory
  • 3 - 1bit in PROGMEM
  • 4 - Palette and indexed sprite in memory
  • 5 - Indexed sprite in PROGMEM, palette in memory
  • 6 - Indexed sprite in memory, palette in PROGMEM
  • 7 - Palette and indexed sprite in PROGMEM
  • 8 - Palette and packed pixels in memory
  • 9 - Packed pixels in PROGMEM, palette in memory
  • 10 - Packed pixels in memory, palette in PROGMEM
  • 11 - Palette and packed pixels in PROGMEM

void pictorDrawCircle(const point Centre, const uint8_t Radius, const uint16_t Colour);

Draws a circle using Bresenham's algorithm of the specified colour around a defined centre of the specified radius.

Parameters:

  1. Centre - Point structure to the intended location of the centre of the circle.
  2. Radius - The radius of the circle in pixels.
  3. Colour - Colour of the circle as a 656-RGB encoded colour.

Sprite Types

Due to the space limitations of the Atmel ATMega644p, Pictor provides a range ways of storing sprites where colour flexibility can be traded for reduced storage size.

Types 0 & 1:

  • These types of sprite have the colour values of each pixel stored in an array. Type 1 stores the pixel array in program memory.
    • No limit to the number of colours used
    • 2 bytes used per pixel

Types 2 & 3:

  • These types of sprite store 8 pixels' information per byte in the array with each bit representing a boolean choice between a foreground and a background colour stored in the sprite. Type 3 stores the pixel array in program memory.
    • Only 2 colours per sprite
    • 8 pixels are stored per byte

Types 4-7:

  • In these types of sprite the up to 16 colours used by the sprite are stored in a palette array. Each byte in the data array then contains a 4-bit palette colour index and a 4-bit count of how many consecutive pixels are that colour. Types 5 & 7 store the data array in program memory. Types 6 & 7 store the palette array in program memory.
    • Up to 16 colours per sprite
    • Very compact for sprites with large areas of a single colour
    • Will not be supported by pictorDrawSpriteTypePartial()

Types 8-11:

  • In these types of sprite the up to 16 colours used by the sprite are stored in a palette array. Each byte in the data array then contains a pair of 4-bit palette colour indexes for each consecutive pair of pixels. Types 9 & 11 store the data array in program memory. Types 10 & 11 store the palette array in program memory.
    • Up to 16 colours per sprite
    • 2 pixels are stored per byte