Sunday, October 12, 2014

MCPI-Scratch: Lines and Circles

The initial release of MCPI-Scratch came with support for the basic operations to move a player around and to set blocks. But it takes a lot of work to create interesting shapes using those primitives - especially for kids that are using Scratch as their introduction to programming. So we thought it would be useful to create a couple of new operations to make it easier to create interesting shapes.

Lines and Circles

Its easy to use loops to create lines with the existing primitives, but doing that results in lines that simpy align with the x,z axes in minecraft (or go at 45 degrees). Creating a line between any two points is a bit harder so we created an operation to make it easier.

The process of taking a shape (such as a line or circle) and converting it to a set of points on a grid (like minecraft) is called Rasterisation. There are some well-known algorithms for performing this in computer graphics - Bresenham's Line Algorithm and the Midpoint Circle Algorithm (or Bresenham's Circle Algorithm).

There are plenty of implementations of these available online in a variety of languages so it was quite simple to find them (line, circle) and adapt them to MCPI-Scratch.


setLine allows you to draw a line between any two x,z coordinates at a given height (y coord).

There is a sample Scratch script (lines.sb2) that adapts an online example to draw lines along the radius of a circle at various degree increments


Similarly, setCircle draw a circle with a given center point (x,z) at a given height (y).

The provided example (circleWork.sb2) draws a dome by using a loop to draw decreasing radius circles at increasing heights

We've also used it to dig an ampitheatre by inverting the dome and setting the blockType to Air


Post a Comment