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

Username:   Password: 
 RegisterRegister   
 [Snippit] Paint - the hard stuff
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
TheZsterBunny




PostPosted: Mon Feb 07, 2005 7:47 pm   Post subject: [Snippit] Paint - the hard stuff

This is sort of an experiment. Recently, there has been a spate of paint program projects, each asking questions about various same aspects.

Here, the hardest parts of paint (bucket and spray can) in easy to understand procedural form.

-Z

code:

proc paintcan (x, y, on, with : int)
    if whatdotcolor (x, y) = on and x > 0 and y > 0 and x < maxx and y < maxy and on not= with then
        drawdot (x, y, with)
        paintcan (x, y - 1, on, with)
        paintcan (x, y + 1, on, with)
        paintcan (x - 1, y, on, with)
        paintcan (x + 1, y, on, with)
    end if
end paintcan

proc spray (x, y, rad, thick, clr : int)
    var ranang : real
    var ranrad : int
    for i : 1 .. thick
        ranang := Rand.Real * (2 * Math.PI)
        ranrad := Rand.Int (0, rad)
        drawdot (x + round (ranrad * cos (ranang)), y + round (ranrad * sin (ranang)), clr)
    end for
    delay (10)
end spray


I'm sure theres a faster way to do the can. Any ideas?
Sponsor
Sponsor
Sponsor
sponsor
Viper




PostPosted: Tue Feb 08, 2005 12:59 pm   Post subject: (No subject)

well a really easie and fast way would be to have it draw a box the size of the paint area eg

if key ("c") then drawfillbox (100,100,700,1000)
end if
Delos




PostPosted: Tue Feb 08, 2005 3:29 pm   Post subject: (No subject)

I take it you don't understand the point of the fill function then.

This is not a case where you are drawing a box...not necassarily of course. Here, the 'bucket' draws a indeterminate shape - it simply fills the area occupied by a consitent colour. Try it out in Paint.

However, your idea does have its merits to it...but in a completely different implementation involving transparent colours and such...

EDIT:

Here's my idea. It works on the premise that you know the area of your pic that you want to edit. It also assumes that there is a particular colour within that area that you want replaced. This could be down w/ whatdotcolour, but would be a lot slower.

code:

% Area to be affected is (0,0) -> (100,100)

var mainPic : int := Pic.FileNew ("pic1.bmp")
Pic.Draw (mainPic, 0, 0, picCopy)

var crop : int := Pic.New (0, 0, 100, 100)
% Capture area to be editted.

Pic.SetTransparentColour (crop, 12)
% Colour to be replaced is 12

drawfillbox (0, 0, 100, 100, 7)
% This draws a box over the affected area, in the colour that you want...in this case black.
Pic.Draw (crop, 0, 0, picMerge)


As you can see, this snippet replaces all the Red in the mainPic to Black. Useful.
TheZsterBunny




PostPosted: Tue Feb 08, 2005 8:12 pm   Post subject: (No subject)

Thats nice ^_^

however, it can replace all the existing color in the paint.

Useful if you're going to be doing some fading

stack overflow errors in mine. maybe the trick would be to try bigger blocks first...

-Z
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  [ 4 Posts ]
Jump to:   


Style:  
Search: