computer-graphics/lecture09-task01-3d-drawing.js
// Draw a cube to the specified specs
Draw a cube to the specified specs
Draw a cube to the specified specs
function drawCube(x, y, wx, wy, h, color) {
        ctx.beginPath();
        ctx.moveTo(x, y);
        ctx.lineTo(x - wx, y - wx * 0.5);
        ctx.lineTo(x - wx, y - h - wx * 0.5);
        ctx.lineTo(x, y - h * 1);
        ctx.closePath();
        ctx.fillStyle = shadeColor(color, -10);
        ctx.strokeStyle = color;
        ctx.stroke();
        ctx.fill();
        ctx.beginPath();
        ctx.moveTo(x, y);
        ctx.lineTo(x + wy, y - wy * 0.5);
        ctx.lineTo(x + wy, y - h - wy * 0.5);
        ctx.lineTo(x, y - h * 1);
        ctx.closePath();
        ctx.fillStyle = shadeColor(color, 10);
        ctx.strokeStyle = shadeColor(color, 50);
        ctx.stroke();
        ctx.fill();
        ctx.beginPath();
        ctx.moveTo(x, y - h);
        ctx.lineTo(x - wx, y - h - wx * 0.5);
        ctx.lineTo(x - wx + wy, y - h - (wx * 0.5 + wy * 0.5));
        ctx.lineTo(x + wy, y - h - wy * 0.5);
        ctx.closePath();
        ctx.fillStyle = shadeColor(color, 20);
        ctx.strokeStyle = shadeColor(color, 60);
        ctx.stroke();
        ctx.fill();
    }
function drawCube ( x , y , wx , wy , h , color ) { ctx . beginPath ( ) ; ctx . moveTo ( x , y ) ; ctx . lineTo ( x - wx , y - wx * 0.5 ) ; ctx . lineTo ( x - wx , y - h - wx * 0.5 ) ; ctx . lineTo ( x , y - h * 1 ) ; ctx . closePath ( ) ; ctx . fillStyle = shadeColor ( color , - 10 ) ; ctx . strokeStyle = color ; ctx . stroke ( ) ; ctx . fill ( ) ; ctx . beginPath ( ) ; ctx . moveTo ( x , y ) ; ctx . lineTo ( x + wy , y - wy * 0.5 ) ; ctx . lineTo ( x + wy , y - h - wy * 0.5 ) ; ctx . lineTo ( x , y - h * 1 ) ; ctx . closePath ( ) ; ctx . fillStyle = shadeColor ( color , 10 ) ; ctx . strokeStyle = shadeColor ( color , 50 ) ; ctx . stroke ( ) ; ctx . fill ( ) ; ctx . beginPath ( ) ; ctx . moveTo ( x , y - h ) ; ctx . lineTo ( x - wx , y - h - wx * 0.5 ) ; ctx . lineTo ( x - wx + wy , y - h - ( wx * 0.5 + wy * 0.5 ) ) ; ctx . lineTo ( x + wy , y - h - wy * 0.5 ) ; ctx . closePath ( ) ; ctx . fillStyle = shadeColor ( color , 20 ) ; ctx . strokeStyle = shadeColor ( color , 60 ) ; ctx . stroke ( ) ; ctx . fill ( ) ; }
Draw a cube to the specified specs
Draw a cube to the specified specs