1
0
This commit is contained in:
Jon Michael Aanes 2016-02-12 12:58:49 +01:00
parent 68c8911918
commit 7fbc5c8597

77
3/main.lua Normal file
View File

@ -0,0 +1,77 @@
math.randomseed(os.time())
local MOONS = {}
local t_moon = nil
for i = 1, 10 do
local color = {math.random(200),math.random(100),math.random(200)}
local moon = {500+math.random(400)-200,200+math.random(400)-200,math.random(10)+1,color}
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)
love.graphics.setColor(255*0.8,255*1,255*0.5,255)
love.graphics.circle("fill", 500, 100, 200)
love.graphics.setColor(255,255,255,50)
for i = 1, 40 do
love.graphics.ellipse("line", 500, 125, 300-i, 50-i*1/6 )
end
for _, moon in ipairs(MOONS) do
love.graphics.setColor(moon[4])
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)
love.graphics.setColor(255,255,255,255)
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