Difference between revisions of "PixelDisplay"

From MiniScript Wiki
Jump to navigation Jump to search
(Added note about tile size)
(→‎Methods and Properties: added value column and divided into 3 categories)
Line 7: Line 7:
 
== Methods and Properties ==
 
== Methods and Properties ==
  
 +
=== Read only ===
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
! Method or Property !! Purpose
+
! Method or Property !! Purpose !! Value
 
|-
 
|-
| [[PixelDisplay.color]] || get or set the default drawing color, used when color is not otherwise specified
+
| [[PixelDisplay.width]] || number of columns in the the pixel buffer || Input: NULL
 +
Output: number
 
|-
 
|-
| [[PixelDisplay.width]] || number of columns in the the pixel buffer
+
| [[PixelDisplay.height]] || number of rows in the the pixel buffer || Input: NULL
 +
Output: number
 
|-
 
|-
| [[PixelDisplay.height]] || number of rows in the the pixel buffer
+
| [[PixelDisplay.pixel]] ''x '', ''y'' || get the color of a particular pixel || Input: x: number; y: number
 +
Output: color
 
|-
 
|-
| [[PixelDisplay.scale]] || scaling factor used to magnify (or shrink) the pixel display on screen
+
| [[PixelDisplay.getImage]](''left'', ''bottom'', ''width'', ''height'') || get a portion of the pixel buffer as an [[Image]] || Input: left: number; bottom: number; width: number; height: number
 +
Output: image
 
|-
 
|-
| [[PixelDisplay.clear]] ''[color]'', ''[width]'', ''[height]'' || clear/reset the pixel buffer
+
|}
 +
 
 +
=== Edit and read ===
 +
{| class="wikitable"
 +
|-
 +
! Method or Property !! Purpose !! Value
 +
|-
 +
| [[PixelDisplay.color]] || get or set the default drawing color, used when color is not otherwise specified || Input: color
 +
Output: color
 +
|-
 +
| [[PixelDisplay.scale]] || scaling factor used to magnify (or shrink) the pixel display on screen || Input: number
 +
Output: number
 
|-
 
|-
| [[PixelDisplay.pixel]] ''x '', ''y'' || get the color of a particular pixel
+
| [[PixelDisplay.scrollX]] || get or set a horizontal shift applied to the entire display || Input: number
 +
Output: number
 
|-
 
|-
| [[PixelDisplay.setPixel]] ''x'', ''y'', ''[color]'' || set the color of a particular pixel
+
| [[PixelDisplay.scrollY]] || get or set a vertical shift applied to the entire display ||  Input: number
 +
Output: number
 +
|-
 +
|}
 +
=== Run ===
 +
{| class="wikitable"
 
|-
 
|-
| [[PixelDisplay.scrollX]] || get or set a horizontal shift applied to the entire display
+
! Method or Property !! Purpose !! Value
 
|-
 
|-
| [[PixelDisplay.scrollY]] || get or set a vertical shift applied to the entire display
+
| [[PixelDisplay.clear]] ''[color]'', ''[width]'', ''[height]'' || clear/reset the pixel buffer || Input: color: color
 +
width: number; height: number
 
|-
 
|-
| [[PixelDisplay.line]] ''x1'', ''y1'', ''x2'', ''y2'', ''[color]'', ''[penSize]'' || draw a line
+
| [[PixelDisplay.setPixel]] ''x'', ''y'', ''[color]'' || set the color of a particular pixel || Input: x: number; y: number; color: color
 
|-
 
|-
| [[PixelDisplay.drawRect]] ''left'', ''bottom'', ''width'', ''height'', ''[color]'', ''[penSize]'' || draw a rectangle outline
+
| [[PixelDisplay.line]] ''x1'', ''y1'', ''x2'', ''y2'', ''[color]'', ''[penSize]'' || draw a line || Input: x1: number; y1: number; x2: number; x2: number;  color: color; penSize: num
 
|-
 
|-
| [[PixelDisplay.fillRect]] ''left'', ''bottom'', ''width'', ''height'', ''[color]'' || draw a filled rectangle
+
| [[PixelDisplay.drawRect]] ''left'', ''bottom'', ''width'', ''height'', ''[color]'', ''[penSize]'' || draw a rectangle outline || Input: left: number; bottom: number; width: number; height: number;  color: color; penSize: num
 
|-
 
|-
| [[PixelDisplay.drawEllipse]] ''left'', ''bottom'', ''width'', ''height'', ''[color]'', ''[penSize]'' || draw an ellipse outline
+
| [[PixelDisplay.fillRect]] ''left'', ''bottom'', ''width'', ''height'', ''[color]'' || draw a filled rectangle ||
 +
Input: left: number; bottom: number; width: number; height: number;  color: color
 
|-
 
|-
| [[PixelDisplay.fillEllipse]] ''left'', ''bottom'', ''width'', ''height'', ''[color]'' || draw a filled ellipse
+
| [[PixelDisplay.drawEllipse]] ''left'', ''bottom'', ''width'', ''height'', ''[color]'', ''[penSize]'' || draw an ellipse outline || Input: left: number; bottom: number; width: number; height: number;  color: color; penSize: num
 
|-
 
|-
| [[PixelDisplay.drawPoly]] ''points'', ''[color]'', ''[penSize]'' || draw a polygon outline
+
| [[PixelDisplay.fillEllipse]] ''left'', ''bottom'', ''width'', ''height'', ''[color]'' || draw a filled ellipse || Input: left: number; bottom: number; width: number; height: number;  color: color
 
|-
 
|-
| [[PixelDisplay.fillPoly]] ''points'', ''[color]'' || draw a filled polygon
+
| [[PixelDisplay.drawPoly]] ''points'', ''[color]'', ''[penSize]'' || draw a polygon outline || Input: points: list of pare of nums; color: color; penSize: num
 
|-
 
|-
| [[PixelDisplay.drawImage]] ''img'', ''left'', ''bottom'', ''[width]'', ''[height]'', ''[srcLeft]'', ''[srcBottom]'', ''[srcWidth]'', ''[srcHeight]'' || draw an [[Image]] (or portion thereof)
+
| [[PixelDisplay.fillPoly]] ''points'', ''[color]'' || draw a filled polygon || Input: points: list of pare of nums; color: color
 
|-
 
|-
| [[PixelDisplay.getImage]](''left'', ''bottom'', ''width'', ''height'') || get a portion of the pixel buffer as an [[Image]]
+
| [[PixelDisplay.drawImage]] ''img'', ''left'', ''bottom'', ''[width]'', ''[height]'', ''[srcLeft]'', ''[srcBottom]'', ''[srcWidth]'', ''[srcHeight]'' || draw an [[Image]] (or portion thereof) || Input: img: image; left: number; bottom: number; width: number; height: number; scrWidth: number; scrHeight
 
|-
 
|-
| [[PixelDisplay.print]] ''str'', ''x'', ''y'', ''[color]'', ''[font]'' || draw a string
+
| [[PixelDisplay.print]] ''str'', ''x'', ''y'', ''[color]'', ''[font]'' || draw a string || Input: str: string; x: number; y: number; color: color; font: font
 
|}
 
