Difference between revisions of "love.graphics.point"
(Add an (admittedly overcomplicated) example) |
|||
Line 12: | Line 12: | ||
== Notes == | == Notes == | ||
The pixel grid is actually offset to the center of each pixel. So to get clean pixels drawn use 0.5 + integer increments. | The pixel grid is actually offset to the center of each pixel. So to get clean pixels drawn use 0.5 + integer increments. | ||
+ | == Examples == | ||
+ | Render a starfield | ||
+ | <source lang="lua"> | ||
+ | function love.load() | ||
+ | stars = {} -- table which will hold our stars | ||
+ | max_stars = 100 -- how many stars we want | ||
+ | for i=1, max_stars do -- generate the coords of our stars | ||
+ | local x = math.random(5, love.graphics.getWidth()-5) -- generate a "random" number for the x coord of this star | ||
+ | local y = math.random(5, love.graphics.getHeight()-5) -- both coords are limited to the screen size, minus 5 pixels of padding | ||
+ | stars[#stars+1] = {x, y} -- stick the values into the next available spot in the table. | ||
+ | end | ||
+ | end | ||
+ | function love.draw() | ||
+ | for i=1, #stars do -- loop through all of our stars | ||
+ | love.graphics.point(stars[i][1], stars[i][2]) -- draw each point | ||
+ | end | ||
+ | end | ||
+ | </source> | ||
== See Also == | == See Also == | ||
* [[parent::love.graphics]] | * [[parent::love.graphics]] |
Revision as of 00:59, 27 September 2011
Draws a point.
Contents
Function
Synopsis
love.graphics.point( x, y )
Arguments
Returns
Nothing.
Notes
The pixel grid is actually offset to the center of each pixel. So to get clean pixels drawn use 0.5 + integer increments.
Examples
Render a starfield
function love.load()
stars = {} -- table which will hold our stars
max_stars = 100 -- how many stars we want
for i=1, max_stars do -- generate the coords of our stars
local x = math.random(5, love.graphics.getWidth()-5) -- generate a "random" number for the x coord of this star
local y = math.random(5, love.graphics.getHeight()-5) -- both coords are limited to the screen size, minus 5 pixels of padding
stars[#stars+1] = {x, y} -- stick the values into the next available spot in the table.
end
end
function love.draw()
for i=1, #stars do -- loop through all of our stars
love.graphics.point(stars[i][1], stars[i][2]) -- draw each point
end
end
See Also
Other Languages
Dansk –
Deutsch –
English –
Español –
Français –
Indonesia –
Italiano –
Lietuviškai –
Magyar –
Nederlands –
Polski –
Português –
Română –
Slovenský –
Suomi –
Svenska –
Türkçe –
Česky –
Ελληνικά –
Български –
Русский –
Српски –
Українська –
עברית –
ไทย –
日本語 –
正體中文 –
简体中文 –
Tiếng Việt –
한국어
More info