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()
love.graphics.setPointSize(3)
love.graphics.points(stars) -- draw all stars as points
end
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
local r = math.random(1, 3)
local color = {0.5+0.5*math.random(), 0.5+0.5*math.random(), 0.5+0.5*math.random()}
local star = {x=x, y=y, r=r, color = color}
table.insert (stars, star) -- stick the values into the table
end
end
function love.draw()
for i, star in pairs (stars) do
love.graphics.setColor(star.color)
love.graphics.circle('fill', star.x, star.y, star.r)
end
end
Attachments
2021-07-15T18_39_54-Untitled.png (6.79 KiB) Viewed 7528 times
A million thanks on showing me a way to think about and tackle my situation to reach my goal. This looks amazing. and we are using pairs because of our custom key value pairs.
klewis wrote: ↑Thu Jul 15, 2021 5:19 pm
A million thanks on showing me a way to think about and tackle my situation to reach my goal. This looks amazing. and we are using pairs because of our custom key value pairs.
function new_star ()
local padding = 5
local x = love.math.random(padding, screen_width-padding) -- generate a "random" number for the x coord of this star
local y = love.math.random(padding, screen_height-padding) -- both coords are limited to the screen size, minus 5 pixels of padding
local r = math.random(1, 3)
-- local r = 1
local color = {0.5+0.5*love.math.random()^0.5, 0.5+0.5*love.math.random()^0.5, 0.5+0.5*love.math.random()^0.5}
local star = {x=x, y=y, r=r, color = color}
return star
end
function love.load()
screen_width, screen_height = love.graphics.getDimensions()
center = {x=screen_width/2, y=screen_height/2}
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 star = new_star ()
table.insert (stars, star) -- stick the values into the table
end
end
function love.update(dt)
for i, star in pairs (stars) do
star.x = star.x + dt*(star.x-center.x)
star.y = star.y + dt*(star.y-center.y)
star.r = star.r + dt*2
if (star.x < 0) or (star.y < 0) or (star.x > screen_width) or (star.y > screen_height) then
-- out of screen, replace the star with the new one
stars[i] = new_star ()
end
end
end
function love.draw()
for i, star in pairs (stars) do
love.graphics.setColor(star.color)
love.graphics.circle('fill', star.x, star.y, star.r)
end
end
function new_star (bool)
local padding = 5
local x = love.math.random(padding, screen_width-padding) -- generate a "random" number for the x coord of this star
if bool then -- new stars on edge
x = screen_width
end
local y = love.math.random(padding, screen_height-padding) -- both coords are limited to the screen size, minus 5 pixels of padding
local r = 1+5*math.random()^4
-- local r = 1
local color = {0.5+0.5*love.math.random()^0.5, 0.5+0.5*love.math.random()^0.5, 0.5+0.5*love.math.random()^0.5}
local star = {x=x, y=y, r=r, color = color}
return star
end
function love.load()
screen_width, screen_height = love.graphics.getDimensions()
center = {x=screen_width/2, y=screen_height/2}
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 star = new_star ()
table.insert (stars, star) -- stick the values into the table
end
end
function love.update(dt)
for i, star in pairs (stars) do
star.x = star.x + dt*(-star.r*100)
if (star.x < 0) or (star.y < 0) or (star.x > screen_width) or (star.y > screen_height) then
stars[i] = new_star (true) -- out of screen, replace the star with the new one
end
end
end
function love.draw()
for i, star in pairs (stars) do
love.graphics.setColor(star.color)
love.graphics.circle('fill', star.x, star.y, star.r)
end
end
function new_star (bool)
local padding = 5
local x = love.math.random(padding, screen_width-padding) -- generate a "random" number for the x coord of this star
if bool then -- new stars on edge
x = screen_width
end
local y = love.math.random(padding, screen_height-padding) -- both coords are limited to the screen size, minus 5 pixels of padding
local r = 0.5+5*math.random()^2
-- local r = 1
local color = {0.5+0.5*love.math.random()^0.5, 0.5+0.5*love.math.random()^0.5, 0.5+0.5*love.math.random()^0.5}
local star = {x=x, y=y, r=r, color = color}
star.vx = (-star.r*500)*(0.1+0.9*math.random())
star.x = star.x - (1/60)*star.vx
return star
end
function love.load()
screen_width, screen_height = love.graphics.getDimensions()
center = {x=screen_width/2, y=screen_height/2}
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 star = new_star ()
table.insert (stars, star) -- stick the values into the table
end
end
function love.update(dt)
for i, star in pairs (stars) do
star.x = star.x + dt*star.vx
if (star.x < 0) then
stars[i] = new_star (true) -- out of screen, replace the star with the new one
end
end
end
function love.draw()
for i, star in pairs (stars) do
love.graphics.setColor(star.color)
love.graphics.setLineWidth( star.r/2 )
love.graphics.line(star.x, star.y, star.x-(star.vx^2)*0.00002, star.y)
end
end