This is my teacher's instructions:
Make a little paint program. Before selecting color, it should not draw. To select a color, the user clicks on one of the little circles at the top. To draw they hold the mouse down and move it (i.e. drag it around). It should not draw unless button is being held. Use ellipses (instead of points) to make painting thicker.
Picture:
https://plus.google.com/photos/1033500600803017243...
Update:I'm using a program called Processing and it uses Java
Copyright © 2024 QUIZLS.COM - All rights reserved.
Answers & Comments
If this is a windows program then you could handle it like this.
The following variables are needed
To indicate the mouse button is down or up
BOOL bMouseDown
To indicate if a color is selected
BOOL bColorSelected
The color selected
RGB rgbColor
Width of ellipse
int iWidth
I will assume that you have color buttons at the top to select the color therefore when
clicked
bColorSelected = true
rgbColor = value of selected button
As widows is a message based system handle the following messages something like this,
On Mouse down
bMouseDown = True
On Mouse up
bMouseDown = False
On Mouse Move
{
if bMouseDown = False // (can be OR with bColorSelected)
return
if bColorSelected = False // wont draw if color not selected
return
Retrive the xy pos the mouse pointer is over
Plot the ellipse at xy point with desired width and rgbColor
Invalidate region of ellipse
Redraw window
}
int iWidth