1
0
dIntDesJam/2016-uge3/main.lua

82 lines
2.2 KiB
Lua
Raw Normal View History

2016-02-12 11:58:49 +00:00
2024-09-19 15:42:50 +00:00
local COLOR_WHITE = {1,1,1}
local COLOR_PLANET = {0.8,1,0.5,1}
local COLOR_SPACE = {1,1,1,50/255}
2016-02-12 11:58:49 +00:00
math.randomseed(os.time())
local MOONS = {}
local t_moon = nil
for i = 1, 10 do
2024-09-19 15:42:50 +00:00
local color = { math.random(200)/255,math.random(100)/255,math.random(200)/255 }
local moon = {500+math.random(400)-200,200+math.random(400)-200,math.random(10)+1, color = color}
2016-02-12 11:58:49 +00:00
table.insert(MOONS, moon)
if moon[2] > 50 and (not t_moon or math.random()>0.5) then
t_moon = moon
end
end
local function generate_planet_canvas ()
local canvas = love.graphics.newCanvas()
local shader = love.graphics.newShader([[
vec4 effect( vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords )
{
vec4 texcolor = Texel(texture, texture_coords);
if (color.r == 0.8 && color.g == 1 && color.b == 0.5) {
float dist = sqrt(pow(screen_coords.x-500, 2)+pow(screen_coords.y-100, 2));
return vec4(0.8, 1, 0.5, 1) * min(1, 0.05*(208-dist));
} else if (color.r == 1 && color.g == 1 && color.b == 1 && screen_coords.y<100 && (pow(screen_coords.x-500, 2)+pow(screen_coords.y-100, 2) < 200*200)) {
return vec4(0, 0, 0, 0);
} else {
return texcolor * color;
}
}
]])
love.graphics.setCanvas(canvas)
love.graphics.setShader(shader)
2024-09-19 15:42:50 +00:00
love.graphics.setColor(COLOR_PLANET)
2016-02-12 11:58:49 +00:00
love.graphics.circle("fill", 500, 100, 200)
2024-09-19 15:42:50 +00:00
love.graphics.setColor(COLOR_SPACE)
2016-02-12 11:58:49 +00:00
for i = 1, 40 do
love.graphics.ellipse("line", 500, 125, 300-i, 50-i*1/6 )
end
for _, moon in ipairs(MOONS) do
2024-09-19 15:42:50 +00:00
love.graphics.setColor(moon.color)
2016-02-12 11:58:49 +00:00
love.graphics.circle("fill",moon[1],moon[2],moon[3])
end
love.graphics.setShader()
love.graphics.setCanvas()
return canvas
end
--------------------------------------------------------------------------------
local PLANET = generate_planet_canvas()
local SCREENS = {}
SCREENS[1] = function (t)
t = t * 0.1
love.graphics.draw(PLANET)
2024-09-19 15:42:50 +00:00
love.graphics.setColor(COLOR_WHITE)
2016-02-12 11:58:49 +00:00
love.graphics.circle("fill", 400*(1-t)+t_moon[1]*t, 600*(1-t)+t*t_moon[2], math.min(0, 50*(t-1)))
end
local screen_id = 1
local time = 0
--------------------------------------------------------------------------------
function love.load ()
end
function love.update (dt)
time = time + dt
end
function love.draw ()
SCREENS[screen_id](time)
end