# Drawing on multiple layers interactively (AutoCad style)

**URL:** <https://discourse.processing.org/t/drawing-on-multiple-layers-interactively-autocad-style/13735>\
**Category:** Gallery\
**Created:** [September 1, 2019, 5:03am UTC](https://discourse.processing.org/t/drawing-on-multiple-layers-interactively-autocad-style/13735 "2019-09-01T05:03:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pvag](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/pvag/32/5934_2.png) [@Pvag](https://discourse.processing.org/u/Pvag)\
**Post date:** [September 1, 2019, 5:03am UTC](https://discourse.processing.org/t/drawing-on-multiple-layers-interactively-autocad-style/13735/1 "2019-09-01T05:03:16Z")

</div>

I am sharing here a simple code I developed to handle the user interaction for a simple drawing tool.

The user can draw points dragging the mouse, or lines, if pressing SHIFT at the beginning of the drag. The cool thing is that lines are drawn dynamically, until the user releases the mouse, with the previous drawing history kept intact.

[This is the link](https://github.com/Pvag/drawStraightLineProcessing) to the GitHub repository for this sketch: I hope it can serve you as a convenience to add to your project. Enjoy !

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [September 1, 2019, 4:07pm UTC](https://discourse.processing.org/t/drawing-on-multiple-layers-interactively-autocad-style/13735/2 "2019-09-01T16:07:48Z")

</div>

Thanks for sharing this!

Just one small note – you could simplify this a bit if you want by using Processing’s built-in point class, PVector, instead of Point.pde.

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [September 1, 2019, 5:33pm UTC](https://discourse.processing.org/t/drawing-on-multiple-layers-interactively-autocad-style/13735/3 "2019-09-01T17:33:51Z")

</div>

I would also suggest that you modify the empty draw method to

```auto
void draw(){
    drawPermanentLayer();
}

```

When looking at sketch code people at the draw method to see what might be happening an empty method is confusing. Also in this case you can remove all the other stemsnts `drawPermanentLayer()` from your code, avoiding duplication.

---

<div class="post-metadata">

**Author:** ![Pvag](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/pvag/32/5934_2.png) [@Pvag](https://discourse.processing.org/u/Pvag)\
**Post date:** [September 2, 2019, 4:54am UTC](https://discourse.processing.org/t/drawing-on-multiple-layers-interactively-autocad-style/13735/4 "2019-09-02T04:54:14Z")

</div>

Right ! I was too lazy to look it up, even if I remembered that class ! 🙃

Thank you for your suggestion and comment, I appreciate it !

---

<div class="post-metadata">

**Author:** ![Pvag](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/pvag/32/5934_2.png) [@Pvag](https://discourse.processing.org/u/Pvag)\
**Post date:** [September 2, 2019, 9:06am UTC](https://discourse.processing.org/t/drawing-on-multiple-layers-interactively-autocad-style/13735/5 "2019-09-02T09:06:15Z")

</div>

That’s an interesting suggestion, thank you for taking the time to review the code and then writing this !

I have modified the sketch a bit, in order to implement your suggestion; meanwhile I was coding, I also had the chance to better understand the role of a fully transparent background (alpha value set to 0): I may eventually discuss this in a future post.

The updated code that includes your suggestion is already on the [aforementioned repo on GitHub](https://github.com/Pvag/drawStraightLineProcessing), so anyone can check this new implementation, if they desire so.

Thank you everyone for the suggestions ! (I have also implemented @jeremydouglass ’ suggestion ! Thank you !)

---

<div class="post-metadata">

**Author:** ![Pvag](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/pvag/32/5934_2.png) [@Pvag](https://discourse.processing.org/u/Pvag)\
**Post date:** [September 3, 2019, 10:19am UTC](https://discourse.processing.org/t/drawing-on-multiple-layers-interactively-autocad-style/13735/6 "2019-09-03T10:19:19Z")

</div>

[Here’s a post](http://paolovagnini.blogspot.com/2019/09/transparent-background-with-multiple.html) that I just created on my blog, with some clarifications about how to use multiple layers to draw stacks of graphical objects, without losing the history of the other drawings already made on the canvas, together without creating an undesired trail ! You can find the code on my GitHub profile [here](https://github.com/Pvag/transparentLayersProcessing), and also a link to the same repo on the blog post.

The post and the code clarify the usage of a fully transparent (0 opacity, i.e. alpha value set to 0) background, together with the usage of multiple, stacked layers.

I hope this can be useful ! Have a nice day 🌴
