Is there a way to memcpy from table variable?
Like: memcpy(120, MyTable , 128*128)
Hello, I need to do something very similar. My use case: I want to draw a sprite to RAM, apply some transformation to the memory zone and then draw the memory back to the screen. I think that I have it it in mind, I will use memcpy and some tricks. Once I got something usable I will post it here, it might be useful to you. The goal is to perform one oldschool demoscene effect: bitmap distortion. So the distortion will be applied not only to a sprite, but also to the pixel that are on the left and on the right.
Hello, here is a way to draw something on the screen from an array. This snippet will draw a small TV on the screen.
-- hexa color. 1 hexa char = 1 pixel. tv={"00000d000d", "000000d0d", "0000000d", "44444444444", "40000000444", "40330330444", "40000000464", "40033300444", "40000000464", "44444444444"} -- position x, pos. y, transparent color to ignore, array to draw function drawArray(x,y,c,a) for i=1,#a do for j=1,#a[i] do cc=tonumber(string.sub(a[i],j,j),16) if(cc~=c) then pix(x+j-1,y+i-1,cc) end --ifcc end --forj end --fori end --drawArray drawArray(120,60,0,tv)
Here's another way to do the same thing which *might* be quicker as it avoids the string and number conversion functions (I haven't tested it!) It also means the data and its descriptors (transparent colour and 'width' are self contained and therefore easier to keep clean/debug) and the numbers are decimals rather than hex. You could even put the drawing function in the table and have it draw itself.
-- drawarray local test={data={2,2,2,2,2,2,2,2, 2,0,0,0,0,0,0,2, 2,0,0,0,0,0,0,2, 2,0,0,4,4,0,0,2, 2,0,0,4,4,0,0,2, 2,0,0,0,0,0,0,2, 2,0,0,0,0,0,0,2, 2,2,2,2,2,2,2,2}, trans=0, width=8 } --x,y,table function drawArray(x,y,a) local startx=x for i=1,#a.data do local cc=a.data[i] if(cc~=a.trans) then pix(x,y,cc) end x=x+1 if (i)%a.width==0 then y=y+1 x=startx end end
end function TIC() cls() drawArray(120,60,test) end
Hope that's of interest!