How to simply draw a line in famo.us?

不羁岁月 提交于 2019-12-12 02:55:21

问题


If tried a couple of things to simply draw a line with famo.us means (not on the canvas).

Is there any possibilty to do that ?


回答1:


Drawing a line in the DOM without canvas is not really drawing a line as much as creating an illusion of having drawn a line. This example shows how to make a surface look like a line.

Famo.us will allow you to create a surface with a height or width of 1 with the alternative being the length you would like the line to be. With a little magic background-color, the line will appear.

Here is a working example

Create the Line

var line = new Surface({ 
    size:[80,1],
    properties: {
      backgroundColor: 'rgba(0,0,0,1.0)'
    }
});

Setting an angle for the line

Remember: We are starting with a horizontal line, so we rotate starting from that perspective.

  var angle = 45;
  var angleModifier = new Modifier({
    origin: [0, 0],
    align: [0.5, 0.5],
    transform: function() {
      var radians = Math.PI/180 * angle;
      return Transform.rotateAxis([0,0,1], radians);
    }
  });

Add to the context

 context.add(angleModifier).add(line);


来源:https://stackoverflow.com/questions/26886424/how-to-simply-draw-a-line-in-famo-us

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!