T
T
Tereverda2020-12-23 16:03:44
Canvas
Tereverda, 2020-12-23 16:03:44

Drawing a cube on canvas?

On the page, after adding dimensions, a cube appears, with which library is this implemented or can it be simply implemented?
www.openovate.com/lbc.php
You set dimensions->length-width-height-> you get a three-dimensional figure with dimensions.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
W
WbICHA, 2020-12-23
@WblCHA

And press F12 and see for yourself in any way?

<script type="text/javascript">function drawSquare(id, w, h, d) {
    var canvas = document.getElementById(id);
    var context = canvas.getContext('2d');
    
    context.lineWidth = 1;
    context.lineCap = "square";
    
    context.strokeStyle = "#0011aa";
    context.fillStyle = "rgba(0, 0, 150, 0.5)";
    
    var dh = d/2;
    var wh = d/2;
    
    context.beginPath();
    context.moveTo(0, d);
    context.lineTo(w,d);
    context.lineTo(w,d+h);
    context.lineTo(0,d+h);
    context.lineTo(0,d);
    
    context.moveTo(0, d);
    context.lineTo(wh,dh);
    context.lineTo(wh+w,dh);
    context.lineTo(w, d);
    context.lineTo(0, d);
    
    context.moveTo(wh+w,dh);
    context.lineTo(w,d);
    context.lineTo(w,d+h);
    context.lineTo(wh+w,dh+h);
    context.lineTo(wh+w,dh);
    
    context.stroke();
    
    context.closePath();
    context.fill();	
  }</script>

Regular 2D object on native canvas.

A
Alexander, 2020-12-28
@Aleksandr-JS-Developer

Such a cube can be easily made in native CSS.
There is even an online editor
. In general, about libraries and frameworks for rendering on canvas - look at ThreeJS or BabylonJS. One of their most powerful tools is the ability to import files from professional 3D editors such as Blender or 3ds Max. This means that you can render 3D objects of any complexity in the browser. The only limitation here is the performance of the client's machine.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question