How to Make 3D Shapes in Scratch – Draw Cubes, Pyramids & Cylinders Using Pen Extension

Published By Kodex Academy — Learn. Build. Innovate.
How to make 3D Shapes in Scratch - 3D Geometry with Code Pen Extension in Scratch Kodex Academy

Learn how to make stunning 3D shapes like cubes, pyramids, and cylinders in Scratch using the Pen Extension. A complete step-by-step Scratch programming guide from Kodex Academy.

Watch the full tutorial video here:
👉 How to Make 3D Shapes in Scratch – 3D Geometry with Code | Pen Extension in Scratch | Kodex Academy

Introduction – 3D Shapes in Scratch

Welcome to Kodex Academy’s Scratch Tutorial Series!
If you’ve ever wondered how to make 3D shapes in Scratch or create 3D geometry using code, you’re about to dive into a creative world of math, animation, and programming fun.

In this tutorial, we’ll explore:

  • How to use the Pen Extension in Scratch
  • How to draw 3D shapes like a Cube, Pyramid, and Cylinder
  • How to apply math (coordinates, sine, cosine) to simulate 3D depth
  • And finally, how to enhance your project with animations, controls, and colors

This project is perfect for beginners and intermediate learners interested in Scratch programming, geometry in Scratch, and creative coding.

Goal: Draw Cube, Pyramid, and Cylinder in Scratch using the Pen Extension, with full, detailed step-by-step code and explanations so a beginner can implement it.

Overview — what you’ll build and why

  • A Cube made from two offset squares + 4 connector lines (trigger key A)
  • A Pyramid (square base + 4 lines meeting at an apex) (trigger key B)
  • A Cylinder built from two ellipses and two vertical side lines (trigger key C)
  • All drawing is done with the Pen Extension (no sprite costumes) so code actually draws shapes on the stage.

This tutorial uses Scratch-style pseudo-blocks you can copy into Scratch block-by-block. I explain every block and why it’s used.

Scratch Code – 3D Shapes in Scratch

Prerequisites

Before we start, make sure you have:

  • A Scratch account at scratch.mit.edu
  • Basic understanding of Scratch coding blocks
  • Familiarity with x-y coordinates in Scratch

If you’re new to Scratch, check out the official Scratch Getting Started Guide.

Preparation (one-time)

  1. Open Scratch: https://scratch.mit.edu/create
  2. Delete default Cat sprite (right-click → delete).
  3. Add Pen extension (bottom-left “Extensions” → choose Pen).
  4. Create variables (for convenience): side, offsetX, offsetY, rx, ry, apexX, apexY, angle, depth, a, xpos, ypos — many are optional but useful when experimenting.

Global: Basic setup script (recommended)

Place this under Events → when green flag clicked. It sets defaults and clears the stage.

when green flag clicked
erase all
set pen size to 4
set pen color to [#00AA00]      // default color
set rotation style [all around v]
set [side v] to 100             // default square side length
set [offsetX v] to 20           // default back-square offset (cube)
set [offsetY v] to 20
set [rx v] to 60                // cylinder horizontal radius
set [ry v] to 20                // cylinder vertical radius
set [apexX v] to 0              // pyramid apex x
set [apexY v] to 80             // pyramid apex y (height)
set [angle v] to 0              // used in rotation examples
set [depth v] to 30             // used in rotation examples

Why: erase all clears previous drawings. set rotation style all around avoids left/right flips if we use direction or sprite rotation math. Variables let learners change dimensions easily.

Utility: Create custom blocks first

Two reusable custom blocks will make scripts cleaner:

1) Draw Square

draw square (x) (y) (side) (dir)

Purpose: draw a square given top-left (or chosen corner) coordinates, side length and direction.

Define Block:

define draw square (x) (y) (side) (dir)
pen up
go to x: (x) y: (y)
point in direction (dir)       // e.g., 90 = point right
pen down
repeat 4
  move (side) steps
  turn clockwise 90 degrees
end
pen up

Notes:

  • Using go to x:y centers or positions the square precisely.
  • dir lets you control orientation (90 = draw to the right first).
  • Keep pen up before traveling, pen down during actual drawing.

