A different Draw.Fill
Author |
Message |
copthesaint
![](http://compsci.ca/v3/uploads/user_avatars/15853548854c9c056fda48d.jpg)
|
Posted: Mon Mar 02, 2009 8:28 pm Post subject: A different Draw.Fill |
|
|
This is also posted on the 20 lines or less topic but I made a forum if anyone want to use this.
Basicly If will replace the dots of a color is an area. this in a way is better because it won't delete all the other colors like draw.fill does.
If sure people will find use in this. I have already.
Turing: |
%This find Dots Equal to The 2nd color and replaces them with the 1st color
Draw.FillOval (25, 25, 25, 25, black)%This is just to show you that it works
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%The program%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
var Xvalue,Yvalue : int := 0
procedure ChangeDotColorArea (X1value : real, Y1value : real, X2value : real, Y2value : real, Color1 : int, Color2 : int)
Xvalue: = round (X1value )
Yvalue: = round (Y1value )
for z : round (X1value * Y1value ) .. round (X2value * Y2value )
Xvalue+= 1
if Xvalue > X2value then
Xvalue: = round (X1value )
Yvalue+ = 1
end if
if View.WhatDotColor (Xvalue,Yvalue ) = Color2 then
Draw.Dot (Xvalue,Yvalue,Color1 )
end if
end for
end ChangeDotColorArea
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%End of the program%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ChangeDotColorArea (0, 0, 25, 25, blue, black) %This is also just to show you that it works
ChangeDotColorArea (25, 25, 50, 50, blue, black)
ChangeDotColorArea (25, 0, 50, 25, red, black)
ChangeDotColorArea (0, 25, 25, 50, red, black) |
|
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Tony
![](http://wiki.compsci.ca/images/f/f4/OniTony.gif)
|
Posted: Mon Mar 02, 2009 8:43 pm Post subject: RE:A different Draw.Fill |
|
|
it serves a somewhat different purpose though.
Turing: |
Draw.Line(100, 100, 100, 200, black)
Draw.Line(100, 200, 200, 200, black)
Draw.Line(200, 200, 100, 100, black)
Draw.Fill(150, 175, red, black)
Draw.Line(300, 100, 300, 200, black)
Draw.Line(300, 200, 400, 200, black)
Draw.Line(400, 200, 300, 100, black)
ChangeDotColorArea (275, 75, 425, 125, red, white)
|
also, there's a problem with the interpretation of Y2Value |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
![](images/spacer.gif) |
The_Bean
![](http://compsci.ca/v3/uploads/user_avatars/8459755754b4009cee84e9.jpg)
|
Posted: Mon Mar 02, 2009 9:39 pm Post subject: Re: A different Draw.Fill |
|
|
A lot simpler way would be...
Turing: |
proc ColourReplace (x1, y1, x2, y2, c1, c2 : int)
for x : x1 .. x2
for y : y1 .. y2
if View.WhatDotColour (x, y ) = c2 then
Draw.Dot (x, y, c1 )
end if
end for
end for
end ColourReplace
|
Fewer lines of code, and the y value is correct. |
|
|
|
|
![](images/spacer.gif) |
The_Bean
![](http://compsci.ca/v3/uploads/user_avatars/8459755754b4009cee84e9.jpg)
|
Posted: Mon Mar 02, 2009 11:20 pm Post subject: Re: A different Draw.Fill |
|
|
Heres an attempt at what I think you're trying to get at. It's a Draw.Fill() but instead of going over every colour within another colour, it branches out from the given point replacing the colour you want with a different colour until it can't go anymore. It's made using an idea from A* path finding to make it more efficient, but it's still fairly slow.
Turing: |
View.Set ("graphics:500,500")
module Fill
export FillArea
type coor :
record
x, y : int
end record
var open_list : flexible array 1 .. 0 of coor
var curr : coor
proc Next (x, y, c1, c2 : int)
if View.WhatDotColour (x, y ) = c2 then
Draw.Dot (x, y, c1 )
new open_list, upper (open_list ) + 1
open_list (upper (open_list )).x := x
open_list (upper (open_list )).y := y
end if
end Next
proc FillArea (x, y, c1, c2 : int)
new open_list, 1
open_list (1).x := x
open_list (1).y := y
loop
exit when upper (open_list ) = 0
curr.x := open_list (upper (open_list )).x
curr.y := open_list (upper (open_list )).y
new open_list, upper (open_list ) - 1
Next (curr.x + 1, curr.y, c1, c2 )
Next (curr.x - 1, curr.y, c1, c2 )
Next (curr.x, curr.y + 1, c1, c2 )
Next (curr.x, curr.y - 1, c1, c2 )
end loop
end FillArea
end Fill
Draw.MapleLeaf (0, 0, maxx, maxy, 7)
Fill.FillArea (maxx div 2, maxy div 2, 12, 0)
cls
Draw.Oval (maxx div 2, maxy div 2, maxx div 2, maxy div 2, 7)
Fill.FillArea (maxx div 2, maxy div 2, 12, 0)
cls
Draw.Star (0, 0, maxx, maxy, 7)
Fill.FillArea (maxx div 2, maxy div 2, 12, 0)
|
|
|
|
|
|
![](images/spacer.gif) |
copthesaint
![](http://compsci.ca/v3/uploads/user_avatars/15853548854c9c056fda48d.jpg)
|
Posted: Tue Mar 03, 2009 8:41 am Post subject: Re: A different Draw.Fill |
|
|
Duhh
The_Bean wrote:
A lot simpler way would be...
Turing: |
proc ColourReplace (x1, y1, x2, y2, c1, c2 : int)
for x : x1 .. x2
for y : y1 .. y2
if View.WhatDotColour (x, y ) = c2 then
Draw.Dot (x, y, c1 )
end if
end for
end for
end ColourReplace
|
Fewer lines of code, and the y value is correct.
Yea obvious also thanks for example of flexible array. I'll spend an hour and learn about it.
(already understand it just have to learn using it) |
|
|
|
|
![](images/spacer.gif) |
|
|