create a website WITH LOADS AND TONS OF animations teaching me how to create a 3d game in js. make it in a single html code block
Assistant
User
now do it for C# where it teaches the user how to create a 3d game in C# in the console. add a option to switch to C++ do learn to do it too with openGL or raylib
Assistant
User
the start tutorial button does nothing please fix that for both C++ and C#
Assistant
User
the start C++ and C# tutorial button does not work, mabey don't make it separate tabs just like a scroll thing and it takes you to the section
Assistant
User
now make a Japanese learning app with tons of lessons
Assistant
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Learn 3D Game Development in JavaScript — With Loads of Animations!</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;700&display=swap');
* {
box-sizing: border-box;
}
body {
margin: 0;
background: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
font-family: 'Poppins', sans-serif;
color: #fff;
overflow-x: hidden;
}
header {
position: sticky;
top: 0;
background: rgba(15, 32, 39, 0.9);
padding: 1rem 2rem;
font-weight: 700;
font-size: 2rem;
text-align: center;
letter-spacing: 3px;
z-index: 1000;
}
main {
max-width: 900px;
margin: 3rem auto 6rem;
padding: 0 1rem;
}
h2 {
font-weight: 700;
font-size: 2.4rem;
margin-top: 3rem;
margin-bottom: 1rem;
text-align: center;
color: #58a6ff;
text-shadow: 0 0 6px #58a6ff88;
}
p {
font-weight: 300;
font-size: 1.12rem;
line-height: 1.6;
margin-bottom: 1.6rem;
text-align: justify;
text-indent: 1rem;
}
pre {
background: #1b2734;
border-radius: 8px;
overflow-x: auto;
padding: 1.2rem;
font-size: 0.9rem;
font-family: 'Source Code Pro', monospace;
box-shadow: 0 0 10px #58a6ff66;
margin-bottom: 2rem;
}
code {
color: #58d68d;
}
/* Animated code highlight */
.highlight {
animation: highlightAnimation 3s infinite alternate ease-in-out;
}
@keyframes highlightAnimation {
0% {background-color: #1b2734;}
50% {background-color: #58a6ff22;}
100% {background-color: #1b2734;}
}
/* Animated floating info boxes */
.info-box {
background: #203a43cc;
border: 2px solid #58a6ffee;
border-radius: 16px;
padding: 1rem 1.3rem;
margin: 2rem 0;
font-size: 1rem;
box-shadow: 0 0 15px #58a6ff80;
transform-origin: center bottom;
animation: floatUpDown 4s ease-in-out infinite;
max-width: 800px;
}
@keyframes floatUpDown {
0%, 100% {transform: translateY(0);}
50% {transform: translateY(-12px);}
}
/* Step fade in animation */
.step {
opacity: 0;
transform: translateY(25px);
animation-fill-mode: forwards;
animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}
.step.visible {
animation-name: fadeInUp;
animation-duration: 1s;
}
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(25px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
/* Interactive 3D cube */
#cube-container {
width: 300px;
height: 300px;
margin: 3rem auto 0;
perspective: 1200px;
}
#cube {
width: 200px;
height: 200px;
margin: auto;
position: relative;
transform-style: preserve-3d;
animation: rotateCube 15s linear infinite;
}
#cube:hover {
animation-play-state: paused;
}
.face {
position: absolute;
width: 200px;
height: 200px;
background: linear-gradient(135deg, #58a6ffcc, #203a43cc);
border: 2px solid #58a6ffaa;
border-radius: 20px;
line-height: 200px;
font-size: 2rem;
font-weight: 700;
color: #fff;
text-align: center;
box-shadow: 0 0 15px #58a6ff99;
}
.face1 { transform: rotateY(0deg) translateZ(100px); }
.face2 { transform: rotateY(90deg) translateZ(100px); }
.face3 { transform: rotateY(180deg) translateZ(100px); }
.face4 { transform: rotateY(-90deg) translateZ(100px); }
.face5 { transform: rotateX(90deg) translateZ(100px); }
.face6 { transform: rotateX(-90deg) translateZ(100px); }
@keyframes rotateCube {
from { transform: rotateX(0deg) rotateY(0deg); }
to { transform: rotateX(360deg) rotateY(360deg); }
}
/* Animate arrow bouncing */
.arrow {
display: inline-block;
margin-left: 8px;
font-weight: 900;
animation: bounce 2s infinite;
color: #58a6ffcc;
}
@keyframes bounce {
0%, 100% {transform: translateY(0);}
50% {transform: translateY(-8px);}
}
/* Button */
button {
display: block;
background: #58a6ff;
border: none;
font-weight: 700;
color: #0f2027;
padding: 14px 28px;
border-radius: 30px;
cursor: pointer;
font-size: 1.1rem;
margin: 2rem auto 0;
box-shadow: 0 0 12px #58a6ffbb;
transition: background 0.3s ease-in-out, color 0.3s ease-in-out;
}
button:hover {
background: #4a8ae8;
color: #e1edff;
}
/* Footer */
footer {
text-align: center;
padding: 2rem 1rem;
font-size: 0.95rem;
color: #58a6ff88;
user-select: none;
}
/* Scroll smoothly on anchor clicks */
html {
scroll-behavior: smooth;
}
</style>
</head>
<body>
<header>Learn 3D Game Dev in JS — Animated Guide</header>
<main>
<section id="intro" class="step">
<h2>Welcome to 3D Game Development with JavaScript!</h2>
<div class="info-box">
<p>In this interactive tutorial, we'll build a basic 3D game using JavaScript and <code>three.js</code>. You'll learn step-by-step with animations and visual explanations. Ready to dive in?</p>
<p>Use the button below to reveal each lesson segment. Hover the cube for a break and observe it closely!</p>
<button id="startBtn">Start Learning <span class="arrow">➡️</span></button>
</div>
</section>
<section id="setup" class="step">
<h2>Step 1: Setting up Your Project</h2>
<p>First, we include the popular 3D library <code>three.js</code> from a CDN to simplify 3D rendering. This saves us the hassle of WebGL's low-level complexity.</p>
<pre class="highlight"><script src="https://cdn.jsdelivr.net/npm/three@0.155.0/build/three.min.js"></script></pre>
<div class="info-box" style="animation-delay: 0.5s;">
<p><strong>Why <code>three.js</code>?</strong>
It wraps WebGL and makes creating and manipulating 3D graphics way easier.</p>
</div>
</section>
<section id="basic-scene" class="step">
<h2>Step 2: Creating a Basic 3D Scene</h2>
<p>Every 3D game starts with three core components: <code>Scene</code>, <code>Camera</code>, and <code>Renderer</code>. Let's create them:</p>
<pre class="highlight">
// Create Scene
const scene = new THREE.Scene();
// Create Camera (PerspectiveCamera)
const camera = new THREE.PerspectiveCamera(
75, // Field of View
window.innerWidth / window.innerHeight,
0.1, // Near clipping plane
1000 // Far clipping plane
);
camera.position.z = 5;
// Create Renderer
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
</pre>
<div class="info-box" style="animation-delay: 1s;">
<p><strong>Tip:</strong> The camera is where the player "looks" from.</p>
</div>
</section>
<section id="cube" class="step" style="text-align:center;">
<h2>Step 3: Adding a 3D Cube (Our First Game Object)</h2>
<p>Let's create a simple spinning cube—your first game object!</p>
<pre class="highlight">
// Geometry + Material + Mesh = Game Object
const geometry = new THREE.BoxGeometry();
const material = new THREE.MeshStandardMaterial({ color: 0x58a6ff });
const cube = new THREE.Mesh(geometry, material);
scene.add(cube);
// Lighting (Directional light for shadows)
const light = new THREE.DirectionalLight(0xffffff, 1);
light.position.set(5,5,5);
scene.add(light);
</pre>
<div class="info-box" style="animation-delay: 1.5s;">
<p>It’s important to add light so we can see our objects in 3D!</p>
</div>
</section>
<section id="animation" class="step" style="text-align:center;">
<h2>Step 4: Animating the Cube</h2>
<p>We use the animation loop to rotate the cube and render the scene every frame.</p>
<pre class="highlight">
function animate() {
requestAnimationFrame(animate);
cube.rotation.x += 0.01; // Rotate cube on X axis
cube.rotation.y += 0.01; // Rotate cube on Y axis
renderer.render(scene, camera);
}
animate();
</pre>
<div class="info-box" style="animation-delay: 2s;">
<p><strong>Note:</strong> <code>requestAnimationFrame</code> creates a smooth animation loop synced to the screen refresh rate.</p>
</div>
</section>
<section id="interaction" class="step">
<h2>Step 5: Adding Basic Interaction (Mouse Move Rotations)</h2>
<p>Make the cube react to the mouse to simulate player control.</p>
<pre class="highlight">
document.addEventListener('mousemove', e => {
const x = (e.clientX / window.innerWidth) * 2 - 1;
const y = -(e.clientY / window.innerHeight) * 2 + 1;
// Apply rotation relative to mouse position
cube.rotation.x = y * 0.5;
cube.rotation.y = x * 0.5;
});
</pre>
<div class="info-box" style="animation-delay: 2.5s;">
<p>Try moving your mouse around once we start the demo!</p>
</div>
</section>
<section id="ready" class="step" style="text-align:center;">
<h2>Step 6: See it all live!</h2>
<p>Below is a live interactive 3D cube. Apply all you learned! Hover to pause rotation; move your mouse for control.</p>
<div id="cube-container" aria-label="Interactive 3D cube example" role="img">
<div id="cube">
<div class="face face1">Front</div>
<div class="face face2">Right</div>
<div class="face face3">Back</div>
<div class="face face4">Left</div>
<div class="face face5">Top</div>
<div class="face face6">Bottom</div>
</div>
</div>
</section>
<section id="final" class="step" style="text-align:center;">
<h2>What's next?</h2>
<p>You just built the foundations to creating your own 3D games! Experiment by adding more objects, textures, and user input. Here's a cheat-sheet you can copy and run instantly:</p>
<pre>
// FULL SIMPLE THREE.JS SETUP
import * as THREE from 'https://cdn.jsdelivr.net/npm/three@0.155.0/build/three.module.js';
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, innerWidth/innerHeight, 0.1, 1000);
camera.position.z = 5;
const renderer = new THREE.WebGLRenderer({antialias:true});
renderer.setSize(innerWidth, innerHeight);
document.body.appendChild(renderer.domElement);
const geometry = new THREE.BoxGeometry();
const material = new THREE.MeshStandardMaterial({color: 0x58a6ff});
const cube = new THREE.Mesh(geometry, material);
scene.add(cube);
const light = new THREE.DirectionalLight(0xffffff,1);
light.position.set(5,5,5);
scene.add(light);
document.addEventListener('mousemove', e => {
const x = (e.clientX / window.innerWidth)*2-1;
const y = -(e.clientY / window.innerHeight)*2+1;
cube.rotation.x = y*0.5;
cube.rotation.y = x*0.5;
});
function animate(){
requestAnimationFrame(animate);
cube.rotation.x += 0.01;
cube.rotation.y += 0.01;
renderer.render(scene, camera);
}
animate();
</pre>
</section>
</main>
<footer>Made by ChatGPT • Happy Coding! 💙</footer>
<script src="https://cdn.jsdelivr.net/npm/three@0.155.0/build/three.min.js"></script>
<script>
// Reveal steps one after another with fade animation on button click
const steps = Array.from(document.querySelectorAll('.step'));
let currentStep = 0;
function showStep(index) {
if(index < steps.length) {
steps[index].classList.add('visible');
if(index === steps.length - 1) {
// Reveal all at once last
document.getElementById('startBtn').style.display = 'none';
}
}
}
document.getElementById('startBtn').addEventListener('click', () => {
if(currentStep < steps.length) {
showStep(currentStep);
currentStep++;
if(currentStep < steps.length) {
// Scroll to next step smoothly
steps[currentStep].scrollIntoView({behavior: 'smooth'});
}
}
});
// Animate the 3D cube demo (CSS cube)
const cube = document.getElementById('cube');
let isPaused = false;
document.getElementById('cube-container').addEventListener('mouseenter', () => {
cube.style.animationPlayState = 'paused';
isPaused = true;
});
document.getElementById('cube-container').addEventListener('mouseleave', () => {
cube.style.animationPlayState = 'running';
isPaused = false;
});
// Mouse move interaction for CSS cube rotation
window.addEventListener('mousemove', (e) => {
if (isPaused) {
const x = (e.clientX / window.innerWidth) * 360;
const y = (e.clientY / window.innerHeight) * 360;
cube.style.transform = `rotateX(${-y}deg) rotateY(${x}deg)`;
}
});
// Initially hide all steps except intro
steps.forEach((s,i) => {
if(i !== 0) s.style.opacity = 0;
});
</script>
</body>
</html>
html
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Learn 3D Game Dev in C# (Console) & C++ (OpenGL/Raylib) - Animated Tutorial</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;700&display=swap');
* {
box-sizing: border-box;
}
body {
margin: 0;
background: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
font-family: 'Poppins', sans-serif;
color: #fff;
overflow-x: hidden;
min-height: 100vh;
display: flex;
flex-direction: column;
}
header {
position: sticky;
top: 0;
background: rgba(15, 32, 39, 0.9);
padding: 1rem 2rem;
font-weight: 700;
font-size: 2rem;
text-align: center;
letter-spacing: 3px;
z-index: 1000;
user-select: none;
}
.toggle-container {
margin: 1rem auto 2rem;
text-align: center;
}
label.switch {
position: relative;
display: inline-block;
width: 70px;
height: 34px;
user-select:none;
}
label.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0; left: 0; right: 0; bottom: 0;
background-color: #ccc;
transition: .4s;
border-radius: 34px;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: #58a6ff;
transition: .4s;
border-radius: 50%;
box-shadow: 0 0 10px #58a6ffaa;
}
input:checked + .slider {
background-color: #58a6ff;
box-shadow: 0 0 18px #58a6ffbb;
}
input:checked + .slider:before {
transform: translateX(36px);
background-color: #203a43;
box-shadow: none;
}
/* Container for content */
main {
max-width: 900px;
margin: auto;
padding: 0 1rem 3rem;
flex-grow: 1;
position: relative;
min-height: 600px;
}
h2 {
font-weight: 700;
font-size: 2.4rem;
margin-top: 3rem;
margin-bottom: 1rem;
text-align: center;
color: #58a6ff;
text-shadow: 0 0 6px #58a6ff88;
}
p {
font-weight: 300;
font-size: 1.1rem;
line-height: 1.6;
margin-bottom: 1.6rem;
text-align: justify;
text-indent: 1rem;
}
pre {
background: #1b2734;
border-radius: 8px;
overflow-x: auto;
padding: 1rem 1.2rem;
font-size: 0.92rem;
font-family: 'Source Code Pro', monospace;
box-shadow: 0 0 10px #58a6ff66;
margin-bottom: 2rem;
white-space: pre-wrap;
word-break: break-word;
}
code {
color: #58d68d;
}
.highlight {
animation: highlightAnimation 3s infinite alternate ease-in-out;
}
@keyframes highlightAnimation {
0% {background-color: #1b2734;}
50% {background-color: #58a6ff22;}
100% {background-color: #1b2734;}
}
.info-box {
background: #203a43cc;
border: 2px solid #58a6ffee;
border-radius: 16px;
padding: 1rem 1.3rem;
margin: 2rem 0;
font-size: 1rem;
box-shadow: 0 0 15px #58a6ff80;
transform-origin: center bottom;
animation: floatUpDown 4s ease-in-out infinite;
max-width: 820px;
}
@keyframes floatUpDown {
0%, 100% {transform: translateY(0);}
50% {transform: translateY(-12px);}
}
.step {
opacity: 0;
transform: translateY(25px);
animation-fill-mode: forwards;
animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}
.step.visible {
animation-name: fadeInUp;
animation-duration: 1s;
}
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(25px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
/* Buttons */
button {
display: block;
background: #58a6ff;
border: none;
font-weight: 700;
color: #0f2027;
padding: 14px 28px;
border-radius: 30px;
cursor: pointer;
font-size: 1.1rem;
margin: 2rem auto 1rem;
box-shadow: 0 0 12px #58a6ffbb;
transition: background 0.3s ease-in-out, color 0.3s ease-in-out;
user-select: none;
}
button:hover {
background: #4a8ae8;
color: #e1edff;
}
/* Footer */
footer {
text-align: center;
padding: 2rem 1rem;
font-size: 0.95rem;
color: #58a6ff88;
user-select: none;
}
/* Scroll smoothly on anchor clicks */
html {
scroll-behavior: smooth;
}
/* Style the code blocks for C# and C++ separately */
pre.cs-code {
border-left: 6px solid #1780c3;
}
pre.cpp-code {
border-left: 6px solid #f34b7d;
}
/* Animated arrow */
.arrow {
display: inline-block;
margin-left: 8px;
font-weight: 900;
animation: bounce 2s infinite;
color: #58a6ffcc;
user-select: none;
}
@keyframes bounce {
0%, 100% {transform: translateY(0);}
50% {transform: translateY(-8px);}
}
</style>
</head>
<body>
<header>3D Game Development Tutorial — C# Console & C++ OpenGL/Raylib</header>
<div class="toggle-container">
<label for="langSwitch">Switch Language:</label>
<label class="switch" title="Toggle between C# and C++ example">
<input type="checkbox" id="langSwitch" aria-label="Toggle language between C# and C++" />
<span class="slider"></span>
</label>
<span style="color:#58a6ff; font-weight: 700;" id="langLabel">C# Console</span>
</div>
<main>
<!-- C# Steps -->
<article class="step cs-step" aria-live="polite">
<h2>Welcome to 3D Game Dev in C# Console!</h2>
<div class="info-box">
<p>Though traditional 3D games are graphical, you can make a form of 3D game in the console using ASCII art, arrays, and math! This tutorial guides you step-by-step animating concepts with C# code snippets.</p>
<p>Toggle the switch above to explore C++ OpenGL/Raylib tutorial as well.</p>
<button id="csStartBtn" aria-controls="cs-step1">Start C# Tutorial <span class="arrow">➡️</span></button>
</div>
</article>
<article id="cs-step1" class="step cs-step" aria-hidden="true">
<h2>Step 1: Representing a 3D Cube in Console</h2>
<p>We'll approximate a 3D cube by projecting 3D points onto 2D console space and drawing lines with ASCII characters.</p>
<pre class="highlight cs-code">
struct Point3D {
public double X, Y, Z;
public Point3D(double x, double y, double z) {
X = x; Y = y; Z = z;
}
}
</pre>
<div class="info-box" style="animation-delay: 0.3s;">
<p><strong>Tip:</strong> Use structs for geometry points to keep your math organized!</p>
</div>
</article>
<article id="cs-step2" class="step cs-step" aria-hidden="true">
<h2>Step 2: Basic 3D to 2D Projection</h2>
<p>Project 3D points onto a 2D plane using a simple perspective projection formula:</p>
<pre class="highlight cs-code">
Point2D Project(Point3D p, double distance) {
double factor = distance / (distance + p.Z);
int x = (int)(p.X * factor);
int y = (int)(p.Y * factor);
return new Point2D(x, y);
}
</pre>
<div class="info-box" style="animation-delay: 0.6s;">
<p><strong>Remember:</strong> The smaller the Z, the closer the point and bigger it appears.</p>
</div>
</article>
<article id="cs-step3" class="step cs-step" aria-hidden="true">
<h2>Step 3: Drawing Lines on Console</h2>
<p>To render polygons, draw lines between points using Bresenham's line algorithm to print ASCII characters.</p>
<pre class="highlight cs-code">
// Simplified line drawing pseudocode
void DrawLine(int x1, int y1, int x2, int y2, char[,] screen) {
// Bresenham's Algorithm implementation here
// Set screen[y, x] = '*';
}
</pre>
<div class="info-box" style="animation-delay: 0.9s;">
<p>This builds the wireframe of your cube in the console.</p>
</div>
</article>
<article id="cs-step4" class="step cs-step" aria-hidden="true">
<h2>Step 4: Animation Loop & Rotation</h2>
<p>Rotate the cube each frame and redraw to simulate 3D spinning!</p>
<pre class="highlight cs-code">
// Rotation around Y axis
Point3D RotateY(Point3D p, double angle) {
double cosA = Math.Cos(angle);
double sinA = Math.Sin(angle);
double x = p.X * cosA - p.Z * sinA;
double z = p.X * sinA + p.Z * cosA;
return new Point3D(x, p.Y, z);
}
</pre>
<div class="info-box" style="animation-delay: 1.2s;">
<p><strong>Hint:</strong> Use <code>Thread.Sleep()</code> and <code>Console.Clear()</code> to create the animation effect.</p>
</div>
</article>
<article id="cs-step5" class="step cs-step" aria-hidden="true">
<h2>Step 5: Putting It All Together</h2>
<p>This is a full simplified example of the main game loop:</p>
<pre class="highlight cs-code">
while (true) {
Console.Clear();
// Rotate points
// Project points
// Draw lines between projected points
Thread.Sleep(50);
}
</pre>
<div class="info-box" style="animation-delay: 1.5s;">
<p>Voila! You have a spinning wireframe cube in your console window.</p>
</div>
</article>
<article id="cs-final" class="step cs-step" aria-hidden="true" style="text-align:center;">
<h2>Ready to run your C# console 3D game?</h2>
<p>Copy these concepts into a Console Application in Visual Studio or your favorite IDE. Play with shapes, rotation, and ASCII art!</p>
<pre class="cs-code">
// Summary Snippet:
struct Point3D { public double X, Y, Z; /* ... */ }
Point2D Project(Point3D p, double d) { /* perspective */ }
void DrawLine(int x1, int y1, int x2, int y2, char[,] screen) { /* Bresenham */ }
Point3D RotateY(Point3D p, double angle) { /* rotate */ }
while(true) {
Console.Clear();
// Rotate, project & draw wireframe cube
Thread.Sleep(50);
}
</pre>
<div class="info-box" style="animation-delay: 1.8s;">
<p>Fantastic start on 3D with just console output!</p>
</div>
</article>
<!-- C++ Steps -->
<article class="step cpp-step" aria-live="polite" aria-hidden="true" style="display:none;">
<h2>Welcome to 3D Game Dev in C++ with OpenGL & Raylib!</h2>
<div class="info-box">
<p>This tutorial guides you through creating a simple 3D spinning cube with graphic output using <code>Raylib</code> (an easy game dev library) or plain <code>OpenGL</code>.</p>
<p>Raylib is recommended if you want fast results without lots of boilerplate.</p>
<button id="cppStartBtn" aria-controls="cpp-step1">Start C++ Tutorial <span class="arrow">➡️</span></button>
</div>
</article>
<article id="cpp-step1" class="step cpp-step" aria-hidden="true" style="display:none;">
<h2>Step 1: Setup Raylib Environment</h2>
<p>Install Raylib and set up your compiler environment.</p>
<pre class="highlight cpp-code">
// Example command (on Linux/macOS):
sudo apt install libraylib-dev
// Or download from https://www.raylib.com
</pre>
<div class="info-box" style="animation-delay: 0.3s;">
<p>Raylib is cross-platform and provides easy functions for 3D rendering.</p>
</div>
</article>
<article id="cpp-step2" class="step cpp-step" aria-hidden="true" style="display:none;">
<h2>Step 2: Basic Raylib Window & Camera</h2>
<pre class="highlight cpp-code">
#include <raylib.h>
int main() {
InitWindow(800, 600, "3D Cube with Raylib");
Camera3D camera = { 0 };
camera.position = (Vector3){ 4.0f, 4.0f, 4.0f };
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
camera.fovy = 45.0f;
camera.type = CAMERA_PERSPECTIVE;
SetTargetFPS(60);
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode3D(camera);
// Cube will go here
EndMode3D();
DrawFPS(10, 10);
EndDrawing();
}
CloseWindow();
return 0;
}
</pre>
<div class="info-box" style="animation-delay: 0.6s;">
<p>This sets up a window and a 3D camera ready to view objects.</p>
</div>
</article>
<article id="cpp-step3" class="step cpp-step" aria-hidden="true" style="display:none;">
<h2>Step 3: Draw and Rotate a Cube</h2>
<pre class="highlight cpp-code">
float rotation = 0.0f;
while (!WindowShouldClose()) {
rotation += 0.01f;
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode3D(camera);
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
// DrawCube with rotation
rlPushMatrix();
rlTranslatef(cubePosition.x, cubePosition.y, cubePosition.z);
rlRotatef(rotation * 50, 0, 1, 0);
DrawCube((Vector3){0, 0, 0}, 2.0f, 2.0f, 2.0f, BLUE);
rlPopMatrix();
EndMode3D();
DrawFPS(10, 10);
EndDrawing();
}
</pre>
<div class="info-box" style="animation-delay: 0.9s;">
<p>Raylib makes rotation and drawing super simple!</p>
</div>
</article>
<article id="cpp-step4" class="step cpp-step" aria-hidden="true" style="display:none;">
<h2>Step 4: OpenGL Alternative Starter</h2>
<p>For a lower-level approach, here is a minimal OpenGL loop using GLFW and GLAD:</p>
<pre class="cpp-code highlight">
// Initialize GLFW & create window
glfwInit();
GLFWwindow* window = glfwCreateWindow(800, 600, "OpenGL 3D Cube", NULL, NULL);
glfwMakeContextCurrent(window);
gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
// Setup viewport & shaders
while(!glfwWindowShouldClose(window)) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Set matrices, bind VAO, draw cube...
glfwSwapBuffers(window);
glfwPollEvents();
}
</pre>
<div class="info-box" style="animation-delay: 1.2s;">
<p>This requires more setup but offers more control over the 3D pipeline.</p>
</div>
</article>
<article id="cpp-final" class="step cpp-step" aria-hidden="true" style="display:none; text-align:center;">
<h2>You're Ready to Build Your 3D Game in C++!</h2>
<p>With Raylib or OpenGL setups, you can now animate 3D objects, add textures, handle input, and build full games.</p>
<p>Try tinkering, add user input, or expand with models and physics engines!</p>
<pre class="cpp-code">
// Summary snippet: Raylib spinning cube
#include <raylib.h>
int main() {
InitWindow(800,600,"3D Cube");
Camera3D cam = {/*...*/};
float rot = 0.0f;
while(!WindowShouldClose()) {
rot += 0.01f;
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode3D(cam);
rlPushMatrix();
rlRotatef(rot*50,0,1,0);
DrawCube((Vector3){0,0,0},2,2,2,BLUE);
rlPopMatrix();
EndMode3D();
DrawFPS(10,10);
EndDrawing();
}
CloseWindow();
return 0;
}
</pre>
</article>
</main>
<footer>Made by ChatGPT • Happy Coding! 💙</footer>
<script>
// Language switch toggle
const langSwitch = document.getElementById('langSwitch');
const langLabel = document.getElementById('langLabel');
// Elements for C# and C++
const csSteps = Array.from(document.querySelectorAll('.cs-step'));
const cppSteps = Array.from(document.querySelectorAll('.cpp-step'));
function showLang(lang) {
if (lang === 'cs') {
langLabel.textContent = 'C# Console';
csSteps.forEach((el, i) => {
el.style.display = '';
el.setAttribute('aria-hidden', 'false');
// reset visible except intro step
if(i === 0) {
el.classList.add('visible');
} else {
el.classList.remove('visible');
}
});
cppSteps.forEach(el => {
el.style.display = 'none';
el.setAttribute('aria-hidden', 'true');
});
} else {
langLabel.textContent = 'C++ OpenGL / Raylib';
cppSteps.forEach((el, i) => {
el.style.display = '';
el.setAttribute('aria-hidden', 'false');
if(i === 0) {
el.classList.add('visible');
} else {
el.classList.remove('visible');
}
});
csSteps.forEach(el => {
el.style.display = 'none';
el.setAttribute('aria-hidden', 'true');
});
}
scrollToTop();
resetButtons();
}
// On toggle change
langSwitch.addEventListener('change', (e) => {
if (e.target.checked) {
showLang('cpp');
} else {
showLang('cs');
}
});
// Initial Load - show C#
showLang('cs');
// Reveal step buttons logic
// C# Tutorial
const csStartBtn = document.getElementById('csStartBtn');
const csStepIds = ['cs-step1','cs-step2','cs-step3','cs-step4','cs-step5','cs-final'];
let csIndex = 0;
csStartBtn?.addEventListener('click', () => {
if(csIndex >= csStepIds.length) return;
const step = document.getElementById(csStepIds[csIndex]);
if(step){
step.classList.add('visible');
step.setAttribute('aria-hidden', 'false');
csIndex++;
step.scrollIntoView({behavior: 'smooth'});
if(csIndex === csStepIds.length){
csStartBtn.style.display = 'none';
}
}
});
// C++ Tutorial
const cppStartBtn = document.getElementById('cppStartBtn');
const cppStepIds = ['cpp-step1', 'cpp-step2', 'cpp-step3', 'cpp-step4', 'cpp-final'];
let cppIndex = 0;
cppStartBtn?.addEventListener('click', () => {
if(cppIndex >= cppStepIds.length) return;
const step = document.getElementById(cppStepIds[cppIndex]);
if(step){
step.classList.add('visible');
step.setAttribute('aria-hidden', 'false');
cppIndex++;
step.scrollIntoView({behavior: 'smooth'});
if(cppIndex === cppStepIds.length){
cppStartBtn.style.display = 'none';
}
}
});
function resetButtons(){
// Reset buttons + steps visibility
csIndex = 0;
cppIndex = 0;
csStartBtn && (csStartBtn.style.display = '');
cppStartBtn && (cppStartBtn.style.display = '');
}
function scrollToTop(){
window.scrollTo({top:0, behavior:'smooth'});
}
</script>
</body>
</html>
html
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Learn 3D Game Dev in C# (Console) & C++ (OpenGL/Raylib) - Animated Tutorial</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;700&display=swap');
* {
box-sizing: border-box;
}
body {
margin: 0;
background: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
font-family: 'Poppins', sans-serif;
color: #fff;
overflow-x: hidden;
min-height: 100vh;
display: flex;
flex-direction: column;
}
header {
position: sticky;
top: 0;
background: rgba(15, 32, 39, 0.9);
padding: 1rem 2rem;
font-weight: 700;
font-size: 2rem;
text-align: center;
letter-spacing: 3px;
z-index: 1000;
user-select: none;
}
.toggle-container {
margin: 1rem auto 2rem;
text-align: center;
}
label.switch {
position: relative;
display: inline-block;
width: 70px;
height: 34px;
user-select:none;
}
label.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0; left: 0; right: 0; bottom: 0;
background-color: #ccc;
transition: .4s;
border-radius: 34px;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: #58a6ff;
transition: .4s;
border-radius: 50%;
box-shadow: 0 0 10px #58a6ffaa;
}
input:checked + .slider {
background-color: #58a6ff;
box-shadow: 0 0 18px #58a6ffbb;
}
input:checked + .slider:before {
transform: translateX(36px);
background-color: #203a43;
box-shadow: none;
}
/* Container for content */
main {
max-width: 900px;
margin: auto;
padding: 0 1rem 3rem;
flex-grow: 1;
position: relative;
min-height: 600px;
}
h2 {
font-weight: 700;
font-size: 2.4rem;
margin-top: 3rem;
margin-bottom: 1rem;
text-align: center;
color: #58a6ff;
text-shadow: 0 0 6px #58a6ff88;
}
p {
font-weight: 300;
font-size: 1.1rem;
line-height: 1.6;
margin-bottom: 1.6rem;
text-align: justify;
text-indent: 1rem;
}
pre {
background: #1b2734;
border-radius: 8px;
overflow-x: auto;
padding: 1rem 1.2rem;
font-size: 0.92rem;
font-family: 'Source Code Pro', monospace;
box-shadow: 0 0 10px #58a6ff66;
margin-bottom: 2rem;
white-space: pre-wrap;
word-break: break-word;
}
code {
color: #58d68d;
}
.highlight {
animation: highlightAnimation 3s infinite alternate ease-in-out;
}
@keyframes highlightAnimation {
0% {background-color: #1b2734;}
50% {background-color: #58a6ff22;}
100% {background-color: #1b2734;}
}
.info-box {
background: #203a43cc;
border: 2px solid #58a6ffee;
border-radius: 16px;
padding: 1rem 1.3rem;
margin: 2rem 0;
font-size: 1rem;
box-shadow: 0 0 15px #58a6ff80;
transform-origin: center bottom;
animation: floatUpDown 4s ease-in-out infinite;
max-width: 820px;
}
@keyframes floatUpDown {
0%, 100% {transform: translateY(0);}
50% {transform: translateY(-12px);}
}
.step {
opacity: 0;
transform: translateY(25px);
animation-fill-mode: forwards;
animation-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
transition: opacity 0.3s ease, transform 0.3s ease;
}
.step.visible {
animation-name: fadeInUp;
animation-duration: 1s;
opacity: 1 !important;
transform: translateY(0) !important;
transition: none;
pointer-events: auto;
}
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(25px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
/* Buttons */
button {
display: inline-block;
background: #58a6ff;
border: none;
font-weight: 700;
color: #0f2027;
padding: 14px 28px;
border-radius: 30px;
cursor: pointer;
font-size: 1.1rem;
margin: 2rem auto 1rem;
box-shadow: 0 0 12px #58a6ffbb;
transition: background 0.3s ease-in-out, color 0.3s ease-in-out;
user-select: none;
pointer-events: auto;
}
button:hover:not(:disabled) {
background: #4a8ae8;
color: #e1edff;
}
button:disabled {
cursor: not-allowed;
background: #26659c;
color: #aac9ff;
box-shadow: none;
}
/* Footer */
footer {
text-align: center;
padding: 2rem 1rem;
font-size: 0.95rem;
color: #58a6ff88;
user-select: none;
}
/* Scroll smoothly on anchor clicks */
html {
scroll-behavior: smooth;
}
/* Style the code blocks for C# and C++ separately */
pre.cs-code {
border-left: 6px solid #1780c3;
}
pre.cpp-code {
border-left: 6px solid #f34b7d;
}
/* Animated arrow */
.arrow {
display: inline-block;
margin-left: 8px;
font-weight: 900;
animation: bounce 2s infinite;
color: #58a6ffcc;
user-select: none;
}
@keyframes bounce {
0%, 100% {transform: translateY(0);}
50% {transform: translateY(-8px);}
}
</style>
</head>
<body>
<header>3D Game Development Tutorial — C# Console & C++ OpenGL/Raylib</header>
<div class="toggle-container">
<label for="langSwitch">Switch Language:</label>
<label class="switch" title="Toggle between C# and C++ example">
<input type="checkbox" id="langSwitch" aria-label="Toggle language between C# and C++" />
<span class="slider"></span>
</label>
<span style="color:#58a6ff; font-weight: 700;" id="langLabel">C# Console</span>
</div>
<main>
<!-- C# Steps -->
<article class="step cs-step" aria-live="polite">
<h2>Welcome to 3D Game Dev in C# Console!</h2>
<div class="info-box">
<p>Though traditional 3D games are graphical, you can make a form of 3D game in the console using ASCII art, arrays, and math! This tutorial guides you step-by-step animating concepts with C# code snippets.</p>
<p>Toggle the switch above to explore C++ OpenGL/Raylib tutorial as well.</p>
<button id="csStartBtn" aria-controls="cs-step1" aria-expanded="false" aria-label="Start the C# tutorial">Start C# Tutorial <span class="arrow">➡️</span></button>
</div>
</article>
<article id="cs-step1" class="step cs-step" aria-hidden="true">
<h2>Step 1: Representing a 3D Cube in Console</h2>
<p>We'll approximate a 3D cube by projecting 3D points onto 2D console space and drawing lines with ASCII characters.</p>
<pre class="highlight cs-code">
struct Point3D {
public double X, Y, Z;
public Point3D(double x, double y, double z) {
X = x; Y = y; Z = z;
}
}
</pre>
<div class="info-box" style="animation-delay: 0.3s;">
<p><strong>Tip:</strong> Use structs for geometry points to keep your math organized!</p>
</div>
</article>
<article id="cs-step2" class="step cs-step" aria-hidden="true">
<h2>Step 2: Basic 3D to 2D Projection</h2>
<p>Project 3D points onto a 2D plane using a simple perspective projection formula:</p>
<pre class="highlight cs-code">
Point2D Project(Point3D p, double distance) {
double factor = distance / (distance + p.Z);
int x = (int)(p.X * factor);
int y = (int)(p.Y * factor);
return new Point2D(x, y);
}
</pre>
<div class="info-box" style="animation-delay: 0.6s;">
<p><strong>Remember:</strong> The smaller the Z, the closer the point and bigger it appears.</p>
</div>
</article>
<article id="cs-step3" class="step cs-step" aria-hidden="true">
<h2>Step 3: Drawing Lines on Console</h2>
<p>To render polygons, draw lines between points using Bresenham's line algorithm to print ASCII characters.</p>
<pre class="highlight cs-code">
// Simplified line drawing pseudocode
void DrawLine(int x1, int y1, int x2, int y2, char[,] screen) {
// Bresenham's Algorithm implementation here
// Set screen[y, x] = '*';
}
</pre>
<div class="info-box" style="animation-delay: 0.9s;">
<p>This builds the wireframe of your cube in the console.</p>
</div>
</article>
<article id="cs-step4" class="step cs-step" aria-hidden="true">
<h2>Step 4: Animation Loop & Rotation</h2>
<p>Rotate the cube each frame and redraw to simulate 3D spinning!</p>
<pre class="highlight cs-code">
// Rotation around Y axis
Point3D RotateY(Point3D p, double angle) {
double cosA = Math.Cos(angle);
double sinA = Math.Sin(angle);
double x = p.X * cosA - p.Z * sinA;
double z = p.X * sinA + p.Z * cosA;
return new Point3D(x, p.Y, z);
}
</pre>
<div class="info-box" style="animation-delay: 1.2s;">
<p><strong>Hint:</strong> Use <code>Thread.Sleep()</code> and <code>Console.Clear()</code> to create the animation effect.</p>
</div>
</article>
<article id="cs-step5" class="step cs-step" aria-hidden="true">
<h2>Step 5: Putting It All Together</h2>
<p>This is a full simplified example of the main game loop:</p>
<pre class="highlight cs-code">
while (true) {
Console.Clear();
// Rotate points
// Project points
// Draw lines between projected points
Thread.Sleep(50);
}
</pre>
<div class="info-box" style="animation-delay: 1.5s;">
<p>Voila! You have a spinning wireframe cube in your console window.</p>
</div>
</article>
<article id="cs-final" class="step cs-step" aria-hidden="true" style="text-align:center;">
<h2>Ready to run your C# console 3D game?</h2>
<p>Copy these concepts into a Console Application in Visual Studio or your favorite IDE. Play with shapes, rotation, and ASCII art!</p>
<pre class="cs-code">
// Summary Snippet:
struct Point3D { public double X, Y, Z; /* ... */ }
Point2D Project(Point3D p, double d) { /* perspective */ }
void DrawLine(int x1, int y1, int x2, int y2, char[,] screen) { /* Bresenham */ }
Point3D RotateY(Point3D p, double angle) { /* rotate */ }
while(true) {
Console.Clear();
// Rotate, project & draw wireframe cube
Thread.Sleep(50);
}
</pre>
<div class="info-box" style="animation-delay: 1.8s;">
<p>Fantastic start on 3D with just console output!</p>
</div>
</article>
<!-- C++ Steps -->
<article class="step cpp-step" aria-live="polite" aria-hidden="true" style="display:none;">
<h2>Welcome to 3D Game Dev in C++ with OpenGL & Raylib!</h2>
<div class="info-box">
<p>This tutorial guides you through creating a simple 3D spinning cube with graphic output using <code>Raylib</code> (an easy game dev library) or plain <code>OpenGL</code>.</p>
<p>Raylib is recommended if you want fast results without lots of boilerplate.</p>
<button id="cppStartBtn" aria-controls="cpp-step1" aria-expanded="false" aria-label="Start the C++ tutorial">Start C++ Tutorial <span class="arrow">➡️</span></button>
</div>
</article>
<article id="cpp-step1" class="step cpp-step" aria-hidden="true" style="display:none;">
<h2>Step 1: Setup Raylib Environment</h2>
<p>Install Raylib and set up your compiler environment.</p>
<pre class="highlight cpp-code">
// Example command (on Linux/macOS):
sudo apt install libraylib-dev
// Or download from https://www.raylib.com
</pre>
<div class="info-box" style="animation-delay: 0.3s;">
<p>Raylib is cross-platform and provides easy functions for 3D rendering.</p>
</div>
</article>
<article id="cpp-step2" class="step cpp-step" aria-hidden="true" style="display:none;">
<h2>Step 2: Basic Raylib Window & Camera</h2>
<pre class="highlight cpp-code">
#include <raylib.h>
int main() {
InitWindow(800, 600, "3D Cube with Raylib");
Camera3D camera = { 0 };
camera.position = (Vector3){ 4.0f, 4.0f, 4.0f };
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
camera.fovy = 45.0f;
camera.type = CAMERA_PERSPECTIVE;
SetTargetFPS(60);
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode3D(camera);
// Cube will go here
EndMode3D();
DrawFPS(10, 10);
EndDrawing();
}
CloseWindow();
return 0;
}
</pre>
<div class="info-box" style="animation-delay: 0.6s;">
<p>This sets up a window and a 3D camera ready to view objects.</p>
</div>
</article>
<article id="cpp-step3" class="step cpp-step" aria-hidden="true" style="display:none;">
<h2>Step 3: Draw and Rotate a Cube</h2>
<pre class="highlight cpp-code">
float rotation = 0.0f;
while (!WindowShouldClose()) {
rotation += 0.01f;
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode3D(camera);
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
// DrawCube with rotation
rlPushMatrix();
rlTranslatef(cubePosition.x, cubePosition.y, cubePosition.z);
rlRotatef(rotation * 50, 0, 1, 0);
DrawCube((Vector3){0, 0, 0}, 2.0f, 2.0f, 2.0f, BLUE);
rlPopMatrix();
EndMode3D();
DrawFPS(10, 10);
EndDrawing();
}
</pre>
<div class="info-box" style="animation-delay: 0.9s;">
<p>Raylib makes rotation and drawing super simple!</p>
</div>
</article>
<article id="cpp-step4" class="step cpp-step" aria-hidden="true" style="display:none;">
<h2>Step 4: OpenGL Alternative Starter</h2>
<p>For a lower-level approach, here is a minimal OpenGL loop using GLFW and GLAD:</p>
<pre class="cpp-code highlight">
// Initialize GLFW & create window
glfwInit();
GLFWwindow* window = glfwCreateWindow(800, 600, "OpenGL 3D Cube", NULL, NULL);
glfwMakeContextCurrent(window);
gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
// Setup viewport & shaders
while(!glfwWindowShouldClose(window)) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Set matrices, bind VAO, draw cube...
glfwSwapBuffers(window);
glfwPollEvents();
}
</pre>
<div class="info-box" style="animation-delay: 1.2s;">
<p>This requires more setup but offers more control over the 3D pipeline.</p>
</div>
</article>
<article id="cpp-final" class="step cpp-step" aria-hidden="true" style="display:none; text-align:center;">
<h2>You're Ready to Build Your 3D Game in C++!</h2>
<p>With Raylib or OpenGL setups, you can now animate 3D objects, add textures, handle input, and build full games.</p>
<p>Try tinkering, add user input, or expand with models and physics engines!</p>
<pre class="cpp-code">
// Summary snippet: Raylib spinning cube
#include <raylib.h>
int main() {
InitWindow(800,600,"3D Cube");
Camera3D cam = {/*...*/};
float rot = 0.0f;
while(!WindowShouldClose()) {
rot += 0.01f;
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode3D(cam);
rlPushMatrix();
rlRotatef(rot*50,0,1,0);
DrawCube((Vector3){0,0,0},2,2,2,BLUE);
rlPopMatrix();
EndMode3D();
DrawFPS(10,10);
EndDrawing();
}
CloseWindow();
return 0;
}
</pre>
</article>
</main>
<footer>Made by ChatGPT • Happy Coding! 💙</footer>
<script>
// Language switch toggle
const langSwitch = document.getElementById('langSwitch');
const langLabel = document.getElementById('langLabel');
// Elements for C# and C++
const csSteps = Array.from(document.querySelectorAll('.cs-step'));
const cppSteps = Array.from(document.querySelectorAll('.cpp-step'));
function showLang(lang) {
if (lang === 'cs') {
langLabel.textContent = 'C# Console';
csSteps.forEach((el, i) => {
el.style.display = '';
el.setAttribute('aria-hidden', 'false');
// reset visible except intro step
if(i === 0) {
el.classList.add('visible');
} else {
el.classList.remove('visible');
}
});
cppSteps.forEach(el => {
el.style.display = 'none';
el.setAttribute('aria-hidden', 'true');
});
// Reset buttons states:
resetButtons('cs');
} else {
langLabel.textContent = 'C++ OpenGL / Raylib';
cppSteps.forEach((el, i) => {
el.style.display = '';
el.setAttribute('aria-hidden', 'false');
if(i === 0) {
el.classList.add('visible');
} else {
el.classList.remove('visible');
}
});
csSteps.forEach(el => {
el.style.display = 'none';
el.setAttribute('aria-hidden', 'true');
});
resetButtons('cpp');
}
scrollToTop();
}
// On toggle change
langSwitch.addEventListener('change', (e) => {
if (e.target.checked) {
showLang('cpp');
} else {
showLang('cs');
}
});
// Initial Load - show C#
showLang('cs');
let csIndex = 0;
const csStartBtn = document.getElementById('csStartBtn');
const csStepIds = ['cs-step1','cs-step2','cs-step3','cs-step4','cs-step5','cs-final'];
let cppIndex = 0;
const cppStartBtn = document.getElementById('cppStartBtn');
const cppStepIds = ['cpp-step1', 'cpp-step2', 'cpp-step3', 'cpp-step4', 'cpp-final'];
csStartBtn.addEventListener('click', () => {
if(csIndex >= csStepIds.length) return;
showStep(csStepIds, csIndex, 'cs');
csIndex++;
if(csIndex === csStepIds.length){
csStartBtn.disabled = true;
csStartBtn.setAttribute('aria-expanded', 'true');
}
});
cppStartBtn.addEventListener('click', () => {
if(cppIndex >= cppStepIds.length) return;
showStep(cppStepIds, cppIndex, 'cpp');
cppIndex++;
if(cppIndex === cppStepIds.length){
cppStartBtn.disabled = true;
cppStartBtn.setAttribute('aria-expanded', 'true');
}
});
function showStep(stepIds, index, lang) {
const stepId = stepIds[index];
if (!stepId) return;
const stepEl = document.getElementById(stepId);
if (!stepEl) return;
stepEl.classList.add('visible');
stepEl.setAttribute('aria-hidden', 'false');
stepEl.scrollIntoView({behavior: 'smooth', block: 'start'});
}
function resetButtons(lang) {
if(lang === 'cs') {
csIndex = 0;
csStartBtn.disabled = false;
csStartBtn.setAttribute('aria-expanded', 'false');
}
if(lang === 'cpp') {
cppIndex = 0;
cppStartBtn.disabled = false;
cppStartBtn.setAttribute('aria-expanded', 'false');
}
}
function scrollToTop(){
window.scrollTo({top:0, behavior:'smooth'});
}
</script>
</body>
</html>
html
<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Learn 3D Game Dev in C# (Console) & C++ (OpenGL/Raylib) - Animated Tutorial</title>
<style>
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;700&display=swap');
* {
box-sizing: border-box;
}
body {
margin: 0;
background: linear-gradient(135deg, #0f2027, #203a43, #2c5364);
font-family: 'Poppins', sans-serif;
color: #fff;
overflow-x: hidden;
min-height: 100vh;
display: flex;
flex-direction: column;
}
header {
position: sticky;
top: 0;
background: rgba(15, 32, 39, 0.9);
padding: 1rem 2rem;
font-weight: 700;
font-size: 2rem;
text-align: center;
letter-spacing: 3px;
z-index: 1000;
user-select: none;
}
.toggle-container {
margin: 1rem auto 2rem;
text-align: center;
}
label.switch {
position: relative;
display: inline-block;
width: 70px;
height: 34px;
user-select:none;
}
label.switch input {
opacity: 0;
width: 0;
height: 0;
}
.slider {
position: absolute;
cursor: pointer;
top: 0; left: 0; right: 0; bottom: 0;
background-color: #ccc;
transition: .4s;
border-radius: 34px;
}
.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: #58a6ff;
transition: .4s;
border-radius: 50%;
box-shadow: 0 0 10px #58a6ffaa;
}
input:checked + .slider {
background-color: #58a6ff;
box-shadow: 0 0 18px #58a6ffbb;
}
input:checked + .slider:before {
transform: translateX(36px);
background-color: #203a43;
box-shadow: none;
}
/* Container for content */
main {
max-width: 900px;
margin: auto;
padding: 0 1rem 3rem;
flex-grow: 1;
position: relative;
min-height: 600px;
scroll-behavior: smooth;
}
h2 {
font-weight: 700;
font-size: 2.4rem;
margin-top: 3rem;
margin-bottom: 1rem;
text-align: center;
color: #58a6ff;
text-shadow: 0 0 6px #58a6ff88;
}
p {
font-weight: 300;
font-size: 1.1rem;
line-height: 1.6;
margin-bottom: 1.6rem;
text-align: justify;
text-indent: 1rem;
}
pre {
background: #1b2734;
border-radius: 8px;
overflow-x: auto;
padding: 1rem 1.2rem;
font-size: 0.92rem;
font-family: 'Source Code Pro', monospace;
box-shadow: 0 0 10px #58a6ff66;
margin-bottom: 2rem;
white-space: pre-wrap;
word-break: break-word;
}
code {
color: #58d68d;
}
.highlight {
animation: highlightAnimation 3s infinite alternate ease-in-out;
}
@keyframes highlightAnimation {
0% {background-color: #1b2734;}
50% {background-color: #58a6ff22;}
100% {background-color: #1b2734;}
}
.info-box {
background: #203a43cc;
border: 2px solid #58a6ffee;
border-radius: 16px;
padding: 1rem 1.3rem;
margin: 2rem 0;
font-size: 1rem;
box-shadow: 0 0 15px #58a6ff80;
transform-origin: center bottom;
animation: floatUpDown 4s ease-in-out infinite;
max-width: 820px;
}
@keyframes floatUpDown {
0%, 100% {transform: translateY(0);}
50% {transform: translateY(-12px);}
}
/* Buttons */
button {
display: inline-block;
background: #58a6ff;
border: none;
font-weight: 700;
color: #0f2027;
padding: 14px 28px;
border-radius: 30px;
cursor: pointer;
font-size: 1.1rem;
margin: 2rem auto 1rem;
box-shadow: 0 0 12px #58a6ffbb;
transition: background 0.3s ease-in-out, color 0.3s ease-in-out;
user-select: none;
pointer-events: auto;
}
button:hover {
background: #4a8ae8;
color: #e1edff;
}
/* Footer */
footer {
text-align: center;
padding: 2rem 1rem;
font-size: 0.95rem;
color: #58a6ff88;
user-select: none;
}
/* Style the code blocks for C# and C++ separately */
pre.cs-code {
border-left: 6px solid #1780c3;
}
pre.cpp-code {
border-left: 6px solid #f34b7d;
}
/* Animated arrow */
.arrow {
display: inline-block;
margin-left: 8px;
font-weight: 900;
animation: bounce 2s infinite;
color: #58a6ffcc;
user-select: none;
}
@keyframes bounce {
0%, 100% {transform: translateY(0);}
50% {transform: translateY(-8px);}
}
/* Highlights for steps */
.step {
opacity: 1;
transform: none;
margin-bottom: 5rem;
transition: none;
}
/* Section anchors offset fix (sticky header) */
section[id] {
scroll-margin-top: 4.5rem;
}
</style>
</head>
<body>
<header>3D Game Development Tutorial — C# Console & C++ OpenGL/Raylib</header>
<div class="toggle-container">
<label for="langSwitch">Switch Language:</label>
<label class="switch" title="Toggle between C# and C++ example">
<input type="checkbox" id="langSwitch" aria-label="Toggle language between C# and C++" />
<span class="slider"></span>
</label>
<span style="color:#58a6ff; font-weight: 700;" id="langLabel">C# Console</span>
</div>
<main>
<!-- C# Intro -->
<section id="cs-intro" aria-live="polite">
<h2>Welcome to 3D Game Dev in C# Console!</h2>
<div class="info-box">
<p>Though traditional 3D games are graphical, you can make a form of 3D game in the console using ASCII art, arrays, and math! This tutorial guides you step-by-step with animated concepts in C# code snippets.</p>
<p>Toggle the switch above to explore the C++ OpenGL/Raylib tutorial as well.</p>
<button id="btnStartCs" aria-label="Go to C# tutorial start">Start C# Tutorial <span class="arrow">➡️</span></button>
</div>
</section>
<!-- C++ Intro -->
<section id="cpp-intro" aria-live="polite" style="display:none;">
<h2>Welcome to 3D Game Dev in C++ with OpenGL & Raylib!</h2>
<div class="info-box">
<p>This tutorial guides you through creating a simple 3D spinning cube with graphics using <code>Raylib</code> (an easy game dev library) or plain <code>OpenGL</code>.</p>
<p>Raylib is recommended if you want fast results without lots of boilerplate.</p>
<button id="btnStartCpp" aria-label="Go to C++ tutorial start">Start C++ Tutorial <span class="arrow">➡️</span></button>
</div>
</section>
<!-- C# Tutorial Steps -->
<section id="cs-step1" class="step cs-step" style="">
<h2>Step 1: Representing a 3D Cube in Console</h2>
<p>We'll approximate a 3D cube by projecting 3D points onto 2D console space and drawing lines with ASCII characters.</p>
<pre class="highlight cs-code">
struct Point3D {
public double X, Y, Z;
public Point3D(double x, double y, double z) {
X = x; Y = y; Z = z;
}
}
</pre>
<div class="info-box" style="animation-delay: 0.3s;">
<p><strong>Tip:</strong> Use structs for geometry points to keep your math organized!</p>
</div>
</section>
<section id="cs-step2" class="step cs-step">
<h2>Step 2: Basic 3D to 2D Projection</h2>
<p>Project 3D points onto a 2D plane using a simple perspective projection formula:</p>
<pre class="highlight cs-code">
Point2D Project(Point3D p, double distance) {
double factor = distance / (distance + p.Z);
int x = (int)(p.X * factor);
int y = (int)(p.Y * factor);
return new Point2D(x, y);
}
</pre>
<div class="info-box" style="animation-delay: 0.6s;">
<p><strong>Remember:</strong> The smaller the Z, the closer the point and bigger it appears.</p>
</div>
</section>
<section id="cs-step3" class="step cs-step">
<h2>Step 3: Drawing Lines on Console</h2>
<p>To render polygons, draw lines between points using Bresenham's line algorithm to print ASCII characters.</p>
<pre class="highlight cs-code">
// Simplified line drawing pseudocode
void DrawLine(int x1, int y1, int x2, int y2, char[,] screen) {
// Bresenham's Algorithm implementation here
// Set screen[y, x] = '*';
}
</pre>
<div class="info-box" style="animation-delay: 0.9s;">
<p>This builds the wireframe of your cube in the console.</p>
</div>
</section>
<section id="cs-step4" class="step cs-step">
<h2>Step 4: Animation Loop & Rotation</h2>
<p>Rotate the cube each frame and redraw to simulate 3D spinning!</p>
<pre class="highlight cs-code">
// Rotation around Y axis
Point3D RotateY(Point3D p, double angle) {
double cosA = Math.Cos(angle);
double sinA = Math.Sin(angle);
double x = p.X * cosA - p.Z * sinA;
double z = p.X * sinA + p.Z * cosA;
return new Point3D(x, p.Y, z);
}
</pre>
<div class="info-box" style="animation-delay: 1.2s;">
<p><strong>Hint:</strong> Use <code>Thread.Sleep()</code> and <code>Console.Clear()</code> to create the animation effect.</p>
</div>
</section>
<section id="cs-step5" class="step cs-step">
<h2>Step 5: Putting It All Together</h2>
<p>This is a full simplified example of the main game loop:</p>
<pre class="highlight cs-code">
while (true) {
Console.Clear();
// Rotate points
// Project points
// Draw lines between projected points
Thread.Sleep(50);
}
</pre>
<div class="info-box" style="animation-delay: 1.5s;">
<p>Voila! You have a spinning wireframe cube in your console window.</p>
</div>
</section>
<section id="cs-final" class="step cs-step" style="text-align:center;">
<h2>Ready to run your C# console 3D game?</h2>
<p>Copy these concepts into a Console Application in Visual Studio or your favorite IDE. Play with shapes, rotation, and ASCII art!</p>
<pre class="cs-code">
// Summary Snippet:
struct Point3D { public double X, Y, Z; /* ... */ }
Point2D Project(Point3D p, double d) { /* perspective */ }
void DrawLine(int x1, int y1, int x2, int y2, char[,] screen) { /* Bresenham */ }
Point3D RotateY(Point3D p, double angle) { /* rotate */ }
while(true) {
Console.Clear();
// Rotate, project & draw wireframe cube
Thread.Sleep(50);
}
</pre>
<div class="info-box" style="animation-delay: 1.8s;">
<p>Fantastic start on 3D with just console output!</p>
</div>
</section>
<!-- C++ Tutorial Steps -->
<section id="cpp-step1" class="step cpp-step" style="display:none;">
<h2>Step 1: Setup Raylib Environment</h2>
<p>Install Raylib and set up your compiler environment.</p>
<pre class="highlight cpp-code">
// Example command (on Linux/macOS):
sudo apt install libraylib-dev
// Or download from https://www.raylib.com
</pre>
<div class="info-box" style="animation-delay: 0.3s;">
<p>Raylib is cross-platform and provides easy functions for 3D rendering.</p>
</div>
</section>
<section id="cpp-step2" class="step cpp-step" style="display:none;">
<h2>Step 2: Basic Raylib Window & Camera</h2>
<pre class="highlight cpp-code">
#include <raylib.h>
int main() {
InitWindow(800, 600, "3D Cube with Raylib");
Camera3D camera = { 0 };
camera.position = (Vector3){ 4.0f, 4.0f, 4.0f };
camera.target = (Vector3){ 0.0f, 0.0f, 0.0f };
camera.up = (Vector3){ 0.0f, 1.0f, 0.0f };
camera.fovy = 45.0f;
camera.type = CAMERA_PERSPECTIVE;
SetTargetFPS(60);
while (!WindowShouldClose()) {
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode3D(camera);
// Cube will go here
EndMode3D();
DrawFPS(10, 10);
EndDrawing();
}
CloseWindow();
return 0;
}
</pre>
<div class="info-box" style="animation-delay: 0.6s;">
<p>This sets up a window and a 3D camera ready to view objects.</p>
</div>
</section>
<section id="cpp-step3" class="step cpp-step" style="display:none;">
<h2>Step 3: Draw and Rotate a Cube</h2>
<pre class="highlight cpp-code">
float rotation = 0.0f;
while (!WindowShouldClose()) {
rotation += 0.01f;
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode3D(camera);
Vector3 cubePosition = { 0.0f, 0.0f, 0.0f };
// DrawCube with rotation
rlPushMatrix();
rlTranslatef(cubePosition.x, cubePosition.y, cubePosition.z);
rlRotatef(rotation * 50, 0, 1, 0);
DrawCube((Vector3){0, 0, 0}, 2.0f, 2.0f, 2.0f, BLUE);
rlPopMatrix();
EndMode3D();
DrawFPS(10, 10);
EndDrawing();
}
</pre>
<div class="info-box" style="animation-delay: 0.9s;">
<p>Raylib makes rotation and drawing super simple!</p>
</div>
</section>
<section id="cpp-step4" class="step cpp-step" style="display:none;">
<h2>Step 4: OpenGL Alternative Starter</h2>
<p>For a lower-level approach, here is a minimal OpenGL loop using GLFW and GLAD:</p>
<pre class="cpp-code highlight">
// Initialize GLFW & create window
glfwInit();
GLFWwindow* window = glfwCreateWindow(800, 600, "OpenGL 3D Cube", NULL, NULL);
glfwMakeContextCurrent(window);
gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
// Setup viewport & shaders
while(!glfwWindowShouldClose(window)) {
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Set matrices, bind VAO, draw cube...
glfwSwapBuffers(window);
glfwPollEvents();
}
</pre>
<div class="info-box" style="animation-delay: 1.2s;">
<p>This requires more setup but offers more control over the 3D pipeline.</p>
</div>
</section>
<section id="cpp-final" class="step cpp-step" style="display:none; text-align:center;">
<h2>You're Ready to Build Your 3D Game in C++!</h2>
<p>With Raylib or OpenGL setups, you can now animate 3D objects, add textures, handle input, and build full games.</p>
<p>Try tinkering, add user input, or expand with models and physics engines!</p>
<pre class="cpp-code">
// Summary snippet: Raylib spinning cube
#include <raylib.h>
int main() {
InitWindow(800,600,"3D Cube");
Camera3D cam = {/*...*/};
float rot = 0.0f;
while(!WindowShouldClose()) {
rot += 0.01f;
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode3D(cam);
rlPushMatrix();
rlRotatef(rot*50,0,1,0);
DrawCube((Vector3){0,0,0},2,2,2,BLUE);
rlPopMatrix();
EndMode3D();
DrawFPS(10,10);
EndDrawing();
}
CloseWindow();
return 0;
}
</pre>
</section>
</main>
<footer>Made by ChatGPT • Happy Coding! 💙</footer>
<script>
const langSwitch = document.getElementById('langSwitch');
const langLabel = document.getElementById('langLabel');
// Sections references
const csIntro = document.getElementById('cs-intro');
const cppIntro = document.getElementById('cpp-intro');
const csSteps = Array.from(document.querySelectorAll('.cs-step'));
const cppSteps = Array.from(document.querySelectorAll('.cpp-step'));
const btnStartCs = document.getElementById('btnStartCs');
const btnStartCpp = document.getElementById('btnStartCpp');
// Initial: show C# intro and steps, hide C++ steps and intro
function showCs() {
langLabel.textContent = 'C# Console';
csIntro.style.display = '';
cppIntro.style.display = 'none';
csSteps.forEach(s => s.style.display = '');
cppSteps.forEach(s => s.style.display = 'none');
}
// Show C++ intro and steps, hide C# steps and intro
function showCpp() {
langLabel.textContent = 'C++ OpenGL / Raylib';
cppIntro.style.display = '';
csIntro.style.display = 'none';
cppSteps.forEach(s => s.style.display = '');
csSteps.forEach(s => s.style.display = 'none');
}
langSwitch.addEventListener('change', e=>{
if (e.target.checked) {
showCpp();
scrollToSection(cppIntro);
} else {
showCs();
scrollToSection(csIntro);
}
});
// Scroll to start tutorial steps on button click
btnStartCs.addEventListener('click', () => {
scrollToSection(document.getElementById('cs-step1'));
});
btnStartCpp.addEventListener('click', () => {
scrollToSection(document.getElementById('cpp-step1'));
});
// Smooth scroll helper, offset for sticky header
function scrollToSection(el) {
if (!el) return;
const yOffset = -70; // header height approx
const y = el.getBoundingClientRect().top + window.pageYOffset + yOffset;
window.scrollTo({top: y, behavior: 'smooth'});
}
// On page load show C# by default
showCs();
</script>
</body>
</html>