2) Draw Ellipse

draw ellipse (cx) (cy) (rx) (ry)

Purpose: draw an ellipse centered at (cx,cy) with radii rx (x-axis) and ry (y-axis). This uses sin() and cos() — Scratch uses degrees.

Define Block:

define draw ellipse (cx) (cy) (rx) (ry)
pen up
set [a v] to 0
repeat 360
  set [xpos v] to ((cx) + ((rx) * (cos (a))))
  set [ypos v] to ((cy) + ((ry) * (sin (a))))
  go to x: (xpos) y: (ypos)
  pen down
  change [a v] by 1
end
pen up

Important math notes:

  • x = cx + rx * cos(angle)
  • y = cy + ry * sin(angle)
  • a loops from 0 → 359 (degrees). In Scratch the cos and sin blocks expect degrees.
  • Keep pen down while iterating through points so the ellipse draws smoothly without gaps.

3) CUBE — step-by-step (trigger: A key)

Concept recap: Draw front square + back square offset by (offsetX, offsetY), then connect corresponding corners.

Event script

when [A v] key pressed
erase all
set pen size to 4
set pen color to [#00FF00]

set [side v] to (100)         // can be changed
set [offsetX v] to (20)
set [offsetY v] to (20)

// front square centered at 0,0 => start at -side/2, -side/2
set [startX v] to ((- (side) / 2))
set [startY v] to ((- (side) / 2))
draw square (startX) (startY) (side) (90)

// back square (offset for depth)
set [backX v] to ((startX) + (offsetX))
set [backY v] to ((startY) + (offsetY))
draw square (backX) (backY) (side) (90)

// connect corners
// 1) front bottom-left -> back bottom-left
go to x: (startX) y: (startY)
pen down
go to x: (backX) y: (backY)
pen up

// 2) front bottom-right -> back bottom-right
go to x: ((startX) + (side)) y: (startY)
pen down
go to x: ((backX) + (side)) y: (backY)
pen up

// 3) front top-right -> back top-right
go to x: ((startX) + (side)) y: ((startY) + (side))
pen down
go to x: ((backX) + (side)) y: ((backY) + (side))
pen up

// 4) front top-left -> back top-left
go to x: (startX) y: ((startY) + (side))
pen down
go to x: (backX) y: ((backY) + (side))
pen up

Detailed explanation — each chunk

  • Positioning: To center the square at origin, start at (-side/2, -side/2) so the square occupies [-side/2 .. +side/2] in both axes. That makes scaling and centering easier.
  • Offset second square: offsetX and offsetY simulate depth — they must be the same relative values for all four corners to maintain shape alignment.
  • Connect corners: The connector lines must map corresponding corners in same order. If you reorder, the cube will look broken.

Tuning tips

  • Increase offsetX to make the cube look more “deep”.
  • Try negative offsetY to move the back square downward instead of upward.
  • Change pen size and color for visual emphasis.

4) PYRAMID — step-by-step (trigger: B key)

Concept recap: Draw square base, then connect each of the four base corners to a common apex (apexX, apexY).

Event script

