Log In  
Follow
howeverice

Usage

This should be used for simple cases like basic pixel noise in small areas or in small amounts.

What this function does

It gives you a higher level wrapper for PICO-8s 4-bit framebuffer (0x6000-0x7fff) (lower 4-bits: left pixel, upper 4-bits: right pixel), and does some bitwise math and multiplication to put a single pixel on screen.

Code Snippet

NOTE: This function should be only used sparingly, it's expensive to use and not fully optimized (e.g. batching and minimizing the code to only required calculations) (using it heavily can cause severe lag).

function putpixel(x,y,col)
	-- floor x & y to stop rounding errors in pixel position calculations
	x, y = flr(x), flr(y)

	-- prevent pixel from wrapping around the screen horizontally 
	if x > 127 or x < 0 then return end

	-- get 1 dimensional bit offset, multiplying y by the screen width to iterate by line
	local pixel_pos = x + (y*128)

	-- divide the pixel position in half to fit into the 4-bit offset to a 2 pixel pair in memory

[ [size=16][color=#ffaabb] [ Continue Reading.. ] [/color][/size] ](/bbs/?pid=198894#p)
2 comments