pbInfo.ro
Probleme
Probleme - clasa a IX-a
Probleme - clasa a X-a
Probleme - clasa a XI-a
Probleme din concursuri
Căutare problemă
Exerciții
Programează cu Blockly
Desenează cu Processing
Exersează SQL
Soluţii
Resurse
Resurse pentru clasa a IX-a
Resurse pentru clasa a X-a
Resurse pentru clasa a XI-a
Articole recomandate
Subiecte bacalaureat
Ajutor
Autentificare
Înregistrare
Autentificare
Utilizator sau email
Parola
Acest site foloseşte cookies. Navigând în continuare, vă exprimaţi acordul asupra folosirii cookie-urilor.
Îti place pbInfo? Atunci acceptă-l cu totul! Dezactivează modulul de blocare a reclamelor!
Fill-3d - Processing
Lista scripturi
Script Nou
Ajutor
ID
Autor
Duplicat din
Ultima modificare
#7247
7B-Necsulescu Stefan Matei (Stefan_Matei_Necsulescu)
-
Marti, 19 mai 2026, 14:15
let cols = 15; let rows = 15; let depth = 15; let scaleFactor = 20; let grid = []; let fillQueue = []; let targetColor, replacementColor, boundaryColor; let isFilling = false; let fillSpeed = 100; function setup() { // 1. IMPORTANT: Set the canvas to 3D mode (WEBGL) createCanvas(400, 400, WEBGL); // Define Colors targetColor = color(605); // Initial state (White) boundaryColor = color(50); // Obstacles (Dark Grey) replacementColor = color(0, 200, 255); // The active "fill" color (Cyan) // Initialize the 3D grid initializeGrid(); } function draw() { background(20); ambientLight(100); pointLight(255, 255, 255, width, -height/2, depth * scaleFactor); directionalLight(255, 255, 255, -1, 1, -1); orbitControl(); translate(-cols * scaleFactor / 2, -rows * scaleFactor / 2, -depth * scaleFactor / 2); if (isFilling) { for (let i = 0; i < fillSpeed; i++) { if (fillQueue.length > 0) { let current = fillQueue.shift(); floodFillStep(current.x, current.y, current.z); } else { isFilling = false; } } } drawGrid(); } function mousePressed() { if (!isFilling) { let startX = floor(cols / 2); let startY = floor(rows / 2); let startZ = floor(depth / 2); resetFillColors(); addToFillQueue(startX, startY, startZ); isFilling = true; } } function addToFillQueue(x, y, z) { if (isValidCoord(x, y, z) && grid[x][y][z].type === 'target') { fillQueue.push({x, y, z}); grid[x][y][z].type = 'queued'; // Mark it to avoid duplicate entry } } function floodFillStep(x, y, z) { grid[x][y][z].type = 'filled'; addToFillQueue(x + 1, y, z); addToFillQueue(x - 1, y, z); addToFillQueue(x, y + 1, z); addToFillQueue(x, y - 1, z); addToFillQueue(x, y, z + 1); addToFillQueue(x, y, z - 1); } // Helper: Coordinate validity check function isValidCoord(x, y, z) { return x >= 0 && x < cols && y >= 0 && y < rows && z >= 0 && z < depth; } function initializeGrid() { grid = new Array(cols); for (let i = 0; i < cols; i++) { grid[i] = new Array(rows); for (let j = 0; j < rows; j++) { grid[i][j] = new Array(depth); for (let k = 0; k < depth; k++) { grid[i][j][k] = { type: 'target' }; if (random(1) < 0.03) { grid[i][j][k].type = 'boundary'; } } } } } function resetFillColors() { for (let i = 0; i < cols; i++) { for (let j = 0; j < rows; j++) { for (let k = 0; k < depth; k++) { if (grid[i][j][k].type === 'filled' || grid[i][j][k].type === 'queued') { grid[i][j][k].type = 'target'; } } } } } // Draws the voxels based on their type function drawGrid() { stroke(220, 50); // Light, transparent wireframe for (let i = 0; i < cols; i++) { for (let j = 0; j < rows; j++) { for (let k = 0; k < depth; k++) { let voxel = grid[i][j][k]; if (voxel.type === 'boundary') { // Obstacles use specular (shiny) material specularMaterial(50); fill(boundaryColor); } else if (voxel.type === 'filled') { // Filled areas use emissive (glowing) cyan emissiveMaterial(replacementColor); fill(replacementColor); } else { // Non-filled areas are mostly transparent white ambientMaterial(255, 10); fill(255, 10); } push(); translate(i * scaleFactor, j * scaleFactor, k * scaleFactor); box(scaleFactor * 0.9); // Draw voxel (slightly smaller than scale for gaps) pop(); } } } }
Duplicare
Executare
Cod
Cod HTML
<iframe sandbox="allow-scripts" src="/p5js/index.php?id=7247" style="width:408px; height:408px;border:solid 1px gray; overflow: scroll;"></iframe>
Duplicare script
Denumirea noului script
Du-te sus!