目前存在哪些可能的集成,这些集成允许在使用 Web 语言(例如:Javascript、HTML、XML、CSS、MATHML 等)构建的环境中实现下图的美学效果?我的主要目标是能够在 HTML 页面中使用由 PGF/TiKz 或 Pstricks 生成的图形,使其看起来像由 TiKz 本身生成的图像在 Canvas 中完成的。我的意思是,我不想要 TiKz 生成的图形周围的空白区域,而只是绘图。下图有一张由 tikzlings 包生成的猫头鹰图像和一张由 canvas 生成的三角形。注意:显然,猫头鹰是屏幕截图,作为图像包含在 HTML5 的 src 键中。事实上,如果我可以直接使用 tikzlings 包图形以及 canvas 生成的三角形,我就不需要问这个问题了。
完整 HTML 代码:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<style>
canvas {
border:1px solid #d3d3d3;
background-color: #f1f1f1;
}
</style>
</head>
<body onload="startGame()">
<script>
var myGamePiece;
var myBackground;
function startGame() {
myGamePiece = new component(30, 30, "owl.png", 225, 225, "image");
myObstacle = new component(10, 200, "gray", 300, 120);
myGameArea.start();
myBackground = new component(1345, 470, "forest.jpg", 0, 0, "image");
}
var myGameArea = {
canvas : document.createElement("canvas"),
start : function() {
this.canvas.width = 1345;
this.canvas.height = 470;
this.context = this.canvas.getContext("2d");
document.body.insertBefore(this.canvas, document.body.childNodes[0]);
this.frameNo = 0;
this.interval = setInterval(updateGameArea, 20);
myBackground.newPos();
ctx.beginPath();
ctx.moveTo(25,35.5);
ctx.lineTo(35.5,50);
ctx.lineTo(12.5,50);
ctx.fill();
}
}
function component(width, height, color, x, y, type) {
this.type = type;
if (type == "image") {
this.image = new Image();
this.image.src = color;
}
this.width = width;
this.height = height;
this.speedX = 0;
this.speedY = 0;
this.speed = 0;
this.angle = 0;
this.moveAngle = 0;
this.x = x;
this.y = y;
this.update = function() {
ctx = myGameArea.context;
ctx.save();
ctx.translate(this.x, this.y);
ctx.rotate(this.angle);
ctx.fillStyle = color;
ctx.beginPath();
ctx.moveTo(25,35.5);
ctx.lineTo(35.5,50);
ctx.lineTo(12.5,50);
ctx.fill();
ctx.restore();
if (type == "image") {
ctx.drawImage(this.image,
this.x,
this.y,
this.width, this.height);
} else {
ctx.fillStyle = color;
ctx.fillRect(this.x, this.y, this.width, this.height);
ctx.restore();
}
ctx.restore();
}
}
function updateGameArea() {
myGamePiece.update();
myBackground.newPos();
}
</script>
</body>
</html>
猫头鹰代码:
\documentclass{article}
\usepackage{tikzlings-owls,tikz}
\begin{document}
\begin{tikzpicture}
\owl
\end{tikzpicture}
\end{document}