Draw some heart #21
turgenevivan
started this conversation in
Show and tell
Replies: 3 comments
-
This is really awesome! Great work! |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thanks for like it. Please feel free to modify and add it to |
Beta Was this translation helpful? Give feedback.
0 replies
-
local width = 144
local height = 144
local window_scale = 4 -- Draw the heart shape with color
local function draw_heart3d_animate(t)
-- Heart scaling based on time (to create the pulsing effect)
local s = math.sin(t)
local a = s * s * s * s * 0.2 -- Scaling factor based on sine wave
for sy = 0, height - 1 do
local z = 1.5 - sy * 3.0 / height -- Map screen coordinates to z
z = z * (1.2 - a) -- animate
for sx = 0, width - 1 do
local x = sx * 3.0 / width - 1.5 -- Map screen coordinates to x
x = x * (1.2 + a) -- animate
local v = f(x, 0.0, z) -- Evaluate the heart equation
local r = 0 -- Red channel value
if v <= 0.0 then
local y0 = h(x, z) -- Get the y value at (x, z)
local ny = 0.0011 -- Small offset for normal calculation
local nx = h(x + ny, z) - y0 -- Calculate the normal x component
local nz = h(x, z + ny) - y0 -- Calculate the normal z component
local nd = 1.0 / math.sqrt(nx * nx + ny * ny + nz * nz) -- Normalize
local d = (nx + ny - nz) * nd * 0.5 + 0.5 -- Calculate brightness
r = math.floor(d * 255.0) -- Map to 0-255 range
end
-- Ensure red channel is clamped between 0 and 255
r = math.max(0, math.min(255, r))
-- Set the pixel color (R, G, B)
local color = fenster.rgb(r, 0, 0)
window:set(sx, sy, color) -- Only red color
end
end
end |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Thanks for the cool lua lib.
play with keyboard 1/2/3.
Lua Code
windows playground.
playground.zip
https://github.com/rrcenter/lua-fenster-playground
Beta Was this translation helpful? Give feedback.
All reactions