In this tutorial, you will learn how to code a rainbow in Minecraft Education Edition with Code Builder
Part 1: Setting up the world
For this tutorial, you will need to create a 'super flat world'!
STEP 1. Launch Minecraft Education Edition and create a new 'super flat' world from 'templates'.
STEP 2. Press 'Play' to launch your world.
Part 2: Writing the code
STEP 1. Press the letter 'c' on your keyboard to launch the code window.
STEP 2. If prompted, from the code connection options, click on 'Microsoft MakeCode'.
STEP 3. Create a new project and call it 'Rainbow'.
STEP 4. Switch to 'JavaScript'.
STEP 5. Type in the following code exactly or, alternatively, download the code from the resources section (below).
let y: number = 0;
player.onChat("rainbow", function (rainbow_radius) { builder.teleportTo(player.position()) builder.move(SixDirection.Forward, 50) builder.setOrigin() for (let x = Math.round((0 - (0.9 * rainbow_radius))); x <= Math.round((0.9 * rainbow_radius)); x++) { builder.teleportToOrigin() y = Math.round(Math.sqrt((rainbow_radius * rainbow_radius) - (x * x))) builder.move(SixDirection.Up, y) builder.move(SixDirection.Right, (x >> 0)) for (let colourIndex = 0; colourIndex <= colours.length - 1; colourIndex++) { builder.place(blocks.blockWithData(blocks.block(Block.Wool), colours[colourIndex])) builder.move(SixDirection.Up, 1) } } }) let colours: number[] = [10, 11, 3, 5, 4, 1, 14]; |
Your finished solution should look like this:
Important: At this point, DO NOT switch back to the block editor view as this will modify parts of your code and stop it from working!
STEP 6. Press the 'play' button to run your code.
STEP 7. Press 't' to open up the chat menu. Type the following (followed by the Enter key) to run your code.
Note: The number 30 after the rainbow command tells the program the radius for the rainbow. Try changing the radius value to increase or decrease the size of the rainbow.
Resources:
Rainbow solution for Make Code.
|
|
Part 3: Exploring the code
Let's explore some of the code.
builder.teleportTo(player.position())
builder.move(SixDirection.Forward, 50)
The first line in the code above teleports the the builder to the player's location. The second line moves the builder in relation to the players position (Direction and distance).
builder.teleportTo(player.position())
builder.move(SixDirection.Forward, 50)
The first line in the code above teleports the the builder to the player's location. The second line moves the builder in relation to the players position (Direction and distance).
Challenge:
- Change the position of where the builder is placed in relation to the player.
let colours: number[] = [10, 11, 3, 5, 4, 1, 14];
This line of code denotes a list (or Array). Lists are useful for storing lots of related data. In this case, our list is being used to store the wool IDs in minecraft which represent each of the colours in our rainbow. These are:
10 = Purple
11 = Blue
3 = Light Blue
5 = Green
4 = Yellow
1 = Orange
14 = Red
This line of code denotes a list (or Array). Lists are useful for storing lots of related data. In this case, our list is being used to store the wool IDs in minecraft which represent each of the colours in our rainbow. These are:
10 = Purple
11 = Blue
3 = Light Blue
5 = Green
4 = Yellow
1 = Orange
14 = Red
Challenge:
- Change the values in the list to see what other combination of colours you can make.
- Who said that a rainbow has to have just 7 colours? Modify your code so that your rainbow contains more than 7 colours.
You may also be interested in:
This work is not affiliated in any way with Mojang AB. Minecraft is a trademark of Mojang AB. The Minecraft Name, the Minecraft Brand and the Minecraft Assets are all property of Mojang AB or their respectful owner. This work adheres to the terms set out by Mojang AB at https://www.minecraft.net/terms