![Confused :?](./images/smilies/ms-confused.png)
Thanks In advance
Code: Select all
local function updateCurtainCanvas (x, y, radius)
love.graphics.setCanvas (CurtainCanvas)
-- black curtain
love.graphics.setBlendMode( "alpha")
love.graphics.setColor (0,0,0,1) -- black
love.graphics.rectangle ('fill', 0,0, CurtainCanvas:getWidth( ), CurtainCanvas:getHeight( ))
-- circle hole
love.graphics.setBlendMode( "replace")
love.graphics.setColor (1,1,1,0)
love.graphics.circle ('fill', x, y, radius)
love.graphics.setCanvas ()
end
function love.load()
-- set background
love.graphics.setBackgroundColor(132/255, 193/255, 238/255)
-- create canvas
CurtainCanvas = love.graphics.newCanvas ()
-- update canvas
updateCurtainCanvas (100, 100, 100)
end
function love.update(dt)
end
function love.draw()
-- restoring color settings
love.graphics.setColor (1,1,1)
love.graphics.setBlendMode("alpha")
-- example graphics
love.graphics.rectangle('fill', 100, 150, 350, 250)
-- and than drawing curtain
love.graphics.draw(CurtainCanvas)
end
function love.mousemoved( x, y, dx, dy, istouch )
-- update canvas
updateCurtainCanvas (x, y, math.min (x, y))
end
Code: Select all
local function updateCurtainCanvas (x, y, radius)
love.graphics.setCanvas (CurtainCanvas)
-- black curtain
love.graphics.setBlendMode( "alpha")
love.graphics.setColor (0,0,0,1) -- black
love.graphics.rectangle ('fill', 0,0, CurtainCanvas:getWidth( ), CurtainCanvas:getHeight( ))
-- circle hole
love.graphics.setBlendMode( "replace")
love.graphics.setColor (0,0,0,0.25)
love.graphics.circle ('fill', x, y, radius)
love.graphics.setColor (0,0,0,0)
love.graphics.circle ('fill', x, y, radius/2)
love.graphics.setCanvas ()
end
Code: Select all
local meshVertices = {} -- for fan mesh
local meshRadius = 1
table.insert (meshVertices, {0,0, 0,0, 1,1,1, 0}) -- white dot int the middle
for angle = 0, 360, 10 do
local x = 0+meshRadius*math.cos (math.rad(angle))
local y = 0+meshRadius*math.sin (math.rad(angle))
table.insert (meshVertices, {x,y, 0,0, 0,0,0, 1}) -- black dots on perimeter
end
Mesh = love.graphics.newMesh( meshVertices, "fan")
local function updateCurtainCanvas (x, y, radius)
love.graphics.setCanvas (CurtainCanvas)
-- black curtain
love.graphics.setBlendMode( "alpha")
love.graphics.setColor (0,0,0,1) -- black
love.graphics.rectangle ('fill', 0,0, CurtainCanvas:getWidth( ), CurtainCanvas:getHeight( ))
-- circle hole
love.graphics.setBlendMode( "replace")
love.graphics.setColor (0,0,0,0.97)
love.graphics.draw(Mesh,x, y, 0, radius)
love.graphics.setCanvas ()
end
Code: Select all
-- circle hole
love.graphics.setBlendMode( "replace")
love.graphics.setColor (1,0,0,1)
love.graphics.draw(Mesh,x, y, 0, radius)
Can you update it or add screenshot?pgimeno wrote: ↑Fri Nov 18, 2022 3:54 pm I did something similar with a canvas: https://www.love2d.org/forums/viewtopic ... 99#p204899
It looks very nice! I cannot right now look how it works, can you please in short explain that?
Users browsing this forum: Bing [Bot], Google [Bot] and 3 guests