Difference between revisions of "love.graphics.point"

m (Remove link to deprecated function.)
(Updated example)
Line 13: Line 13:
 
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 ==
 
== Examples ==
Render a starfield.
+
Render a starfield
 
<source lang="lua">
 
<source lang="lua">
 
function love.load()
 
function love.load()
 +
  local screen_width, screen_height = love.graphics.getDimensions()
 +
  local max_stars = 100  -- how many stars we want
 +
 
   stars = {}  -- table which will hold our stars
 
   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
 
   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 x = love.math.random(5, screen_width-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
+
       local y = love.math.random(5, screen_height-5)  -- both coords are limited to the screen size, minus 5 pixels of padding
 
       stars[i] = {x, y}  -- stick the values into the table
 
       stars[i] = {x, y}  -- stick the values into the table
 
   end
 
   end
 
end
 
end
 +
 
function love.draw()
 
function love.draw()
   for i=1, #stars do  -- loop through all of our stars
+
   for i, star in ipairs(stars) do  -- loop through all of our stars
       love.graphics.point(stars[i][1], stars[i][2])  -- draw each point
+
       love.graphics.point(star[1], star[2])  -- draw each point
 
   end
 
   end
 
end
 
end

Revision as of 02:52, 14 November 2015

Draws a point.

Function

Synopsis

love.graphics.point( x, y )

Arguments

number x
The position on the x-axis.
number y
The position on the y-axis.

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()
   local screen_width, screen_height = love.graphics.getDimensions()
   local max_stars = 100   -- how many stars we want

   stars = {}   -- table which will hold our stars

   for i=1, max_stars do   -- generate the coords of our stars
      local x = love.math.random(5, screen_width-5)   -- generate a "random" number for the x coord of this star
      local y = love.math.random(5, screen_height-5)   -- both coords are limited to the screen size, minus 5 pixels of padding
      stars[i] = {x, y}   -- stick the values into the table
   end
end

function love.draw()
   for i, star in ipairs(stars) do   -- loop through all of our stars
      love.graphics.point(star[1], star[2])   -- draw each point
   end
end

See Also


Other Languages