The MineCraft world can sometimes get a bit boring, so why not make it prettier by adding a beautiful rainbow?
The challenge is to create some code to build a rainbow in the MineCraft world.
Step 1 – a quick maths lesson
What we see as rainbows are actually arcs of a circle and sometimes you can actually see a full circle rainbow when flying in a plane. So if we want to create a rainbow we first need to work out how to create a circle in the MineCraft world. We can do this simply by add a block of wool at each of the 360 degree points on the circumference of a circle.
But how do we find out where to put each of these points? Well we use some maths!
Here are the equations we need to calculate each X and Y.
PointX = OriginX + radius of circle * cos(angle * Pi / 180)
PointY= OriginY + radius of circle * sin(angle * Pi / 180 )
Step 2 – Calculating the x coordinate
Using the formula above we first need to calculate the x coordinate of the point.
Step 3 – Calculate the y coordinate
Can you calculate the Y-coordinate by adapting the above code above and looking at step 1? Have a go!
Step 4 – Add a block of wool
Step 5 – Repeat for all 360 degrees
Add all the code above into a for loop or while loop and repeat for every degree in the circle ( or just 180 degrees if you like!)
Step 6 – Repeat for all 7 colours of the rainbow
The code above is great but it just draws a circle, it doesn’t do all the colours of a rainbow. In order to do this we need to use a list of colours and to take it in turn to draw each colour of the rainbow, increasing the radius of the circle by 1 each time so that each colour doesn’t overwrite the previous colour.
- Add a user interface to your code so that user can choose the size and position of the rainbow.
- Create a rainbow road instead of a normal rainbow (see the YouTube video)
- Adapt your code so that the rainbow follows the player around the MineCraft world.
- Create a double rainbow (see Wikipedia for what one should look like!
Don’t have time to work out your own solution? Here’s the code for the solution.