Voronoi diagram: Difference between revisions
Content added Content deleted
m (Phix/pGUI) |
m (Updated to work with the latest version of LÖVE.) |
||
Line 1,113: | Line 1,113: | ||
=={{header|Lua}}== |
=={{header|Lua}}== |
||
{{libheader|LÖVE}} |
{{libheader|LÖVE}} |
||
{{works with|LÖVE| |
{{works with|LÖVE|11.3}} |
||
{{trans|Python}} |
{{trans|Python}} |
||
<lang lua> |
<lang lua> |
||
Line 1,140: | Line 1,140: | ||
table.insert( nx, love.math.random( 0, imgx ) ) |
table.insert( nx, love.math.random( 0, imgx ) ) |
||
table.insert( ny, love.math.random( 0, imgy ) ) |
table.insert( ny, love.math.random( 0, imgy ) ) |
||
table.insert( nr, love.math.random( 0, |
table.insert( nr, love.math.random( 0, 1 ) ) |
||
table.insert( ng, love.math.random( 0, |
table.insert( ng, love.math.random( 0, 1 ) ) |
||
table.insert( nb, love.math.random( 0, |
table.insert( nb, love.math.random( 0, 1 ) ) |
||
end |
end |
||
love.graphics.setColor( { |
love.graphics.setColor( { 1, 1, 1 } ) |
||
love.graphics.setCanvas( canvas ) |
love.graphics.setCanvas( canvas ) |
||
for y = 1, imgy do |
for y = 1, imgy do |
||
Line 1,162: | Line 1,162: | ||
end |
end |
||
--reset color |
--reset color |
||
love.graphics.setColor( { |
love.graphics.setColor( { 1, 1, 1 } ) |
||
--draw points |
--draw points |
||
for b = 1, num_cells do |
for b = 1, num_cells do |
||
Line 1,174: | Line 1,174: | ||
function love.draw( ) |
function love.draw( ) |
||
--reset color |
--reset color |
||
love.graphics.setColor( { |
love.graphics.setColor( { 1, 1, 1 } ) |
||
--draw diagram |
--draw diagram |
||
love.graphics.draw( voronoiDiagram ) |
love.graphics.draw( voronoiDiagram ) |
||
Line 1,181: | Line 1,181: | ||
love.graphics.print( "space: regenerate\nesc: quit", 1, 1 ) |
love.graphics.print( "space: regenerate\nesc: quit", 1, 1 ) |
||
--draw text |
--draw text |
||
love.graphics.setColor( { |
love.graphics.setColor( { 0.7, 0.7, 0 } ) |
||
love.graphics.print( "space: regenerate\nesc: quit" ) |
love.graphics.print( "space: regenerate\nesc: quit" ) |
||
end |
end |