<i id='PbmoT'><tr id='PbmoT'><dt id='PbmoT'><q id='PbmoT'><span id='PbmoT'><b id='PbmoT'><form id='PbmoT'><ins id='PbmoT'></ins><ul id='PbmoT'></ul><sub id='PbmoT'></sub></form><legend id='PbmoT'></legend><bdo id='PbmoT'><pre id='PbmoT'><center id='PbmoT'></center></pre></bdo></b><th id='PbmoT'></th></span></q></dt></tr></i><div id='PbmoT'><tfoot id='PbmoT'></tfoot><dl id='PbmoT'><fieldset id='PbmoT'></fieldset></dl></div>

    <bdo id='PbmoT'></bdo><ul id='PbmoT'></ul>
<tfoot id='PbmoT'></tfoot>

      1. <legend id='PbmoT'><style id='PbmoT'><dir id='PbmoT'><q id='PbmoT'></q></dir></style></legend>
      2. <small id='PbmoT'></small><noframes id='PbmoT'>

      3. 如何在 HTML5(或 Fabric.js)中制作屋顶文字效果和山谷文字效果

        How to make rooftext effect and valley text effect in HTML5 (or Fabric.js)(如何在 HTML5(或 Fabric.js)中制作屋顶文字效果和山谷文字效果)
        <i id='9lndy'><tr id='9lndy'><dt id='9lndy'><q id='9lndy'><span id='9lndy'><b id='9lndy'><form id='9lndy'><ins id='9lndy'></ins><ul id='9lndy'></ul><sub id='9lndy'></sub></form><legend id='9lndy'></legend><bdo id='9lndy'><pre id='9lndy'><center id='9lndy'></center></pre></bdo></b><th id='9lndy'></th></span></q></dt></tr></i><div id='9lndy'><tfoot id='9lndy'></tfoot><dl id='9lndy'><fieldset id='9lndy'></fieldset></dl></div>

        <tfoot id='9lndy'></tfoot>

            <tbody id='9lndy'></tbody>

          <legend id='9lndy'><style id='9lndy'><dir id='9lndy'><q id='9lndy'></q></dir></style></legend>
          • <bdo id='9lndy'></bdo><ul id='9lndy'></ul>
            • <small id='9lndy'></small><noframes id='9lndy'>

                  本文介绍了如何在 HTML5(或 Fabric.js)中制作屋顶文字效果和山谷文字效果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用以下代码:

                  <script type='text/javascript'>//<![CDATA[ 
                  window.onload=function(){
                  /// (c) Ken Fyrstenberg Nilsen, Abidas Software .com
                  /// License: CC-Attribute
                  
                  var ctx = demo.getContext('2d'),
                      font = '64px impact',
                      w = demo.width,
                      h = demo.height,
                      curve,
                      offsetY,
                      bottom,
                      textHeight,
                      angleSteps = 255/h,
                      i = h,
                      y,
                      os = document.createElement('canvas'),
                      octx = os.getContext('2d');
                  
                  os.width = w;
                  os.height = h;
                  octx.font = font;
                  octx.textBaseline = 'top';
                  octx.textAlign = 'center';
                  
                  function renderBridgeText() {
                      curve = parseInt(iCurve.value, 10);
                      offsetY = parseInt(iOffset.value, 10);
                      textHeight = parseInt(iHeight.value, 10);
                      bottom = parseInt(iBottom.value, 10);
                  
                      vCurve.innerHTML = curve;
                      vOffset.innerHTML = offsetY;
                      vHeight.innerHTML = textHeight;
                      vBottom.innerHTML = bottom;
                  
                      octx.clearRect(0, 0, w, h);
                      ctx.clearRect(0, 0, w, h);
                  
                      octx.fillText(iText.value, w * 0.5, 0);
                  
                      /// slide and dice
                      i = w;
                      while (i--) {
                          y = bottom + curve * Math.sin(i / angleSteps * Math.PI /160);
                          ctx.drawImage(os, i, offsetY, 1, textHeight,i,offsetY, 1, y);
                      }
                  }
                  iCurve.onchange = iOffset.onchange = iHeight.onchange = iBottom.onchange = iText.onkeyup = renderBridgeText;
                  renderBridgeText()
                  }//]]>  
                  </script>
                  </head>
                  <body>
                    <canvas id=demo width=600 height=300></canvas>
                  <br>
                      <span>Curve:</span>
                  <input id="iCurve" type="range" min=0 max=200 value=110>
                  <span id="vCurve">110</span>
                      <br><span>OffsetY:</span>
                  <input id="iOffset" type="range" min=0 max=100 value=4>
                  <span id="vOffset">0</span>
                      <br><span>Text height:</span>
                  <input id="iHeight" type="range" min=0 max=200 value=64>
                  <span id="vHeight">64</span>
                      <br><span>Bottom:</span>
                  <input id="iBottom" type="range" min=0 max=200 value=200>
                  <span id="vBottom">200</span>
                  <br><span>Text:</span>
                  <input id="iText" type="text" value="BRIDGE TEXT">
                  </body>
                  

                  我需要像下图这样的文字效果,我做了很多尝试,但我做不到.

                  I need the text effect like below images,I have tried a lot to make this but i cannot.

                  谁能帮帮我?

                  我们还可以使用带有上下文的 fabric.js 中的活动对象吗?

                  Also can we use active object from fabric.js with context?

                  推荐答案

                  这是原始代码的修改版本(提供的代码与我的原始代码相比已更改值..-))可以产生所有这些形状只需使用参数即可:

                  Here is a modified version of the original code (the provided code in question has changed values compared to my original code.. .-) ) which can produce all these shapes just by playing around with the parameters:

                  屋顶不是超级好,但我会把它留给你来添加缩放支持,因为这只是一个例子.

                  The roof is not super but I'll leave it to you to add scaling support as this is meant as an example.

                  在线演示

                  初始化:

                  var ctx = demo.getContext('2d'), /// context
                      font = '64px impact',        /// font
                      w = demo.width,              /// cache canvas width and height
                      h = demo.height,
                      curve,                       /// radius
                      offsetY,                     /// offset for text
                      bottom,                      /// bottom of text
                      textHeight,                  /// text height (region of text)
                      isTri = false,               /// is triangle shaped (roof)
                      dltY,                        /// delta for triangle
                      angleSteps = 180 / w,        /// angle steps for curved text
                      i = w,                       /// "x" backwards
                      y,                           /// top of text
                  
                      /// offscreen canvas that holds original text
                      os = document.createElement('canvas'),
                      octx = os.getContext('2d');
                  
                  os.width = w;
                  os.height = h;
                  
                  /// set font on off-screen canvas where we draw it
                  octx.font = font;
                  octx.textBaseline = 'top';
                  octx.textAlign = 'center';
                  

                  主要功能:

                  /// render
                  function renderBridgeText() {
                  
                      /// demo stuff snipped (see link)
                  
                      /// clear canvases    
                      octx.clearRect(0, 0, w, h);
                      ctx.clearRect(0, 0, w, h);
                  
                      /// draw text (text may change)
                      octx.fillText(iText.value.toUpperCase(), w * 0.5, 0);
                  
                      /// slide and dice
                      dltY = curve / textHeight;  /// calculate delta for roof/triangle
                      y = 0;                      /// reset y in case we do roof
                      i = w;                      /// init "x"
                  
                      while (i--) {
                  
                          if (isTri) {
                              /// bounce delta value mid-way for triangle
                              y += dltY;
                              if (i === (w * 0.5)|0) dltY = -dltY;
                  
                          } else {
                              /// calc length based on radius+angle for curve
                              y = bottom - curve * Math.sin(i * angleSteps * Math.PI / 180);
                          }
                  
                          /// draw a slice
                          ctx.drawImage(os, i, 0, 1, textHeight,
                                            i, h * 0.5 - offsetY / textHeight * y, 1, y);
                      }
                  }
                  

                  这篇关于如何在 HTML5(或 Fabric.js)中制作屋顶文字效果和山谷文字效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Draw border around nontransparent part of image on canvas(在画布上的图像不透明部分周围绘制边框)
                  dragging and resizing an image on html5 canvas(在 html5 画布上拖动图像并调整其大小)
                  What#39;s the difference between a boolean as primitive and a boolean as property of an object?(作为原始对象的布尔值和作为对象属性的布尔值有什么区别?)
                  I want to do animation of an object along a particular path(我想沿特定路径对对象进行动画处理)
                  How to upload image into HTML5 canvas(如何将图像上传到 HTML5 画布中)
                  How to show a running progress bar while page is loading(如何在页面加载时显示正在运行的进度条)

                        <tbody id='1Wzmk'></tbody>

                    • <legend id='1Wzmk'><style id='1Wzmk'><dir id='1Wzmk'><q id='1Wzmk'></q></dir></style></legend>
                      <tfoot id='1Wzmk'></tfoot>

                          <bdo id='1Wzmk'></bdo><ul id='1Wzmk'></ul>
                        • <i id='1Wzmk'><tr id='1Wzmk'><dt id='1Wzmk'><q id='1Wzmk'><span id='1Wzmk'><b id='1Wzmk'><form id='1Wzmk'><ins id='1Wzmk'></ins><ul id='1Wzmk'></ul><sub id='1Wzmk'></sub></form><legend id='1Wzmk'></legend><bdo id='1Wzmk'><pre id='1Wzmk'><center id='1Wzmk'></center></pre></bdo></b><th id='1Wzmk'></th></span></q></dt></tr></i><div id='1Wzmk'><tfoot id='1Wzmk'></tfoot><dl id='1Wzmk'><fieldset id='1Wzmk'></fieldset></dl></div>

                          <small id='1Wzmk'></small><noframes id='1Wzmk'>