javascript - Implementing an eraser with paperjs -


I have checked, similar questions have been asked, but partly answered or not answered .

I need to create an Eraser tool with PaperJS which is capable of erasing existing amounts, without erasing the image.

The image may be located on the first layer, and the second one. View with JSFiddle: which shows two attempts:

  paperinstol (window); Var canvas = document. GetElementById ("myCanvas"); Paper.setup (canvas); // Yellow background (can also be a background image), which var rect = new rectangle (new point (0, 0), new point (paper.view.size.width, paper.view.size.height) Should not go); Var rectpath = new path Context (rect); RectPath.fillColor = 'yellow'; // Black Line er first = paper.project.activeLayer First attempt to erase; Var seconds = new layer (); = New from point (50, 0); Var to = new point (50, 100); Var path1 = new path Line (from, to); Path1.strokeColor = 'black'; Path1.strokeWidth = 40; = Var from new point (0, 50); Var to = new point (100, 50); Var path2 = new path Line (from, to); Path2.strokeColor = 'green'; // I have also tried other colors, it seems irrelevant path2.strokeWidth = 40; Path2.blendMode = 'Destination-Out'; // So I saw this path - new compound path ({children: [new path cycles ({center: new point (200, 50), radius: 30}), new path cycles ({center: new point (200) , 50), radius: 10})], fill color: 'black', selected: true}); // second attempt // I really want to wipe out a line through several paths, it is not sure how to apply it along this path = new compound path ({children: [new path line ({from: [350, 0], [400, 50], strokewidth: [350, 100], stroke width: 30, stroke color: 'green' // seems irrelevant)), new path. 30, stroke color: 'white' // it seems irrelevant}), stroke color: 'black', selected: true, strokeweight: 20}); Paper.view.draw ();  
  & lt; Script src = "http://tmantechblog.com/testpaperjs/js/libs/paper.js"></script> & Lt; Canvas ID = "Mikevas" Height = '500' width = '500' & gt; It does not support the HTML5 canvas & lt; / Canvas & gt;  

  • The first attempt tries to use blendMode = 'destination-out', but instead of a transparent path Leaves a white mark
  • The second implementation tries to duplicate the pathfinder path available there, but where the path crosses, a hole is produced. Apart from this, I am unsure of how it can be used in many ways to implement an Eraser.

Any advice will be given about how to proceed. Otherwise I have to shut down my entire project to do basic HTML 5 canvas or FabricJs, or something like that.


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -