so://phie

outline

A web-based drawing app
git clone git://soophie.de/outline

blob: d257731f000d1c7a6acce45ec432544809b56f5e (802 bytes)[doc][blame][raw]

1module.exports = {

2 init: function(g, o) {

3 this.g = g;

4 this.o = o;

5 },

6 draw: function(args) {

7 let { pos, last, radius, color } = args || {};

8 if(last) {

9 let delta = {

10 x: last.x - pos.x,

11 y: last.y - pos.y

12 };

13 let dist = Math.sqrt(Math.pow(delta.x, 2) + Math.pow(delta.y, 2));

14 let length = dist / (radius / 2);

15 for(let i = 0; i < length; i++) {

16 let x = pos.x + (delta.x / length * i);

17 let y = pos.y + (delta.y / length * i);

18 this.g.fillStyle = color;

19 this.g.beginPath();

20 this.g.arc(x, y, 2 * radius, 0, 2 * Math.PI);

21 this.g.fill();

22 this.g.fillStyle = 'black';

23 }

24 }

25 else {

26 this.g.fillStyle = color;

27 this.g.beginPath();

28 this.g.arc(pos.x, pos.y, 2 * radius, 0, 2 * Math.PI);

29 this.g.fill();

30 this.g.fillStyle = 'black';

31 }

32 }

33};