Created
February 27, 2020 06:48
-
-
Save incinirate/45c6fe264f54efbf86b8fda2afca95a7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
love.graphics.setDefaultFilter("linear", "linear", 16) | |
function love.load() | |
love.window.setMode(800, 600, { msaa = 0 }) | |
end | |
local triCanvas = love.graphics.newCanvas(2*1792, 2*828, { msaa = 8 }) | |
local function mkCanvas() | |
triCanvas:clear() | |
end | |
local variance = 0.1 | |
local function uvColor(u, v) | |
math.randomseed(u*500 + v) | |
local clkSpdR = math.random(5, 10) | |
-- local clkSpdG = math.random(5, 10) | |
-- local clkSpdB = math.random(5, 10) | |
local clkOffR = math.random(0, 50) | |
-- local clkOffG = math.random(0, 50) | |
-- local clkOffB = math.random(0, 50) | |
local colA = { 85/255, 205/255, 252/255 } | |
local colB = { 1, 1, 1 } | |
local colC = { 247/255, 168/255, 184/255 } | |
local pat = { colA, colC, colB, colC, colA } | |
-- local r, g, b = u, v, 0.5 | |
local idx = math.ceil(v * #pat) | |
-- print(v) | |
if idx == 0 then idx = 1 end | |
if idx > #pat then idx = #pat end | |
local r, g, b = unpack(pat[idx]) | |
-- P | B | W | B | P | |
local statVar = variance*math.sin(3*clkSpdR*os.clock() + clkOffR) | |
-- return {r + variance*math.sin(10*clkSpdR*os.clock() + clkOffR), g + variance*math.sin(10*clkSpdG*os.clock() + clkOffG), b + variance*math.sin(10*clkSpdB*os.clock() + clkOffB)} | |
return {r + statVar, g + statVar, b + statVar} | |
end | |
local triHeight = (math.sqrt(3)/2)*50 | |
local width = 1792*2/50 + 10--32 | |
local height = 828*2/triHeight + 5 | |
function love.draw() | |
love.graphics.setCanvas(triCanvas) | |
do | |
love.graphics.clear() | |
-- love.graphics.setLineStyle("smooth") | |
-- love.graphics.setLineWidth(10) | |
-- love.graphics.polygon("fill", 0, 0, 50, 0, 25, (math.sqrt(3)/2)*50) | |
for x = 0, width do | |
for y = 0, height do | |
local cx, cy = x / width, y / height | |
love.graphics.setColor(uvColor(cx, cy)) | |
local yOff = ((y / 4) % 1) | |
if y % 2 == 0 then | |
local yTri = (y / 2)*triHeight | |
-- love.graphics.setColor({1, 1, 1}) | |
love.graphics.polygon("fill", (x - yOff)*50, yTri, ((x - yOff) + 1)*50, yTri, (x - yOff)*50 + 25, yTri + triHeight) | |
else | |
local yTri = ((y - 1) / 2)*triHeight | |
local xSha = (x + yOff - 0.75) | |
-- love.graphics.setColor({0.5, 0.5, 0.5}) | |
love.graphics.polygon("fill", xSha*50, yTri + triHeight, (xSha + 1)*50, yTri + triHeight, xSha*50 + 25, yTri) | |
end | |
end | |
end | |
-- love.graphics.polygon("line", 0, 0, 2*50, 0, 2*25, 2*(math.sqrt(3)/2)*50) | |
end | |
love.graphics.setCanvas() | |
love.graphics.setColor({1, 1, 1}) | |
love.graphics.draw(triCanvas, 0, 0, 0, 0.5) | |
end | |
function love.keypressed(k) | |
if k == "up" then | |
height = height - 1 | |
elseif k == "down" then | |
height = height + 1 | |
elseif k == "s" then | |
triCanvas:newImageData():encode("png", "tri-" .. math.random(0, 100000000) .. ".png") | |
end | |
print(height) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment