Low-resolution Procedural Textures With Minecraft Blocks

The techniques mathematicians and engineers use to approximate or simulate natural processes are fascinating. Fascinating because they increase our understanding of how the world works around us, and because they can often be used to solve seemingly unrelated problems. For example consider particle swarms which can be used to simulate flocks of birds or insects, but also can be used to quickly and iteratively optimize problems. L-systems can be used to simulate the growth of plants, but also can be used to create fractals not found in the botanical world.

Another popular technique we use to simulate nature is adding noise to synthetic textures in video games to increase the realism of objects. For example, the texture below could be a closeup of a grain of wood or marbling from a rock:

75 x 40 Rectangle Texture

75 x 40 block rectangle texture

To generate a texture like this we start with a striped texture like a barber’s pole and than add turbulence, which is just another way of saying “Hey you, add a couple different layers of variously zoomed noise to the color value of each block!” Now when I say noise I am referring to a method of generating random values between 0 and 1 that takes the x and y coordinates of blocks as input. Of course some random values are better than others for generating textures.

Low zoom factor makes for a less smooth texture.

Low zoom factor makes for a less smooth texture.

This is a 50 x 50 block shot of a texture which was generated using a method called Simplex noise. Simplex noise is a special type of noise first developed by Ken Perlin (of Perlin noise fame). We are using Simplex noise here because it is fast, the Bukkit API has already implemented it for us, and because it has the special property of creating visual artifacts of about the same size which lets us control it to for interesting results.

The results captured here are interesting, but since they were created in Minecraft there are some limitations–namely, we have a severely limited palette of colors. I choose to only use wool since the colors are solid and their internal IDs are contiguous; however, you could probably create some neat textures using all available Minecraft block types.

Wool Block IDs

Wool Block IDs

In the pics above I only used 4 colors of wool: white, light gray, gray, and black. If you use all 16 wool colors you get textures like the one below:

Colored marble

Colored marble

Yet another colored marble

Yet another colored marble

The code I used to create these textures is below. Copy and drop the file into your js-plugins folder to install it. All of the turbulence parameters should be tinkered with to experiment with the various textures you can make. Tinkering with the make_discrete function to change the palette is also fun.

If you want to learn more about Perlin and Simplex noise I recommend checking out Ken Perlin’s site. Sign up for email updates to hear about more ScriptCraft shenanigans!

A Small Portion Of 10-Disked Hanoi

Visualizing The Towers Of Hanoi In Minecraft

In this post I will talk about the Towers Of Hanoi puzzle and create a few neat in-game visualizations for various puzzle sizes using ScriptCraft.

Towers Of Hanoi

The Towers Of Hanoi is a math puzzle that involves usually three poles and disks. The puzzle starts with all the disks stacked on the left-most pole with the largest disk on the bottom and the smallest on top. For example, here is the initial configuration for a 3 disk puzzle….in the snow:

Initial Configuration With 3 Disks

Initial Configuration With 3 Disks

The object of the puzzle is to move all the disks from the left-most pole to the right-most while following these three rules:

  1. You can only move one disk at a time.
  2. You can only move the very top disk from a pole.
  3. You can only stack a smaller disk onto a bigger one.
Sketch It Out By Hand

Now that you have the initial configuration and the rules, grab a piece of scratch paper and see if you can sketch all the moves needed to complete a three disk puzzle. With three disks it will not take you long to draw them all out.  If you get stuck check out the Towers Of Hanoi Wikipedia page for help.

Tracking & Visualizing Moves

Now that you are probably tired of drawing out moves manually, lets devise a recursive algorithm to solve this puzzle for an any number of disks.  In fact, the Towers Of Hanoi is one of those fun and almost magical problems that if you characterize it the right way you can almost word for word translate it into a programming language.  To solve a puzzle with disks and three poles we have to:

  1. Move all the disks but the bottom disk (n – 1 disks) from the left pole to the middle pole.
  2. Move the bottom disk to the right-most pole.
  3. Move all the disks from the middle pole (n – 1 disks) to the right-most pole.
Javascript Translation

Running the above with ScriptCraft will cause the moves to be printed out.  If you want to see how I rendered the move visualizations with colored wool checkout my Towers Of Hanoi Gist which you can drop into your ScriptCraft js-plugins directory and start creating move visualizations.

