Code edit (5 edits merged)
Please save this source code
User prompt
Make a translateTriangle function and centre the cube with the translateTriangle function.
Code edit (2 edits merged)
Please save this source code
User prompt
Please fix the bug: 'Cannot read properties of undefined (reading '0')' in or related to this line: 'var p1 = project(triangle[0], triangle[1], triangle[2]);' Line Number: 144
User prompt
In the projectTriangle function, use perspective project on the 3 points array in the triangle parameter, and return a 2 point array to draw.
Code edit (1 edits merged)
Please save this source code
Code edit (5 edits merged)
Please save this source code
User prompt
make an arg for wireframes on the drawTri function, default false.
Code edit (2 edits merged)
Please save this source code
User prompt
In the drawTri function, fill in the triangles using the scanline rendering algorithm.
User prompt
Fill in the triangles using the scanline rendering algorithm.
Code edit (2 edits merged)
Please save this source code
User prompt
Create a class "Cube" and store the triangles for now.
Code edit (1 edits merged)
Please save this source code
User prompt
optimise the code for speed
Code edit (2 edits merged)
Please save this source code
User prompt
Draw a 1000 random lines in a loop in between the start valuable and the console log
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'toString is not a function' in or related to this line: 'console.log("Time: " + toString(Date.now() - start));' Line Number: 82
Code edit (1 edits merged)
Please save this source code
User prompt
Draw the triangles in the tris.forEach function
Code edit (3 edits merged)
Please save this source code
User prompt
Make a line drawing function using the putPixel function
Code edit (1 edits merged)
Please save this source code
User prompt
Please fix the bug: 'tween.to is not a function' in or related to this line: 'tween.to(self, {' Line Number: 36 ↪💡 Consider importing and using the following plugins: @upit/tween.v1
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0
});
/****
* Game Code
****/
// Game constants for the grid
var GRID_SIZE = 64;
var PIXEL_SIZE = 2048 / GRID_SIZE;
// Create the grid of pixels
function putPixel(x, y, color) {
if (x >= 0 && x < GRID_SIZE && y >= 0 && y < GRID_SIZE) {
game.children[x + y * GRID_SIZE].tint = color;
}
}
// Line drawing function using Bresenham's line algorithm
function drawLine(x0, y0, x1, y1, color) {
var dx = Math.abs(x1 - x0);
var dy = Math.abs(y1 - y0);
var sx = x0 < x1 ? 1 : -1;
var sy = y0 < y1 ? 1 : -1;
var err = dx - dy;
var x = x0;
var y = y0;
while (true) {
putPixel(x, y, color);
if (x === x1 && y === y1) break;
var e2 = 2 * err;
if (e2 > -dy) {
err -= dy;
x += sx;
}
if (e2 < dx) {
err += dx;
y += sy;
}
}
}
var colorIndex = 0;
for (var y = 0; y < GRID_SIZE; y++) {
for (var x = 0; x < GRID_SIZE; x++) {
// Center the virtual screen
var offset = 2732 / 2 - GRID_SIZE * PIXEL_SIZE / 2;
// Get an instance of our pixel asset
var pixel = LK.getAsset('pixel', {
x: x * PIXEL_SIZE,
y: y * PIXEL_SIZE + offset,
tint: 0
});
// Add the pixel to the game stage
game.addChild(pixel);
}
} ===================================================================
--- original.js
+++ change.js
@@ -11,8 +11,36 @@
// Game constants for the grid
var GRID_SIZE = 64;
var PIXEL_SIZE = 2048 / GRID_SIZE;
// Create the grid of pixels
+function putPixel(x, y, color) {
+ if (x >= 0 && x < GRID_SIZE && y >= 0 && y < GRID_SIZE) {
+ game.children[x + y * GRID_SIZE].tint = color;
+ }
+}
+// Line drawing function using Bresenham's line algorithm
+function drawLine(x0, y0, x1, y1, color) {
+ var dx = Math.abs(x1 - x0);
+ var dy = Math.abs(y1 - y0);
+ var sx = x0 < x1 ? 1 : -1;
+ var sy = y0 < y1 ? 1 : -1;
+ var err = dx - dy;
+ var x = x0;
+ var y = y0;
+ while (true) {
+ putPixel(x, y, color);
+ if (x === x1 && y === y1) break;
+ var e2 = 2 * err;
+ if (e2 > -dy) {
+ err -= dy;
+ x += sx;
+ }
+ if (e2 < dx) {
+ err += dx;
+ y += sy;
+ }
+ }
+}
var colorIndex = 0;
for (var y = 0; y < GRID_SIZE; y++) {
for (var x = 0; x < GRID_SIZE; x++) {
// Center the virtual screen
@@ -25,6 +53,5 @@
});
// Add the pixel to the game stage
game.addChild(pixel);
}
-}
-game.children[3].tint = 0xFF0000;
\ No newline at end of file
+}
\ No newline at end of file