This site requires JavaScript, please enable it in your browser!
Greenfoot back

Report as inappropriate.

mjrb4
mjrb4 presents ...

2008/8/1

Paint v2

This version has lines rather than the jagged dots seen earlier.

Source and worksheets are available for download at http://greenfoot.org/greenroom/index.php/Paint_2

3758 views / 17 in the last 7 days

1 vote | 0 in the last 7 days

Tags: mouse demo paint

Your browser does not support the canvas tag.
JL235JL235

2008/8/1

An improvement, but it gets really laggy after a while (or at least on my 900mhz celeron). How are you representing the lines? I can imagine it's an array of points with you adding to it, then clearing and redrawing the entire screen (or something similar). If your not too concrned about undo then just draw any new lines directly to the background with no storing or clearing. It should then be at the same speed regardless of how many lines have been drawn since old ones are stored on the background. But you could still implement undo by copying the background over the last 5 times that a line was added (so undo is just going to a previous background). I'd aim to try and keep the speed consistent.
mjrb4mjrb4

2008/8/1

Actually, I scrapped the array of points / redraw the entire screen each time for the reasons you mentioned pretty early on, I figured it'd be pretty inefficient and get very laggy after a while, especially redrawing the whole screen. In fact, none of the lines are stored at all. There's only one point stored, and that's the previous one. Then it draws a line between the previous point and the new one, then sets the new point to the previous point and loops again. Nothing is redrawn at all, it's just one line drawn per act cycle (while the mouse is being dragged, of course.) The only reason I can think of for it being laggy is the sheer number of lines on the screen - and there's not a lot I can do about that!
JL235JL235

2008/8/2

Are the lines actors or are you drawing the lines to the world's background?
mjrb4mjrb4

2008/8/2

They're actors - I did try drawing them directly to the background, but that seemed to make things worse. Though thinking about it, that was my coding at 2 in the morning so there's a good chance there was something I missed...
BlackholeGFBlackholeGF

2009/2/13

Post the source!
mjrb4mjrb4

2009/2/13

The source is available on the greenroom, along with worksheets on how to write it - you can download it from http://greenfoot.org/greenroom/index.php/Paint_2
the lines are actors? why don't you create an object the size of the screen and draw onto it using drawLine(x,y,x,y)?
mjrb4mjrb4

2009/2/15

The idea was it'd mean manipulation was a lot easier later. I never got round to it, but when drawing shapes and undoing lines etc. it seemed a lot easier to be working with individual actors than keeping a record of lines drawn and drawing them straight to the world. It'd also make them a lot easier to drag about and suchlike if I implemented that at any point. But... I see what you mean, it's a lot more laggy than I thought it would be so if I ever did take it further I might well rethink on that one!

Want to leave a comment? You must first log in.

Who likes this?

hatsumomo