when [B v] key pressed
erase all
set pen size to 4
set pen color to [#FFD700]    // base color

set [side v] to 100
set [startX v] to ((- (side) / 2))
set [startY v] to ((- (side) / 2))
draw square (startX) (startY) (side) (90)

// apex point
set [apexX v] to 0
set [apexY v] to 80
set pen color to [#FF4500]    // apex-edge color

// bottom-left to apex
go to x: (startX) y: (startY)
pen down
go to x: (apexX) y: (apexY)
pen up

// bottom-right to apex
go to x: ((startX) + (side)) y: (startY)
pen down
go to x: (apexX) y: (apexY)
pen up

// top-right to apex
go to x: ((startX) + (side)) y: ((startY) + (side))
pen down
go to x: (apexX) y: (apexY)
pen up

// top-left to apex
go to x: (startX) y: ((startY) + (side))
pen down
go to x: (apexX) y: (apexY)
pen up

Explanation & tweaks

  • apexY positive places apex above the base (since base sits centered near y=0). Increase apexY for a taller pyramid.
  • Changing apexX moves the apex left or right for perspective skewing.
  • If you want triangular faces filled in using pen, you can draw many close horizontal lines within each triangle (advanced technique).

5) CYLINDER — step-by-step (trigger: C key)

Concept recap: Draw two ellipses (top and bottom) with the custom draw ellipse block and connect them with vertical side lines at x = ±rx.

Event script

when [C v] key pressed
erase all
set pen size to 4
set pen color to [#FF0000]

set [rx v] to 60                 // horizontal radius
set [ry v] to 20                 // vertical radius for ellipses
set [centerX v] to 0
set [centerTopY v] to 60
set [centerBottomY v] to -60

// top ellipse
draw ellipse (centerX) (centerTopY) (rx) (ry)

// bottom ellipse
draw ellipse (centerX) (centerBottomY) (rx) (ry)

// connect left side
go to x: ((-rx)) y: (centerTopY)
pen down
go to x: ((-rx)) y: (centerBottomY)
pen up

// connect right side
go to x: (rx) y: (centerTopY)
pen down
go to x: (rx) y: (centerBottomY)
pen up

Important implementation details for ellipse

  • The repeat 360 loop increments a by 1 (degrees). Scratch cos() and sin() are degree-based — do not convert to radians.
  • If you see gaps, ensure pen down occurs before moving between successive go to points and that a increments by 1 each iteration.

Visual depth trick

To make the back (lower) ellipse appear as the “back edge”:

  • Draw the back ellipse first with a lighter color or lower brightness, then draw the front ellipse (same coordinates but different y if needed) on top with a darker/normal color. Alternatively, draw the bottom ellipse faint first, then the top ellipse fully.

Enhancements — add more interactivity & polish

I include full block sketches and explanations so you can paste into Scratch and extend.

A) Keyboard controls to move or scale the cube

Use variables for position centerX, centerY and update them on arrow keys:

when [right arrow] key pressed
change [centerX v] by 10

when [left arrow] key pressed
change [centerX v] by -10

when [up arrow] key pressed
change [centerY v] by 10

when [down arrow] key pressed
change [centerY v] by -10

when [z] key pressed
change [side v] by 10

when [x] key pressed
change [side v] by -10

Then change draw square calls to start at centerX - side/2 and centerY - side/2.

Why: Learners can interactively reposition and resize shapes to see how geometry responds.

B) Animated rotation illusion for the cube (no full 3D math, simple projection)

This draws the cube repeatedly while changing the offset using simple trigonometry:

when green flag clicked
set [angle v] to 0
forever
  erase all
  // compute a rotating offset
  set [offsetX v] to (round ((cos (angle)) * (depth)))
  set [offsetY v] to (round ((sin (angle)) * ((depth) / 2)))
  // draw cube using current offset values
  set [side v] to 100
  set [startX v] to (- (side) / 2)
  set [startY v] to (- (side) / 2)
  draw square (startX) (startY) (side) (90)
  set [backX v] to ((startX) + (offsetX))
  set [backY v] to ((startY) + (offsetY))
  draw square (backX) (backY) (side) (90)
  // connect corners (as earlier)
  change [angle v] by 3
  wait 0.05 seconds
end

Explanation: offsetX and offsetY circle around using cos/sin. This doesn’t perform real 3D rotation but gives an appealing illusion of motion.

C) Color cycling

Simple loop to animate pen color:

when green flag clicked
forever
  change pen color by 5
  wait 0.1 seconds
end

Why: Fun visual effect; Scratch’s change pen color cycles through the color wheel.

D) Broadcast modularization (good for projects / presentation)

Use broadcast messages to separate drawing tasks for clarity:

when [space] key pressed
erase all
broadcast [drawCube v]
wait 0.5 seconds
broadcast [drawPyramid v]
wait 0.5 seconds
broadcast [drawCylinder v]

when I receive [drawCube v]
... // cube code (call custom blocks)

when I receive [drawPyramid v]
... // pyramid code

when I receive [drawCylinder v]
... // cylinder code

Why: Improves maintainability and makes it easy to add sounds or transitions between draws.

