Make a Spinning Particle Galaxy in Three.js (TypeScript)

Codegiz — Built by Claude AI · Beginner ·🌐 Frontend Engineering ·1mo ago

About this lesson

A glowing spiral galaxy made of thousands of points looks like a lot of work. It isn't. The whole thing is one loop that places each star, a material that makes overlapping points glow, and a render loop that slowly spins it — about fifty lines of Three.js. In this tutorial we scaffold a TypeScript project with Vite from the command line, write it in the editor, and run it in the browser. Source code: https://github.com/GoCelesteAI/particle-galaxy-threejs What You'll Build (scaffolded with the CLI, in TypeScript): - A spinning galaxy of 14,000 points on three spiral arms, colored from a warm core to a cool blue edge. - The one idea that makes the spiral: twist each star further out the farther it sits from the center (spinAngle = r * SPIN). - A particle system done right — flat position and color arrays handed to a single BufferGeometry, drawn as one THREE.Points (no per-star objects). - Additive blending for the glow, vertex colors for the per-star color, and a clock-driven loop to spin it. - The full setup: npm create vite (vanilla-ts), npm install three, write index.html + src/main.ts, then npm run dev to see it live. Timestamps: 0:00 - Intro — what makes a particle galaxy 0:27 - See the galaxy 0:47 - The plan 1:13 - Scaffold the TypeScript project with Vite 2:11 - Write the scene in main.ts 3:14 - The loop that builds the spiral 4:18 - Run it with npm run dev 4:27 - The finished galaxy 4:47 - Recap Key Takeaways: 1. A particle system is just flat arrays of positions and colors handed to a BufferGeometry and drawn as one THREE.Points — that's how 14,000 stars stay fast. 2. The spiral comes from one line: a spin angle that grows with each star's radius, so stars further out are twisted more. 3. Additive blending sums the colors of overlapping points so dense regions bloom to bright white, like a real galaxy core; vertex colors give each star its own color. 4. Math.pow(random, 3) biases the scatter toward the arm, keeping the arms crisp with a few strays inste

Original Description

A glowing spiral galaxy made of thousands of points looks like a lot of work. It isn't. The whole thing is one loop that places each star, a material that makes overlapping points glow, and a render loop that slowly spins it — about fifty lines of Three.js. In this tutorial we scaffold a TypeScript project with Vite from the command line, write it in the editor, and run it in the browser. Source code: https://github.com/GoCelesteAI/particle-galaxy-threejs What You'll Build (scaffolded with the CLI, in TypeScript): - A spinning galaxy of 14,000 points on three spiral arms, colored from a warm core to a cool blue edge. - The one idea that makes the spiral: twist each star further out the farther it sits from the center (spinAngle = r * SPIN). - A particle system done right — flat position and color arrays handed to a single BufferGeometry, drawn as one THREE.Points (no per-star objects). - Additive blending for the glow, vertex colors for the per-star color, and a clock-driven loop to spin it. - The full setup: npm create vite (vanilla-ts), npm install three, write index.html + src/main.ts, then npm run dev to see it live. Timestamps: 0:00 - Intro — what makes a particle galaxy 0:27 - See the galaxy 0:47 - The plan 1:13 - Scaffold the TypeScript project with Vite 2:11 - Write the scene in main.ts 3:14 - The loop that builds the spiral 4:18 - Run it with npm run dev 4:27 - The finished galaxy 4:47 - Recap Key Takeaways: 1. A particle system is just flat arrays of positions and colors handed to a BufferGeometry and drawn as one THREE.Points — that's how 14,000 stars stay fast. 2. The spiral comes from one line: a spin angle that grows with each star's radius, so stars further out are twisted more. 3. Additive blending sums the colors of overlapping points so dense regions bloom to bright white, like a real galaxy core; vertex colors give each star its own color. 4. Math.pow(random, 3) biases the scatter toward the arm, keeping the arms crisp with a few strays inste
Watch on YouTube ↗ (saves to browser)
Sign in to unlock AI tutor explanation · ⚡30

Related Reads

📰
I Built 174 Free Browser-Based Tools Using React + Vite
Learn how to build a suite of free browser-based tools using React and Vite, and why this matters for developers and users alike
Dev.to · Utkarsh Bharti
📰
How I Merge PDFs in the Browser with Vue 3 and pdf-lib
Learn to merge PDFs in the browser using Vue 3 and pdf-lib, streamlining document management and reducing server load
Dev.to · sunshey
📰
Trying Declarative Partial Updates: A Future API for Replacing HTML Later
Learn about Declarative Partial Updates, a potential future API for replacing HTML, and how it can improve frontend development
Dev.to · nyaomaru
📰
Debugging React: From Taking a Deep Breath to Finding the Root Cause
Learn to debug React applications by taking a systematic approach to identify and fix issues
Dev.to · surajrkhonde

Chapters (9)

Intro — what makes a particle galaxy
0:27 See the galaxy
0:47 The plan
1:13 Scaffold the TypeScript project with Vite
2:11 Write the scene in main.ts
3:14 The loop that builds the spiral
4:18 Run it with npm run dev
4:27 The finished galaxy
4:47 Recap
Up next
The masks we wear | Zora Krstić | TEDxLuxembourgCity
TEDx Talks
Watch →