Comparing Puzzles Of Different Disk Size

Placing together visualizations from different disk-sized puzzles yields the most interesting results.  Here is a picture showing Towers Of Hanoi moves starting on the left with 3 disks and ending with the moves required to solve an 8 disk puzzle on the right:

Moves From Disks 3-8 Compared

Moves From Disks 3-8 Compared

As you can see the number of moves required to solve the puzzle for every additional disk grows by leaps and bounds!  Specifically for n disks the fewest moves required to solve a puzzle is 2^n - 1 moves.

  • So if you have a puzzle with 10 discs it would take 2^{10} - 1 = 1023 moves.  
  • A puzzle with 30 disks would take 2^{30} - 1 = 1,073,741,823 moves!

Is there a topic you would like to see covered here?  I want to hear your input. Send me an email with any suggestions for future posts.  If you liked this post, then you might also like Visualizing Sorting Algorithms In Minecraft.

Three Sorting Algorithms

Visualizing Sorting Algorithms In Minecraft

In this post I will use ScriptCraft to create static visualizations in Minecraft for a couple well-known sorting algorithms.

Sorting Algorithms

Sorting algorithms are a popular branch of algorithms. For young computer scientists sorting algorithms are the vehicle for learning important concepts in the field such as Big O notation and time-space tradeoffs. For older computer scientists, this family of algorithms are still interesting enough to devote time for research and analysis (e.g. Library Sort). And yet despite the ubiquity of these algorithms I doubt most of us have developed strong intuitions on how they work, or have simply forgotten–myself included.

Static Visualizations

A few years ago, Aldo Cortesi, a New Zealand coder, made a case for static over animated visualizations as the tool of choice for understanding the flow of sorting algorithms.  His argument is that these animated visualizations are initially unclear and take longer to understand. We have trouble with these animations because humans estimate distances in space well, but are generally poor at estimating distances in time, so why when trying to teach potentially confusing material would we play to our weakness? Static visualizations play to our strength.

Below there are three sorting algorithm visualizations along with a few notes. Look at each picture from right to left to follow the flow of each algorithm. If you hadn’t already guessed from the pictures we are sorting colored wool and using Minecraft’s internal IDs for each block. A list of all block IDs can be found at MinecraftInfo.

Bubblesort Meets Colored Wool

Bubblesort Meets Colored Wool

A simple sorting algorithm. If your list is small and your data mostly sorted, then there is certainly nothing wrong with this little algorithm.


  • When a line of wool is swapped with another the most it moves is by one line.
  • Towards the end of the rectangle (towards the left) there is a stretch where no wool is swapped and yet the algorithm is still “sorting”.
Shell Sort
Shell Sort Meets Colored Wool

Shell Sort Meets Colored Wool

Discovered by Donald Shell in ’59. Compare the picture above with that of Bubblesort and you should notice:

  • Swaps between rows can move wool more than one line (unlike poor old Bubblesort)!
  • The visualization has a shorter width than that of Bubblesort. This is due to the fact that Shell Sort took fewer passes sorting the same data.
Quicksort Meets Colored Wool

Quicksort Meets Colored Wool

Discovered by Tony Hoare in ’60. Quicksort is popular because it is usually very fast in practice.


  • There is a pattern where first wool swaps are made from farther away, but then are followed by swaps with closer lines of wool. This is because Quicksort takes a bigger uglier problem (like sorting a lot of wool) and divides into smaller similar problems (sorting just a little bit of wool). The smaller problems are easier to solve and can be recombined to create a solution for the original big ugly problem.
  • The orange wool does not appear at the very top like in the previous sorts.  (Don’t worry it’s there, but for some reason Minecraft doesn’t always show the blocks I render with ScriptCraft).
More Visualizations

After your done reading this post I sugget you visit Cortesi’s sortvis site to see more sorting algorithm visualizations. If you are interested in creating your own sorting algorithm visualizations in Minecraft you can find the JavaScript code I used as a Gist. You’ll need ScriptCraft installed which is a little painful, but once installed you can do plenty of other neat things like creating L-system fractals.


Is there a topic you would like to see covered here?  I want to hear your input. Send me an email with any suggestions for future posts.