Debugging checklist (common mistakes & fixes)

  • No ellipse drawn / gaps → make sure pen down is inside the repeat loop and a increments by 1 each iteration. Use repeat 360 + change a by 1.
  • Lines misplaced → check start coordinates; remember draw square expects a starting corner; using -side/2 centers the square.
  • Weird rotation or flipped drawing → ensure set rotation style [all around v] if using direction or rotation.
  • Slow performance → 360 steps for ellipses is fine; if animating many shapes at once, increase wait or reduce frame redraw frequency.
  • Pen keeps drawing between shapes → always pen up when moving to new starting coordinates.

Teaching notes and learning path

  • Beginner: implement draw square and the cube only. Learn move, turn, repeat.
  • Intermediate: create draw ellipse, learn sin/cos and degree-based loops. Draw cylinder.
  • Advanced: add rotation illusion, animate color, and expose parameters (side, rx, ry, apexY) as sliders using Scratch variables for user experimentation.

Full Code Summary

(1) Create custom block draw square (x) (y) (side) (dir) — copy the block definition above.
(2) Create custom block draw ellipse (cx) (cy) (rx) (ry) — copy the block definition above.
(3) Paste the when green flag clicked initialization script above.
(4) Add the three event scripts for keys A, B, C.
(5) Optional: add enhancements (rotation, keyboard controls, broadcasts).

Conclusion — Bringing 3D Shapes to Life in Scratch

By following this tutorial, you’ve learned how to use Scratch’s Pen Extension to draw and simulate 3D geometric shapes — a cube, pyramid, and cylinder — using nothing but logic, loops, and trigonometry.

You now understand how:

  • Mathematical coordinates control shape positioning and proportions.
  • Pen movement in Scratch translates code into real-time visuals.
  • Trigonometric functions (sin, cos) can create smooth, curved shapes like ellipses and cylinders.
  • Custom blocks (draw square, draw ellipse) make code reusable, modular, and clean.
  • Offsets, apexes, and connectors simulate perspective and depth, giving a 2D canvas a 3D feel.

This project is a great example of how coding and geometry come together to create visually engaging designs. You didn’t just draw — you programmed shapes with logic!

What’s next?

  • Experiment with different angles and offsets to create new 3D illusions (like prisms or cones).
  • Add color transitions or rotations for animation effects.
  • Combine these shapes to build entire 3D structures or scenes (like a house or rocket).
  • Integrate user interaction — let players draw shapes using buttons or sliders.

Scratch proves that even without advanced 3D engines, creativity + math + code = magic

Call to Action

  1. Don’t forget to check out the full video tutorial: How to make 3D Shapes in Scratch – 3D Geometry with Code | Pen Extension in Scratch | Kodex Academy
  2. Like, comment & share the video
  3. Visit kodexacademy.com
  4. subscribe to the Kodex Academy YouTube channel for deeper Scratch content.

Happy coding with Kodex Academy! 🚀

Learn More with Kodex Academy

At Kodex Academy, we’re passionate about helping students learn coding in creative ways. This project teaches more than Scratch—it empowers young minds to build tools that work in the real world.

Explore more:

Stay updated with new content, free tutorials, and coding challenges!

Further Reading & Links

Recent Posts

How to Create a Health Bar Animation in Scratch: Healthy vs. Junk Food Game Tutorial

How to Make a Health Bar in Scratch | Healthy vs Junk Food Game | Scratch Animation | Kodex AcademyCreating fun and engaging games in Scratch not only helps kids learn coding, but also encourages...

How to Create a Basketball Game in Scratch: Full Step-by-Step Tutorial (Moving Hoop, Jumping Ball & Scoring)

Are you ready to create an exciting basketball game in Scratch with a moving hoop, jumping player, and real-time scoring? This step-by-step Scratch game tutorial is perfect for beginners who want to...

How to Make 3D Shapes in Scratch – Draw Cubes, Pyramids & Cylinders Using Pen Extension

If you’ve ever wondered how to make 3D shapes in Scratch or create 3D geometry using code, you’re about to dive into a creative world of math, animation, and programming fun. Learn how to make...

