๐ŸŸจ Create a 3-Color Carpet in Minecraft with VisualModder

Download the XML code here:

In this tutorial, you will learn how to create a giant colorful carpet automatically using code. The carpet will have three colors and a cool pattern!


๐ŸŽฏ What This Program Builds

  • A large square carpet on the ground
  • Three colors: white, black, and yellow
  • A repeating pattern of shrinking squares

๐Ÿง  The Code


๐Ÿงฉ Step 1 โ€” Create a Variable

What is a variable?

  • A variable is like a box that stores numbers.
  • This one is called counter.
  • It will control how big each square is.

๐Ÿง  Step 2 โ€” Create the Function

  • This creates a function named carpet3colors.
  • When you run it, the carpet will be built automatically.

๐Ÿ” Step 3 โ€” Draw White Squares

What is happening?

  • The program draws squares that get smaller each time.
  • from 20 to 2 by 6 means:
    • Start at size 20
    • Decrease by 6 each time
    • Stop at size 2

So the game draws big โ†’ medium โ†’ small white squares.


โฌ› Step 4 โ€” Add Black Squares

  • This draws black squares on top of the white ones.
  • Because the sizes are slightly different, it creates a pattern.

๐ŸŸก Step 5 โ€” Add Yellow Squares

  • Now yellow squares are added.
  • These are the biggest squares.
  • All three colors together create a layered carpet.

๐ŸŽจ Why the Pattern Looks Cool

  • Each color starts at a different size.
  • The squares shrink as they are drawn.
  • This makes a repeating border pattern.

It looks like a fancy floor or a magic rug! โœจ


๐ŸŽฎ What Happens When You Run It

  1. Large yellow squares appear
  2. Black squares appear inside
  3. White squares appear inside those
  4. The pattern repeats smaller and smaller

Result: A beautiful 3-color carpet!


๐ŸŒŸ Fun Challenges

  • Change the colors to your favorites
  • Try making a rainbow carpet ๐ŸŒˆ
  • Use it as the floor of a palace or temple

๐ŸŽ‰ Great job! You used coding to create art!

Here is the Python code that creates it:

# Variables
counter = None

def carpet3colors():
  global counter
  for counter in range(20, 1, -6):
    vm.createRectangle(counter, counter, False, Block.WHITE_CONCRETE);
  for counter in range(22, 1, -6):
    vm.createRectangle(counter, counter, False, Block.BLACK_CONCRETE);
  for counter in range(24, 1, -6):
    vm.createRectangle(counter, counter, False, Block.YELLOW_CONCRETE);
Visualmodder.org Learn coding with Minecraft
Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.