Skip to content

Commit

Permalink
Bunch of script updates
Browse files Browse the repository at this point in the history
  • Loading branch information
emmachase committed Sep 10, 2017
1 parent 6bc2c2b commit d42d5d0
Show file tree
Hide file tree
Showing 36 changed files with 1,581 additions and 579 deletions.
6 changes: 4 additions & 2 deletions scripts/boot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,18 @@ local coreFont = font.new(data)
gpu.font = coreFont

function write(t, x, y, col, target)
local fnt = gpu.font.data

t = tostring(t)
col = col or 16
local xoff = 0
for i=1, #t do
local text = t:sub(i, i)
local c = string.byte(text)
if gpu.font.data[c] then
if fnt[c] then
for j=1, 7 do
for k=1, 7 do
if gpu.font.data[c][j][k] then
if fnt[c][j][k] then
local dx = x + xoff + k
local dy = y + j
if target then
Expand Down
52 changes: 40 additions & 12 deletions scripts/home/demos/circ.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
Random fun little thing
... I don't even know
Inspired by @egordorichev
]]
Expand All @@ -15,36 +14,65 @@ local w, h = gpu.width, gpu.height

local gpp = dofile("/lib/gpp.lua")

local sin, cos = math.sin, math.cos

local timer = 0
local vel = 0
local off = 0
local loff = 0
local function update(dt)
timer = timer + (2 * dt)
timer = timer + dt
vel = 10 * sin(2 * timer)
loff = off
off = off + vel * dt
end

local function round(n)
if n % 1 >= 0.5 then
return n % 1 + 1
else
return n % 1
end
end

local gr = 50

local function cfunc(i, j)
if round(i / (math.pi / 2)) % 2 == 0 then
return 16
else
if j % 2 == 0 then
return 9
else
return 8
end
end
end

local function draw()
for i = 1, 1499 do
local x, y = math.random(1, w), math.random(1, h)
-- gpu.drawRectangle(x - 1, y, 3, 1, 1)
-- gpu.drawRectangle(x, y - 1, 1, 3, 1)
gpu.drawPixel(x - 1, y, 1)
gpu.drawPixel(x + 1, y, 1)
gpu.drawPixel(x, y - 1, 1)
gpu.drawPixel(x, y + 1, 1)
end
-- gpu.clear()

for j = 0.5, 4, 0.5 do
for j = 1, 7 do
for i = 0, 2 * math.pi, math.pi / 4 do
local r = (math.sin(4 * timer + i) * gr + gr) * j
gpp.fillEllipse(w / 2 + math.cos(timer + i + (10 * j)) * r, h / 2 + math.sin(timer + i + (10 * j)) * r, 10, 10, math.floor(i * 12 + timer) % 15 + 2)
local r = (sin((timer + j / 3) * 1.5) + 1.25) * (35 + j * 10)
-- local cloff = loff * (j % 2 == 0 and 1 or -1)
-- local coff = off * (j % 2 == 0 and 1 or -1)

for k = math.min(off, loff), math.max(off, loff), 0.05 do
local coff = k * (j % 2 == 0 and 1 or -1)
gpp.fillEllipse(w / 2 + math.cos(coff + i) * r, h / 2 + math.sin(coff + i) * r, 10, 10, cfunc(i, j))
--math.floor((i + j) * 12) % 15 + 2)
end
end
end

-- for i = 0, 2 * math.pi, math.pi / 2 do
-- local r = (4 * gr) - (math.sin(4 * timer + i) * (4 * gr) + (4 * gr))
-- gpp.fillEllipse(w / 2 + math.cos(timer + i) * r, h / 2 + math.sin(timer + i) * r, 10, 10, math.floor(i * 12 + timer) % 15 + 2)
-- end

gpu.swap()
end

Expand Down
Binary file added scripts/home/demos/dither/astc.bmp.rif
Binary file not shown.
5 changes: 5 additions & 0 deletions scripts/home/demos/dither/dither.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
-- (1/32)

local bitmap = dofile("/lib/bitmap.lua")
local rif = dofile("/lib/rif.lua")

local file = ({...})[1] or "land.bmp"

Expand Down Expand Up @@ -91,6 +92,10 @@ for i=1, ditherImage.height do
end
end

local handle = fs.open(file .. ".rif", "w")
handle:write(rif.encode(dithered, ditherImage.width, ditherImage.height))
handle:close()

while true do
gpu.clear()

Expand Down
Binary file added scripts/home/demos/dither/tucan.bmp.rif
Binary file not shown.
File renamed without changes.
Binary file modified scripts/home/demos/ghost.rif
Binary file not shown.
44 changes: 38 additions & 6 deletions scripts/home/demos/ltest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,23 @@ local running = true

local rif = dofile("/lib/rif.lua")

local handle = fs.open("logo.rif", "rb")
local file = ({...})[1] or "logo.rif"
local handle = fs.open(file, "rb")
local data = handle:read("*a")
handle:close()

local rifData, w, h = rif.decode1D(data)

local rifImg = rif.createImage(rifData, w, h)

local track = {}

local c = 1
for i = 1, h do
for j = 1, w do
local d = rifData[c]
if d ~= -1 then
track[#track + 1] = {c = d, dx = j + (gpu.width / 2 - 15), dy = i + (gpu.height / 2 - 35)}
track[#track + 1] = {c = d, dx = j + (gpu.width - w) / 2, dy = i + (gpu.height - h) / 2}
--x = j + 140 + math.random(-40, 40), y = i + 85 + math.random(-40, 40)}
end
c = c + 1
Expand All @@ -41,20 +44,49 @@ local round = function(x)
end
end

-- local lookup = {}
-- for i = 1, #track do
-- lookup[i] = i
-- end
-- local dorder = {}
-- for i = 1, #track do
-- dorder[i] = table.remove(lookup, math.random(1, #lookup))
-- end

local frms = 0
local function drawContent()
local brkpt = 5
for i=1, #track do
frms = frms + 1
local brkpt = w
gpu.clear()
-- local min = math.huge
for i=math.max(0, math.floor((frms - 90)/1.4) * w) + 1, #track do
-- local i = dorder[pt]
if not track[i].x then
track[i].x = track[i].dx + math.random(-40, 40)
track[i].y = track[i].dy + math.random(-40, 40)
brkpt = brkpt - 1
if brkpt == 0 then break end
end
gpu.drawPixel(round(track[i].x), round(track[i].y), track[i].c)

-- if min > i then min = i end

if math.abs(track[i].x - track[i].dx) < 1 then
gpu.drawPixel(track[i].dx, track[i].dy, track[i].c)
else
gpu.drawPixel(round(track[i].x), round(track[i].y), track[i].c)
end

track[i].x = (track[i].dx - track[i].x) * 0.04 + track[i].x
track[i].y = (track[i].dy - track[i].y) * 0.04 + track[i].y
end

if math.max(0, math.floor((frms - 90)/1.4)) + 1 > 1 then
rifImg:render((gpu.width - w) / 2 + 1, (gpu.height - h) / 2 + 1, w, math.min(h, math.max(0, math.floor((frms - 90)/1.4)) + 1))
end

-- print(min)

-- rifImg:render(1, 1)
end

local eventQueue = {}
Expand All @@ -75,4 +107,4 @@ while running do
drawContent()

gpu.swap()
end
end
Loading

0 comments on commit d42d5d0

Please sign in to comment.