How to Add Imaginary Numbers in Scratch: A Complete Guide

Scratch doesn't have a built-in imaginary number type — but that doesn't mean you can't work with them. With the right approach, you can represent and manipulate complex numbers (numbers with both real and imaginary components) entirely within Scratch's block-based environment. Here's how it works and what you need to think through before building it.

What Is an Imaginary Number, Exactly?

An imaginary number is any number that involves the square root of a negative value. The core unit is i, defined as √(−1). A full complex number looks like this:

a + bi

Where:

  • a is the real part
  • b is the imaginary coefficient
  • i is the imaginary unit

In standard math, i² = −1. This concept underpins everything from electrical engineering to fractal geometry (Mandelbrot sets, for instance, are built on complex number arithmetic).

Scratch has no native support for this. It works with regular floating-point numbers only. So adding imaginary numbers means building the math yourself using variables and custom blocks.

Why Scratch Doesn't Support Imaginary Numbers Natively

Scratch is designed as an educational tool for beginners, so its math operators cover only real numbers: addition, subtraction, multiplication, division, and basic functions like square root and absolute value. There's no complex number type in the block library.

This isn't a flaw — it's a scope decision. Handling complex numbers requires representing two values simultaneously (the real part and the imaginary part), which Scratch can do through variables, just not automatically.

How to Represent Imaginary Numbers in Scratch 🔢

The standard approach is to treat each complex number as a pair of variables:

Variable NameWhat It Stores
realThe real component (a)
imagThe imaginary component (b)

For example, the complex number 3 + 4i would be stored as:

  • real = 3
  • imag = 4

If you need to work with multiple complex numbers at once, name them clearly:

  • z1_real, z1_imag
  • z2_real, z2_imag

This naming convention keeps your project readable, especially as operations get more complex.

The Core Arithmetic: Building It Block by Block

Once you've defined your variable pairs, you can implement the four basic operations.

Addition

Adding two complex numbers is straightforward — add the real parts together and the imaginary parts together separately:

  • result_real = z1_real + z2_real
  • result_imag = z1_imag + z2_imag

In Scratch, you'd drag a Set Variable block and use the Addition operator to combine the corresponding variables.

Subtraction

Same logic, reversed:

  • result_real = z1_real − z2_real
  • result_imag = z1_imag − z2_imag

Multiplication

This is where it gets interesting. Multiplying (a + bi)(c + di) expands to:

  • Real part: (a × c) − (b × d)
  • Imaginary part: (a × d) + (b × c)

The key rule: i × i = −1, which is why the real component subtracts b×d instead of adding it.

In Scratch, you'd need multiple operator blocks nested together to compute this correctly.

Division

Dividing complex numbers requires multiplying by the conjugate of the denominator. For (a + bi) ÷ (c + di):

  • Denominator scalar: c² + d²
  • Real part: (a×c + b×d) ÷ (c² + d²)
  • Imaginary part: (b×c − a×d) ÷ (c² + d²)

This takes more blocks but is entirely achievable in Scratch.

Using Custom Blocks to Keep Things Clean

Scratch's My Blocks feature (the "Make a Block" option) lets you define reusable procedures — the closest thing Scratch has to functions. You can create blocks like:

  • Multiply Complex (a) (b) (c) (d) — where inputs are real and imaginary components
  • Add Complex (a) (b) (c) (d)

Inside each custom block, you set the result variables using the math described above. This keeps your main script clean and makes debugging much easier.

Variables That Affect How Complicated This Gets 🧮

How difficult this project becomes depends on a few things:

What you're trying to build. Simple addition of two complex numbers takes maybe 10 minutes to set up. A full Mandelbrot set renderer using iterative complex multiplication is a significantly more involved project.

Your familiarity with Scratch's block system. Nesting multiple operator blocks to compute multiplication or division can get visually cluttered. Programmers coming from text-based languages sometimes find the spatial layout harder to debug than actual code.

Whether you need lists. If you're computing complex number sequences or storing results, you'll likely need Scratch Lists alongside your variables — one list for real parts, one for imaginary parts, indexed in parallel.

The precision you need. Scratch handles floating-point arithmetic, but rounding errors can accumulate in iterative calculations. For visual projects like fractals, this usually doesn't matter. For precise scientific computation, it can.

Different Use Cases, Different Builds

A student visualizing complex number addition for a math class might only need four variables and a handful of blocks — a simple, clean project built in an afternoon.

Someone building a Mandelbrot or Julia set renderer needs to loop the multiplication formula hundreds of times per pixel, manage screen coordinates, and map results to colors — a much heavier project requiring a solid grasp of both the math and Scratch's performance limits.

Someone using Scratch to teach a concept to younger students might skip division entirely and focus only on addition and multiplication to avoid overwhelming the audience.

The math itself is the same in all cases. What changes is the scope, the iteration depth, and how results get displayed — and those depend entirely on what you're actually trying to accomplish.