Coder Social home page Coder Social logo

computercraft-stuff's Introduction

ComputerCraft NFP Image Converter

A Python program to convert images into NFP images for display on ComputerCraft monitors inside of Minecraft. Inspired by this program.

Feel free to contact us with questions, suggestions, or to request help.

The nfp.py module can convert between standard image formats and NFP. When converting from image to NFP, it uses Pillow to quantize the image, reducing its color palette to the 16 available ComputerCraft colors.

convert_nfp.py is a simple command-line utilty that uses this module, made because why not?

NFP format

"NFP" is a simple text-based 16-color image format used by ComputerCraft's paint program and the paintutils API. Each pixel is represented by a one-digit hex value from 0-f (decimal 0-15) corresponding to an index into the 16-color ComputerCraft color palette. Each row is terminated by a newline.

A black/white 4x4 checkerboard NFP image looks like this:

f0f0
0f0f
f0f0
0f0f

Usage and Example

Converting from image -> NFP:

convert_nfp.py image.png

(Images are automatically resized to 164x81, the maximum resolution for 8 by 6 (max size) scale 0.5 ComputerCraft monitors, before conversion, unless the --skip-resize, --resize-width, or --resize-height arguments are specified.)

Converting from NFP -> PNG:

convert_nfp.py image.nfp

Converting from NFP -> JPEG:

convert_nfp.py image.nfp --format=JPEG

See convert_nfp.py -h for full usage info. See the Pillow docs for supported conversion formats.

After converting an image to NFP, you can upload it to pastebin, and use paintutils.drawImage() to fetch and display it in-game. Example program that downloads an NFP from pastebin (like this one) using the paste ID passed in as an argument and displays it on a connected monitor:

local args = {...}
local paste_id = args[1]
shell.run("delete image.nfp") --delete file if it already exists
shell.run("pastebin", "get", paste_id, "image.nfp") --fetch NFP image from pastebin at given paste_id
print("Drawing...")
local old_term = term.current()
local mon = peripheral.find("monitor") --find and attach to monitor
mon.setTextScale(0.5)
term.redirect(mon)
term.clear()
--draw image through paintutils
local image = paintutils.loadImage("image.nfp") 
paintutils.drawImage(image, 0, 0)
term.redirect(old_term)
print("Done")

This example program has been posted to pastebin, so you can just use the below to display an example image:

pastebin get MuZxYKrQ disp_nfp
disp_nfp yjXanZ0j

Python scripts were tested on Python 2.7, PIL/Pillow 1.1.7.

computercraft-stuff's People

Contributors

budak7273 avatar downrightnifty avatar frankiebinns avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.