We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi everyone,
I am pretty new to programming and I'm using p5 so it would be amazing if you could help me out. Basically I would like to create a drawing app, I've managed to create really simple drawing functions but I have a few questions and I'm not sure how to go about it. I know my questions aren't that specific yet - If you could just refer me to the right references to look at, that would help me a lot.
Would it be possible to have an image of a Sketchbook laying on a desk as my background and only let the user draw on the actual book (not the rest of the background)?
How can I create different drawing tools (like pen, pencil etc.) that can be activated by clicking on an icon/image.
Is it possible to let someone draw something and then add filters to it. (editing the finished drawing)
Is there a way of including buttons, that let someone share what they've drawn on the canvas on Twitter, Facebook etc.
Thanks a lot, Elisa
Answers
you need to break this down to single steps.
start by playing with the examples to get a little practice with coding:
https://www.processing.org/examples/pattern.html
https://www.processing.org/examples/continuouslines.html
To your four questions:
1. The Answer is yes
look at
loadImage
andimage
in the referencethen check with
if
if your mouse is inside the canvas part, only then allow drawing:2. you need to define clickable buttons like a tool bar
see here
https://www.processing.org/examples/mousefunctions.html
store which is your drawing color and your pen type when a button is pressed with the mouse.
when drawing act accordingly using different drawing colors and techniques as stored
actually, you might want to use a input library for that or you want to define multiple buttons in an array or even with a class.
3. yes. Either make a new sketch for that or invent a different state of the program (instead of stateDraw now stateEdit) that comes with a different tool bar etc.
4. dunno.
Chrisir
czelisa --
Once you have the continuous lines example as a drawing tool, you could also try line segments. Or brushes, as in this recent discussion of brushes.
Yes. The simplest example of a filter would be a button to turn on and off tint().
Yes -- see the embedded links example.
I wrote:
see
https://processing.org/tutorials/objects/
Thanks for your help guys, I'll try it!
@Chrisir
About my first question. It seems like the mouse is drawing, but behind the background. At least I can't see the lines, once I start loading images as a background. Any ideas how to change that?
@czelisa -- from the background() reference
You probably want to call the background command only once during setup().
@jeremydouglass
Thanks a lot for helping me with my beginner questions :) that was the problem! The drawing works now, I have used mouseDragged. Wherever I start do draw (click and drag), it automatically draws a line from where the cursor was when I opened the window too and not just where I started click and drag. Why is that happening?
Can you post your code please
Sure:
I guess set a boolean firsttime to false In setup
Set it to true in draw
Exec line21 of nly when the var is true
http://p5ide.HerokuApp.com/editor#?sketch=5831eb9d67d01b04000f7523
@Chrisir : Thank you, is this the right reference? https://p5js.org/reference/#/p5/boolean
@GoToLoop: could you please explain what you have done to the code? I am very new to coding. Thank you
Not quite - this is the conversion.
I meant the boolean type itself
Like there is a type int there is one for boolean
It can be true or false only
Well, mostly nothing! :)) Just some tweaks, like change stroke() color. :\">
You need to be more specific on what exactly you didn't understand.
Remember everything above is found on the online reference: :-B
http://p5js.org/reference/
e.g. gotoloop inserted
preload()
which is very good.reference says:
you wrote:
I can't see that behavior when I run gotoloops sketch
http://p5ide.herokuapp.com/editor#?sketch=5831eb9d67d01b04000f7523
No, I haven't. She did! ;;)
oh, that's true
I am so blind...
;-)
@Chrisir and @GoToLoop: I was confused about the "use strict" but I just looked it up. :D thank you! just tried to run your code and I don't have the problem with the starting point anymore. :)