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

Paint Utils Extra: The Essential API extention for your Paintutils needs!

Started by LDDestroier, 28 October 2017 - 04:22 PM
LDDestroier #1
Posted 28 October 2017 - 06:22 PM
Paintutils sucks, but now it doesn't! Not with my brand new functions to spice up the Paintutils API!

Flip images, stretch images, merge images, you name it!!


pastebin get 7XAmsAbX pue

Here's a demo. Demonstrates stretching, the blit-based drawImage, and using merge to remove all flickering.

pastebin get weLUU423 puedemo

You can use this by copying it into the beginning of your code. os.loadAPI isn't recommended.

Here are the functions:
Spoiler
paintutils.drawImageBlit(image, x, y)
Replicates the functions of drawImage, but sacrifices transparency for speed.


paintutils.drawImageBlitCenter(image,x,y,object)
Same as drawImageBlit, but draws centered around X and Y. If no X or Y, then half of the screen width and height respectively are used. Either terminal size, or object size optionally.


paintutils.drawImageCenter(image,x,y,object)
Same as drawImageBlitCenter, but using the normal paintutils.drawImage function.


paintutils.merge({
	image1,
	x,
	y
}, {
	image2,
	x,
	y
}, ...)
Merges an arbitrary amount of images formatted like {image,x,y} into the same image. The first argument will be layered upon the second, second onto the third, and so forth.


flippedImage = paintutils.flipX(image)
and
flippedImage =paintutils.flipY(image)
Returns image, but flipped horizontally or vertically respectively. I don't know why this function wasn't default.


fullscreenRectangle = paintutils.fullscreen(color,object)
Returns an image of a rectangle of a flat color, and the size of the terminal screen. You can also use 'object' to make it output a rectangle the size of something like a monitor or a window.


newImage =paintutils.grayOut(image)
Returns the image in as best grayscale as I could get in computercraft.


newImage = paintutils.lighten(image)
Returns the image with colors lightened up. Useful for transitions.


newImage = paintutils.darken(image)
Returns the image with colors darkened up. Useful for transitions.


x, y = paintutils.getSize(image)
Returns the X and Y sizes of an image.


newImage = paintutils.stretchImage(image, xsize, ysize)
Stretches the image to xsize,ysize. Supports negative sizing and flipping.


stringImage = paintutils.unloadImage(image)
Converts a tabular NFP image format back to a string format that can be used with paintutils.loadImage() again, if saved to a file.


newImage = paintutils.autocrop(image)
Cuts out all blank space above and to the left of an image. Save some trees.


paintutils.centerWithBlankSpace(image,x,y,object)
Returns the same image, but with blank space added to make the image centered.

One possible way to reduce flickering would be to merge every image into a buffer, then draw the buffer. I'll try to change all my billboards to use this!
Edited on 13 December 2017 - 02:05 AM
Dave-ee Jones #2
Posted 30 October 2017 - 03:27 AM
Was gonna say, a buffer would be good practise here, but then saw you mention it at the bottom of the page. Would be wise to do so with the fullscreen rectangle as well.

May I ask, what is the point of the fullscreen rectangle function? Why not use drawRectangle with terminal width and height arguments? That way you could pass them to the rectangle function far easier as well - but, again, you wouldn't need to because you already know the width/height of the terminal, having created the buffer with those dimensions in the first place.

I agree with you on the flip functions. Those should probably have been added in, but I guess it's another one of those 'they can program it themselves, I don't need to' moments that Dan and the others had. Frustrating. To be fair, I probably would've thought a similar way. :P/>
LDDestroier #3
Posted 31 October 2017 - 11:41 AM
May I ask, what is the point of the fullscreen rectangle function? Why not use drawRectangle with terminal width and height arguments? That way you could pass them to the rectangle function far easier as well - but, again, you wouldn't need to because you already know the width/height of the terminal, having created the buffer with those dimensions in the first place.

To my knowledge, the drawRectangle function draws a rectangle. My rectangle function outputs the rectangle as a serialized function, so you can merge other pictures upon it and then avoid the problem of having a black screen for like, one frame.

I agree with you on the flip functions. Those should probably have been added in, but I guess it's another one of those 'they can program it themselves, I don't need to' moments that Dan and the others had. Frustrating. To be fair, I probably would've thought a similar way. :P/>

Feh.
LDDestroier #4
Posted 07 December 2017 - 10:05 PM
Update! A plethora quanta of new functions to play with.
  • paintutils.stretchImage(image,xsize,ysize) Stretch an image to be a specific size!
  • paintutils.merge({image1,x,y}, {image2,x,y}, …) Merge two or more images together into one single image!
  • paintutils.grayOut(image) Turns a picture into grayscale as best I could.
  • paintutils.lighten(image) Makes every color in a picture a lighter tone. Useful for transitions.
  • paintutils.darken(image) Makes every color in a picture a darker tone. Useful for transitions.
  • paintutils.getSize(image) Returns the X and Y sizes of the image.
  • paintutils.unloadImage(image) Returns the string formatted NFP that you would actually save to a file!
  • paintutils.autocrop(image) Removes all blank space to the left and below the image! Save some trees.
  • paintutils.drawImageBlitCenter(image,x,y,object) Draws an image centered to X and Y. If not X or Y, then the terminal's (or object's, optionally,) center point.
  • paintutils.drawImageCenter(image,x,y,object) Same as above, but with the regular drawImage function.
  • paintutils.centerWithBlankSpace(image,x,y,object) Returns the same image, but with blank space added to make the image centered.
I also found out that the optimized version of paintutils.drawImage() doesn't allow transparency in the images, so:
  • Renamed the new paintutils.drawImage() with paintutils.drawImageBlit()
If you're looking for a simple graphical enhancer API, look no further than Paintutils Extra!
BUY IT NOW
Edited on 15 January 2018 - 03:20 AM