Difference between revisions of "Lua API:Graphics"

From The Powder Toy
Jump to: navigation, search
m (Work? Nah.)
(Add gfx.drawPixel)
 
(7 intermediate revisions by 4 users not shown)
Line 2: Line 2:
  
 
== Methods ==
 
== Methods ==
 +
 +
=== graphics.textSize ===
 +
number, number graphics.textSize(string text)
 +
Returns the width and height of the specified text.
 +
 +
=== graphics.drawText ===
 +
graphics.drawText(number x, number y, string text, [number r, number g, number b, [number a]])
 +
Draws the specified text at (x,y). Providing the color is optional, if not provided defaults to white.
 +
 +
=== graphics.drawPixel ===
 +
graphics.drawPixel(number x, number y, [number r, number g, number b, [number a]])
 +
Draws a pixel at (x, y). Providing the color is optional, if not provided defaults to white.
  
 
=== graphics.drawLine ===
 
=== graphics.drawLine ===
  nil graphics.drawLine(number x1, number y1, number x2, number y2, [number r, number g, number b, [number a]])
+
  graphics.drawLine(number x1, number y1, number x2, number y2, [number r, number g, number b, [number a]])
Draws a line from (x1,y1) to (x2,y2) using either the color specified or white.
+
Draws a line from (x1,y1) to (x2,y2). Providing the color is optional, if not provided defaults to white.
  
 
=== graphics.drawRect ===
 
=== graphics.drawRect ===
  nil graphics.drawRect(number x, number y, number width, number height, [number r, number g, number b, [number a]])
+
  graphics.drawRect(number x, number y, number width, number height, [number r, number g, number b, [number a]])
Draws a hollow rectangle at (x,y) with width and height using either the color specified or white.
+
Draws a hollow rectangle at (x,y) with the specified width and height. Providing the color is optional, if not provided defaults to white.
 +
 
 +
=== graphics.fillRect ===
 +
graphics.fillRect(number x, number y, number width, number height, [number r, number g, number b, [number a]])
 +
Draws a filled rectangle at (x,y) with the specified width and height. Providing the color is optional, if not provided defaults to white.
  
 
=== graphics.drawCircle ===
 
=== graphics.drawCircle ===
  nil graphics.drawCircle(number x, number y, number radiusW, number radiusH , [number r, number g, number b, [number a]])
+
  graphics.drawCircle(number x, number y, number radiusW, number radiusH, [number r, number g, number b, [number a]])
Draws a hollow circle at (x,y) with radius of (radiusW,radiusH) using either the color specified or white.
+
Draws a hollow circle at (x,y) with radius of (radiusW,radiusH). Providing the color is optional, if not provided defaults to white.
  
 
=== graphics.fillCircle ===
 
=== graphics.fillCircle ===
  nil graphics.fillCircle(number x, number y, number radiusW, number radiusH , [number r, number g, number b, [number a]])
+
  graphics.fillCircle(number x, number y, number radiusW, number radiusH, [number r, number g, number b, [number a]])
Draws a filled circle at (x,y) with radius of (radiusW,radiusH) using either the color specified or white.
+
Draws a filled circle at (x,y) with radius of (radiusW,radiusH). Providing the color is optional, if not provided defaults to white.
 +
 
 +
=== graphics.getColors ===
 +
graphics.getColors(number color)
 +
Converts color from hex. Return number r,g,b,a.
  
=== graphics.fillRect ===
+
=== graphics.getHexColor ===
  nil graphics.fillRect(number x, number y, number width, number height, [number r, number g, number b, [number a]])
+
  graphics.getHexColor( [number r], [number g], [number b], [number a])
Draws a filled rectangle at (x,y) with width and height using either the color specified or white.
+
Converts color to hex.
  
=== graphics.textSize ===
+
=== graphics.setClipRect ===
  number, number graphics.textSize(string text)
+
  graphics.setClipRect([number x], [number y], [number w], [number h])
Returns the width and height of the specified text.
+
Sets the clip rect used while drawing graphics to the screen. Graphics drawn outside the given rectangle will be clipped out. The default clip rect is the entire screen, and clip rects will be reset to this after every frame.
  
=== graphics.drawText ===
+
Returns the old clip rect (x, y, w, h).
nil graphics.drawText(number x, number y, string text, [number r, number g, number b, [number a]])
 
Draws the text specified at (x,y) using either the color specified or white.
 
  
 
== Constants ==
 
== Constants ==
Any of these constants can be accessed with graphics.<constant name here>
+
; graphics.WIDTH
 +
The complete window width including side buttons, usually 629.
 +
; graphics.HEIGHT
 +
The complete window height including the bottom area, usually 424.
  
=== Uncatergorized ===
+
[[Category:Lua]]
; WIDTH
 
; HEIGHT
 

Latest revision as of 20:31, 10 March 2024

Various methods that allow lua to draw on the simulation screen.

Methods

graphics.textSize

number, number graphics.textSize(string text)

Returns the width and height of the specified text.

graphics.drawText

graphics.drawText(number x, number y, string text, [number r, number g, number b, [number a]])

Draws the specified text at (x,y). Providing the color is optional, if not provided defaults to white.

graphics.drawPixel

graphics.drawPixel(number x, number y, [number r, number g, number b, [number a]])

Draws a pixel at (x, y). Providing the color is optional, if not provided defaults to white.

graphics.drawLine

graphics.drawLine(number x1, number y1, number x2, number y2, [number r, number g, number b, [number a]])

Draws a line from (x1,y1) to (x2,y2). Providing the color is optional, if not provided defaults to white.

graphics.drawRect

graphics.drawRect(number x, number y, number width, number height, [number r, number g, number b, [number a]])

Draws a hollow rectangle at (x,y) with the specified width and height. Providing the color is optional, if not provided defaults to white.

graphics.fillRect

graphics.fillRect(number x, number y, number width, number height, [number r, number g, number b, [number a]])

Draws a filled rectangle at (x,y) with the specified width and height. Providing the color is optional, if not provided defaults to white.

graphics.drawCircle

graphics.drawCircle(number x, number y, number radiusW, number radiusH, [number r, number g, number b, [number a]])

Draws a hollow circle at (x,y) with radius of (radiusW,radiusH). Providing the color is optional, if not provided defaults to white.

graphics.fillCircle

graphics.fillCircle(number x, number y, number radiusW, number radiusH, [number r, number g, number b, [number a]])

Draws a filled circle at (x,y) with radius of (radiusW,radiusH). Providing the color is optional, if not provided defaults to white.

graphics.getColors

graphics.getColors(number color)

Converts color from hex. Return number r,g,b,a.

graphics.getHexColor

graphics.getHexColor( [number r], [number g], [number b], [number a])

Converts color to hex.

graphics.setClipRect

graphics.setClipRect([number x], [number y], [number w], [number h])

Sets the clip rect used while drawing graphics to the screen. Graphics drawn outside the given rectangle will be clipped out. The default clip rect is the entire screen, and clip rects will be reset to this after every frame.

Returns the old clip rect (x, y, w, h).

Constants

graphics.WIDTH

The complete window width including side buttons, usually 629.

graphics.HEIGHT

The complete window height including the bottom area, usually 424.