Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Yet Another Paint Program
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ericfourfour




PostPosted: Mon Dec 11, 2006 3:12 pm   Post subject: Yet Another Paint Program

Since everyone seems to be making paint programs, I decided to make one. I just started working on it today so you can only use the line tool and the brush tool.

What makes this different from all of the other paint programs is that it has undo and redo for every action.

Controls:
line tool: '1'
brush too: '2'
undo: CTRL+Z
redo: CTRL+Y



paint.zip
 Description:

Download
 Filename:  paint.zip
 Filesize:  275.91 KB
 Downloaded:  193 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
Silent Avenger




PostPosted: Mon Dec 11, 2006 10:55 pm   Post subject: (No subject)

Pretty good for a start to a paint program. Good work! Now are you going to continue this into a fully functioning paint program? (eg. MS Paint)
ericfourfour




PostPosted: Mon Dec 11, 2006 11:37 pm   Post subject: (No subject)

Silent Avenger wrote:
are you going to continue this into a fully functioning paint program?

I will if I feel like it. The box and oval tool are done. I just forgot to make it so you could select them. The thing I am working on is making someway for the user to select colours (from palettes and the spectrum thing). With the way it is made, the palettes will work like paint.

The way I set up the tools is pretty cool too. If you are interested, there is a tool class. In that tool class there is a procedure called draw which draws whatever was made with that tool. Everything that is drawn is a new tool. This is what allows me to undo and redo easily. Then I have a TwoPointTool class which represents tools that only deal with 2 points (box, line, oval, etc.). I have another one called MultiPointTool which represents tools that deal with multiple points (brush, spray can, etc.).
uberwalla




PostPosted: Tue Dec 12, 2006 4:02 pm   Post subject: (No subject)

ok im just wondering how u got undo//redo to work w/o screenshots Razz ive been looking for something like this for a while. Razz plz share Cool or point me in right direction Smile
thx.
ericfourfour




PostPosted: Tue Dec 12, 2006 4:24 pm   Post subject: (No subject)

To start, everything drawn on the screen is an object. To be specific they are called Drawer's (they draw stuff). I have one for every tool (brush, oval, etc.). They save what they are drawing as you draw it (ie. mouse coordinates). If you read the previous post you will see I have two point tools and multipoint tools, which are inherited by the Drawer's.

With a system like this it is just a matter of storing all of the Drawer's in an array for the undo/redo system.

There is room for optimization though.

Every frame it draws everything again. This will eventually slow the program down if the user draws enough. The one optimization I have implemented is that if the mouse does not move it does not add the point to the list.

There is another optimization I've been thinking of. It involves taking a screen shot after a certain amount has been drawn and simply drawing that screen shot instead of the old stuff (you would still be able to undo because the tools would be saved on the memory).

If I don't feel like putting the last one in you could do the same (when I'm done) by saving and then loading the picture. Except it would not have undo or redo.

If you however, try to make it go slow you will see that it take a lot of drawing. I'm pretty sure you should be able to get a decent picture before it gets unbearable. Very Happy
BenLi




PostPosted: Tue Dec 12, 2006 4:35 pm   Post subject: (No subject)

uberwalla: I think you know this, but you can take screenshots. File.New accepts four parameters which are the left bottom and right top corners of the screenshot you want. Just use an array of say 10 to store the last ten changes to the screen. If you want more than 10, a flexible array is in order.
Clayton




PostPosted: Tue Dec 12, 2006 4:45 pm   Post subject: (No subject)

ericfourfour, how about you check for a mouse down event, then a mouse up event, after each mouse up event, take a screen shot (this is the way it works in most paint programs anyways)
uberwalla




PostPosted: Tue Dec 12, 2006 8:29 pm   Post subject: (No subject)

BenLi wrote:
uberwalla: I think you know this, but you can take screenshots. File.New accepts four parameters which are the left bottom and right top corners of the screenshot you want. Just use an array of say 10 to store the last ten changes to the screen. If you want more than 10, a flexible array is in order.


ok thx for the tip of taking corners but yet it still wouldnt work the way you would want it. because if u always do stuff in the middle then it will over write the middle. (dont worry bout what i am saying Razz)
anyways... im trying to get away from screen shots because its all the extra files that i dont find really needed.

ericfourfour: thx for sharing Smile and not posting your code Razz (that one sounds weird but i like to try it myself Smile [sometimes Wink])

ok and for what i understand of what ur saying u store coordinates into the array right? so do each seperate coordinate get its own spot in that array?

for example:
Turing:

drawfillbox (x,y,z,a, clr) %dont mind the random variables :P
then it stores like...

x = array (1)
y = array (2)
etc?

kinda like that?
Sponsor
Sponsor
Sponsor
sponsor
ericfourfour




PostPosted: Tue Dec 12, 2006 10:28 pm   Post subject: (No subject)

I'll give you a sample of how the mouse coordinates are tracked in TwoPointTool classes (this code will not actually run):
code:
body proc setStartPoint
    point1.x := ^ (mouse.x)
    point1.y := ^ (mouse.y)
end setStartPoint

body proc updateBody
    point2.x := ^ (mouse.x)
    point2.y := ^ (mouse.y)
end updateBody

The updateBody procedure is what is called to update the tool.
uberwalla




PostPosted: Tue Dec 12, 2006 11:38 pm   Post subject: (No subject)

ok wow i have never seen these used in turing Shocked
whats the dif between
"proc" and "body proc"
lol Razz. dont tell me what body means cuz it clearly means main support type thing. like the body paragraph in an essay as an example. but what do they do dif in turing? Razz

and what does '^' do?
ericfourfour




PostPosted: Wed Dec 13, 2006 3:19 pm   Post subject: (No subject)

First of all, I suggest not to try and figure out the fancy names I used for my procedures. Just look at the code and you could figure out the algorithm.

Anyway, there is a nice tutorial on classes made by Cervantes so I'm not going to go into details on body procedures.

And the "^" dereferences a pointer. It is known as the dereference operator. There is not any good tutorials on pointers right now so I would suggest Google and/or Wikipedia.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 11 Posts ]
Jump to:   


Style:  
Search: