Python: Auto Rainbow

This cool little program designed by ‘500 Internal Server Error‘, automatically builds a rainbow in your MCPI world, upon loading the python file.

—————————————————————————————————-

The code is as follows:

import mcpi.minecraft as minecraft
import mcpi.block as block
from math import *
colors = [14, 1, 4, 5, 3, 11, 10]
mc = minecraft.Minecraft.create()
  height = 60
mc.setBlocks(-64,0,0,64,height + len(colors),0,0)
  for x in range(0, 128):
  for colourindex in range(0, len(colors)):
  y = sin((x / 128.0) * pi) * height + colourindex
  mc.setBlock(x - 64, int(y), 0, block.WOOL.id, colors[len(colors) - 1 - colourindex])

—————————————————————————————————-

The original thread where the program was shared can be found here.

To run the program, open up ‘LeafPad‘, copy this code into it and save it in /mcpi/api/python as a .py file. Save it as rainbow.py. Then, once you have a MCPI world loaded up, open up ‘Terminal‘ and navigate to where you saved the file using cd and type python rainbow.py.

Advertisements

Posted on February 17, 2013, in Program, Python and tagged , , , , , , , . Bookmark the permalink. Leave a comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: