An issue with a canvas
Posted: Thu Sep 19, 2013 5:32 am
Hi people, I have this code and I want to draw a canvas with a grid full of gray and white squares (to appreciate the transparency of colors)
but I only get one "row" What am I doing wrong?
Many thanks.
but I only get one "row" What am I doing wrong?
Code: Select all
function love.load()
gr=love.graphics
kb=love.keyboard
ms=love.mouse
ANCHO_BARRA_HERR=100
ancho_p=gr.getWidth()-- Ancho de la pantalla.
alto_p=gr.getHeight()-- Alto de la pantalla.
lienzo={}-- Lienzo y sus dimensiones.
-- Dimensiones por default (pixeles).
lienzo.ancho=16
lienzo.alto=16
lienzo.tam_pixel=20-- Tamano de pixel (20 pixeles reales).
--Lienzo de fondo:
fondo=gr.newCanvas(lienzo.ancho*lienzo.tam_pixel,lienzo.alto*lienzo.tam_pixel)
gr.setCanvas(fondo)
local tcf=8-- Cuadrito de fondo.
local x,y=0,0
for i=1,lienzo.alto*lienzo.tam_pixel,tcf do
y=y+1 -- THIS LINE SEEMS NOT TO WORK.
for j=1,lienzo.ancho*lienzo.tam_pixel,tcf do
x=x+1
if (x+y)%2==0 then
gr.setColor(255,255,255)
else
gr.setColor(127,127,127)
end
gr.rectangle("fill",(x-1)*tcf,(y-1)*tcf,tcf,tcf)
end
end
gr.setCanvas()
-- Crear la imagen inicial:
m={}-- Matriz.
for y=1,lienzo.alto do
-- Crear fila:
m[y]={}
for x=1,lienzo.ancho do
-- Crear un pixel blanco y con tranparencia de 100%:
local pixel={}
pixel.r=r()--255-- Red.
pixel.g=r()--255-- Green.
pixel.b=r()--255-- Blue.
pixel.o=50-- Opacity (opacidad).
-- Guardar pixel:
m[y][x]=pixel
end
end
end
function r( ... )return math.random(0,255) end
function love.update(dt)
end
function love.draw()
local x=x or ancho_p/2-lienzo.ancho*lienzo.tam_pixel/2
local y=y or alto_p/2-lienzo.alto*lienzo.tam_pixel/2+ANCHO_BARRA_HERR/2
--Dibujar fondo del lienzo:
gr.setColor(255,255,255)
gr.draw(fondo,x,y)
-- Dibujar imagen:
for i=1,lienzo.alto do
for j=1,lienzo.ancho do
gr.setColor(m[j][i].r,m[j][i].g,m[j][i].b,m[j][i].o)
gr.rectangle("fill",
x+(j-1)*lienzo.tam_pixel,
y+(i-1)*lienzo.tam_pixel,
lienzo.tam_pixel,
lienzo.tam_pixel)
end
end
end