Log In  


Cart #stripe_print-0 | 2022-07-14 | Code ▽ | Embed ▽ | License: CC4-BY-NC-SA
11

Hi All,

This is just a quick util method for printing in multiple colours per line of pixel. Its probably been done many time before but this is just my take on it.

The function in question is 41 tokens:

function stripe(txt, x, y, cols)
	local w = print(txt,x,y,0)
	for i=1,#cols do
		clip(x,y+i-1,w,1)
		print(txt,x,y,cols[i])
	end
end

cols is an array of colours which should be at least as large as the height of the text being printed. For normal text this will be 5 values, but if split into multiple lines or you print bigger text then you need more values.

In the cart I've demonstrated some uses of it including a scrolling table that could be used as an effect.

11


Superb work here, @SquidLight ! I can definitely see the animated SCROLL working in future carts. Gold star effort.

Here is your STRIPE function even smaller:

function stripe(t,x,y,c)for i=0,#c do clip(0,y+i,128,y+i)print(t,x,y,c[i+1])end end

83-characters compared to the original 120-characters.

The real gem you have here is THIS:

add(scroll, deli(scroll,1))

What an interesting and compact way to rotate an array !


@dw817 thanks for this. I see you've opted to clip the whole line which makes sense for optimisation purposes.

The scrolling I didn't really pay too much attention to. It just seemed to rotate an array you needed an object ref since deli did both provide an object ref and removed from the table I thought it made sense.



[Please log in to post a comment]