This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
jay5476's profile picture

Change Paintutils To Use Drawpixel Instead Of Drawpixelinternal

Started by jay5476, 02 September 2013 - 04:37 AM
jay5476 #1
Posted 02 September 2013 - 06:37 AM
I think this is reasonable
as it hard to map the background of the screen with drawLine drawImage
etc. because of this, using drawPixel will allow these drawings to be mapped by users.
also this is reasonable because drawPixel is not much different from drawPixelInternal
exept for the color check( yes this is done at the top of the other functions but still )

please consider this
Zudo #2
Posted 02 September 2013 - 01:13 PM
I don't understand what you mean :blink:/>
theoriginalbit #3
Posted 02 September 2013 - 01:49 PM
I don't understand what you mean :blink:/>
I think he might be referring to this


function drawImage( tImage, xPos, yPos )
  for y=1,#tImage do
	local tLine = tImage[y]
	for x=1,#tLine do
	  if tLine[x] > 0 then
		term.setBackgroundColor( tLine[x] )
		drawPixelInternal( x + xPos - 1, y + yPos - 1 )
	  end
	end
  end
end

can be changed to this


function drawImage( tImage, xPos, yPos )
  for y=1,#tImage do
	local tLine = tImage[y]
	for x=1,#tLine do
	  if tLine[x] > 0 then
		drawPixel( x + xPos - 1, y + yPos - 1, tLine[x] )
	  end
	end
  end
end

As this is the only place that using drawPixel over draw pixel internal would make sense, although a pointless change it would be, I would much rather they make a change that actually makes a difference over someone just being picky about lines of code…

EDIT: Oh and not to mention making this change adds yet another function onto the function call stack.
Edited on 02 September 2013 - 12:00 PM
jay5476 #4
Posted 10 September 2013 - 03:24 AM
wouldn't that mean that it wouldn't error after drawing 256 pixels
theoriginalbit #5
Posted 10 September 2013 - 05:16 AM
wouldn't that mean that it wouldn't error after drawing 256 pixels
I don't think you understand how a call stack works. When a function is invoked it gets pushed onto the stack, when the function completes it gets popped from the stack.
As there is no recursive call, this means that paintutils adds 1-3 function calls onto the call stack, 1 when it's in the loop (which has been added when the person invoked paintutils), the second to DrawPixelInternal, and the 3rd when it's calling the functions in there. As such this means that it is capable of drawing the max size image 13,284 (max size monitor, text scale 0.5, is 164*81 pixels….. and people say we need more pixels, psht)… If we were to make the change of having it use DrawPixel instead of DrawPixelInternal it would mean that the call stack would have 1-4 calls.

If paintutils actually had this problem it wouldn't even be able to draw an image that fills the default terminal screen which is 969 pixels (51*19). Also if you're getting stack overflow when you're invoking paintutils the problem is in your code, you should not be getting anywhere near the call stack limit, you need to restructure and reassess your code!
Cranium #6
Posted 10 September 2013 - 10:47 AM
You can edit the funtion to suit your needs as much as you want. We're not stopping you. Locked for 'enhancements' that you can already do yourself.