|}
  

Revision as of 10:06, 29 January 2025

The PixelDisplay class in Mini Micro is a display type that represents a rectangular pixel buffer, with methods to efficiently draw lines, shapes, images, and text.

By default, display 5 is configured as a pixel display, and is in fact the pixel display to which the gfx global refers (unless you change it). But you can make any display layer a pixel display by setting its mode to displayMode.pixel.

A PixelDisplay is 960 x 640 pixels by default (see screen coordinates), though this may be changed via the clear method.

Methods and Properties

Read only

Method or Property Purpose Value
PixelDisplay.width number of columns in the the pixel buffer Input: NULL

Output: number

PixelDisplay.height number of rows in the the pixel buffer Input: NULL

Output: number

PixelDisplay.pixel x , y get the color of a particular pixel Input: x: number; y: number

Output: color

PixelDisplay.getImage(left, bottom, width, height) get a portion of the pixel buffer as an Image Input: left: number; bottom: number; width: number; height: number

Output: image

Edit and read

Method or Property Purpose Value
PixelDisplay.color get or set the default drawing color, used when color is not otherwise specified Input: color

Output: color

PixelDisplay.scale scaling factor used to magnify (or shrink) the pixel display on screen Input: number

Output: number

PixelDisplay.scrollX get or set a horizontal shift applied to the entire display Input: number

Output: number

PixelDisplay.scrollY get or set a vertical shift applied to the entire display Input: number

Output: number

Run

Method or Property Purpose Value
PixelDisplay.clear [color], [width], [height] clear/reset the pixel buffer Input: color: color

width: number; height: number

PixelDisplay.setPixel x, y, [color] set the color of a particular pixel Input: x: number; y: number; color: color
PixelDisplay.line x1, y1, x2, y2, [color], [penSize] draw a line Input: x1: number; y1: number; x2: number; x2: number; color: color; penSize: num
PixelDisplay.drawRect left, bottom, width, height, [color], [penSize] draw a rectangle outline Input: left: number; bottom: number; width: number; height: number; color: color; penSize: num
PixelDisplay.fillRect left, bottom, width, height, [color] draw a filled rectangle

Input: left: number; bottom: number; width: number; height: number; color: color

PixelDisplay.drawEllipse left, bottom, width, height, [color], [penSize] draw an ellipse outline Input: left: number; bottom: number; width: number; height: number; color: color; penSize: num
PixelDisplay.fillEllipse left, bottom, width, height, [color] draw a filled ellipse Input: left: number; bottom: number; width: number; height: number; color: color
PixelDisplay.drawPoly points, [color], [penSize] draw a polygon outline Input: points: list of pare of nums; color: color; penSize: num
PixelDisplay.fillPoly points, [color] draw a filled polygon Input: points: list of pare of nums; color: color
PixelDisplay.drawImage img, left, bottom, [width], [height], [srcLeft], [srcBottom], [srcWidth], [srcHeight] draw an Image (or portion thereof) Input: img: image; left: number; bottom: number; width: number; height: number; scrWidth: number; scrHeight
PixelDisplay.print str, x, y, [color], [font] draw a string Input: str: string; x: number; y: number; color: color; font: font

Implementation Note

For performance reasons, a PixelDisplay under the hood is made up of 256x256 pixel tiles. These are initialized to the color passed to PixelDisplay.clear. As a result, if your width or height is not an even multiple of 256, then this initial clear color will extend beyond the usable area. As an example, try:

gfx.clear color.red, 200,200
gfx.fillRect 0,0,gfx.width,gfx.height, color.blue

This displays a 200x200 blue square (the official size of the pixel display) with an additional red area extending 256x256 (one full tile) in size.