How to Make Flappy Bird Game in Scratch | Coin Collection Game in Scratch | Scratch Coding for Beginners

Have you ever wondered how people create fun games like Flappy Bird without writing a single line of code? With Scratch programming, anyone — from complete beginners to young creators — can build...

How to Make Day & Night Animation in Scratch (Step-By-Step Full Tutorial)

If you’ve ever wondered how to make day and night animation in Scratch or wanted to bring your stories and games to life with realistic sky transitions, this tutorial is perfect for you! Scratch is...

How to Make a Shooting Game in Scratch | Jet Shooting Game Tutorial (Step-By-Step Guide)

Introduction - Jet Shooting Game in Scratch Scratch Tutorial Game | Scratch Game Tutorial Easy | Scratch Programming Games | Jet Shooting Game in ScratchWant to build your first arcade-style...

Top 5 Animations in Scratch: Jump, Bounce & Fly (Beginner Tutorial + Code)

In this step-by-step guide, we explore the Top 5 animations in Scratch games that will make your projects smoother, interactive, and fun to play. You’ll learn: ✅ How to make a sprite jump ✅ How to...

How to Make a Tic-Tac-Toe Game in Scratch – Easy Scratch Tutorial for Beginners

We are going to build the all-time favourite logic game in Scratch: Tic‐Tac‐Toe. In this game two players take turns making X and O on a 3×3 grid. The first one to get three in a row — across, down or...

How to Make a Real-Time Wall Clock in Scratch | Step-by-Step Scratch Tutorial

If you’ve ever wondered how to make a real-time wall clock in Scratch, you’re in the right place! In this step-by-step Scratch tutorial, we’ll show you how to build a fully functional analog clock...

How to Make a 3-Level Platformer Game in Scratch | Mario-Style Hen Adventure Game

Have you ever wanted to build your own Mario-style platformer game in Scratch? This step-by-step guide will walk you through how to make a 3-level platformer game in Scratch — featuring a jumping hen...

How to Make a Math Racing Game in Scratch | Game Concepts and Complete Tutorial

In this tutorial, you’ll learn to build a Math Racing Game in Scratch. Players solve math problems to move their character forward; wrong answers benefit the opponent. It’s a race of speed, accuracy...

How to make Memory Skill Game in Scratch | Card Matching Game in Scratch – Part 2 | Step-by-Step Coding

In this tutorial you'll learn how to make memory skill game in Scratch / card matching game in Scratch. This is a great beginner‑to‑intermediate project for scratch tutorial game, scratch programming...

How to make a Card Matching Game in Scratch | Memory Skill Game in Scratch – Part 1 | Step-by-Step Coding

In this Scratch tutorial, we'll walk you through how to make a card matching game in Scratch, also known as a memory game or skill game. This is a popular beginner project that introduces essential...

Create a Quiz Game in Scratch | Spelling Test in Scratch | Picture Identification in Scratch

Want to make learning spelling fun, visual, and interactive? In this Scratch tutorial, you'll learn how to make a spelling quiz game in Scratch using picture identification, text-to-speech, and...

How to make a Double Jump Game in Scratch | Platformer game in Scratch | Step by Step Coding

How to make a Double Jump Game in Scratch. Scratch is a fantastic platform for beginners to learn programming by making games, animations, and interactive stories. Among the many kinds of games...

How to Use Variables in Scratch | Variable Blocks in Scratch | Complete Tutorial

Introduction: Variable Blocks in Scratch Whether you’re just getting started with Scratch programming or looking to take your projects to the next level, understanding variables and lists is...

How to Make Earth Revolve Around the Sun in Scratch: A Complete Tutorial & Enhancements

Animating Earth revolving around the Sun is a classic beginner/intermediate Scratch animation project. It combines trigonometry (sine & cosine), variables, loops, and visual scripting. Kids can learn...

How to Make a Game in Scratch | Snake Game in Scratch | Step-by-Step Game Coding

In this tutorial, we’ll build a Snake Grid style game in Scratch step by step (very similar to the Kodex Academy example). By doing this, you’ll cover many of the core Scratch building blocks. We will...
Scroll to Top