canvas一周一练 -- canvas绘制立体文字

Posted 张不丢

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了canvas一周一练 -- canvas绘制立体文字相关的知识,希望对你有一定的参考价值。

运行效果:

<!DOCTYPE html>
<html>
<head>
</head>
<body>
    <canvas id="drawing" width="800" height="600">A drawing of someing!</canvas>
    <script type="text/javascript">
        var drawing = document.getElementById(\'drawing\');
        if(drawing.getContext) {
            //绘制立体文字
            var context = drawing.getContext(\'2d\');
            context.fillStyle = \'Purple\';
            context.textAlign = \'center\';
            context.textBaseline = \'middle\';
            context.font = \'bold 100px Arial\';
            context.fillText(\'\', 290, 90);
            context.globalAlpha = 0.7;

            context.font = \'bold 80px Arial\';
            context.fillText(\'\', 380, 90);
            context.globalAlpha = 0.6;

            context.font = \'bold 70px Arial\';
            context.fillText(\'\', 205, 90);
            context.globalAlpha = 0.6;

            context.font = \'bold 60px Arial\';
            context.fillText(\'\', 450, 90);
            context.globalAlpha = 0.5;

            context.font = \'bold 60px Arial\';
            context.fillText(\'\', 140, 90);
            context.globalAlpha = 0.5;

            context.font = \'bold 40px Arial\';
            context.fillText(\'\', 500, 90);
            context.globalAlpha = 0.4;

            context.font = \'bold 40px Arial\';
            context.fillText(\'\', 95, 90);
            context.globalAlpha = 0.4;

            context.font = \'bold 20px Arial\';
            context.fillText(\'\', 530, 90);
            context.globalAlpha = 0.3;

            context.font = \'bold 20px Arial\';
            context.fillText(\'\', 65, 90);
            context.globalAlpha = 0.3;
        }

    </script>
</body>
</html>

 

以上是关于canvas一周一练 -- canvas绘制立体文字的主要内容,如果未能解决你的问题,请参考以下文章

如何使用HTML5中canvas绘制一个立体金字塔图形?(javascript可以)

如何使用 Canvas 创建 3D 图形

如何使用 Canvas 创建 3D 图形

canvas绘制文本

《每周一点canvas动画》——修改增强版

《每周一点canvas动画》——修改增强版