简体   繁体   English

如何在没有CSS3和WebGL的情况下向HTML5画布添加3D透视图

[英]How to add 3d perspective to html5 canvas without css3 and webGL

I have this canvas here: 我在这里有这张画布:

http://jsbin.com/soserubafe http://jsbin.com/soserubafe

and CODE javascript: 和CODE javascript:

var canvas=document.getElementById("canvas");
var ctx=canvas.getContext("2d");

var w = canvas.width;
var h = canvas.height;


var cw=canvas.width;
var ch=canvas.height;
var fov = 250;

var pts = [{x:32,y:59.45},{x:136,y:66},{x:170,y:99},{x:171,y:114},{x:183,y:125},{x:218,y:144},{x:218,y:165},{x:226,y:193},{x:254,y:195},{x:283,y:195},{x:292,y:202},{x:325,y:213},{x:341,y:134},{x:397,y:245},{x:417,y:548}];

mimicSvg(pts);

function mimicSvg(pts){

  // make caps & joins round
  //ctx.lineCap='round';
  ctx.lineJoin='round';


  // draw the outside line with red shadow
  ctx.shadowColor='red';
  ctx.shadowBlur='2';
  ctx.lineWidth='40';
  ctx.scale(3,3);
  // draw multiple times to darken shadow
  drawPolyline(pts);
  drawPolyline(pts);
  drawPolyline(pts);

  // stop shadowing
  ctx.shadowColor='transparent';

  // refill the outside line with pink
  ctx.strokeStyle='yellowgreen';
  drawPolyline(pts);

  // draw the inside line
  ctx.lineWidth=2;
  ctx.strokeStyle='blue';
  drawPolyline(pts);

}

function drawPolyline(pts){
  ctx.beginPath();
  ctx.moveTo(pts[0].x,pts[0].y);
  for(var i=1;i<pts.length;i++){
    ctx.lineTo(pts[i].x,pts[i].y);
  }
  ctx.stroke();
}

and HTML: 和HTML:

<canvas id="canvas" width=1000 height=800></canvas>

How I can add 3d perspective view of this canvas witout using css3, webGL and similar. 我如何使用css3,webGL和类似的东西添加此画布的3d透视图。

Is it possible to add 3d view on 2d canvas? 是否可以在2d画布上添加3d视图?

If you can draw 2d and do math and combine the 2 you can create 3d image (not easy though) 如果您可以绘制2d并进行数学运算并结合2,则可以创建3d图像(尽管不容易)

A quick google let me to: http://www.kevs3d.co.uk/dev/phoria/ And this : Possible to run/create 3d animation without need for webgl in HTML5? 一个快速的谷歌让我去: http : //www.kevs3d.co.uk/dev/phoria/而且: 可以运行/创建3d动画而不需要HTML5中的webgl吗? (so duplicate) (如此重复)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM