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

Username:   Password: 
 RegisterRegister   
 semi shading?
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
MihaiG




PostPosted: Sat Feb 25, 2006 1:47 pm   Post subject: semi shading?

well this is sortoff a shading program i am working on.....its ok so far..

but i need some tips on optimizing...

and i cant get it to work so u draw in -y or - x direction from where mosue is clicked and dragged

and how can i make it more efficient Question

code:
setscreen ("graphics:max;max")
var mx, my, mb : int

proc shade (x1, y1, x2, y2 : int, col : int)
    for decreasing j : y2 .. y1 by 3
        for i : x1 .. x2 by 3
            Draw.Dot (i, j, col)
        end for
    end for
    for decreasing j : y2 - 1 .. y1 by 3
        for i : x1 + 1 .. x2 - 1 by 3
            Draw.Dot (i, j, col)
        end for
    end for
end shade

var temp := 1
var x1, y1, x2, y2 : int := 0
var chars : array char of boolean

Pic.ScreenLoad ("C:/water.jpg", 100, 100, picUnderMerge)%add a picture to see a bit how it works
loop
    Mouse.Where (mx, my, mb)

    Input.KeyDown (chars)
    if chars ('t') then
        put "The T key is pressed"
    end if
    if mb = 1 and temp = 1 then
        x1 := mx
        y1 := my
        temp := 0
    elsif mb = 1 and temp = 0 then
        x2 := mx
        y2 := my
        shade (x1, y1, x2, y2, 15)
    elsif mb = 0 then
        temp := 1
    end if

end loop

Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Mon Feb 27, 2006 10:35 am   Post subject: (No subject)

For your shade proc, try this instead:

code:

proc shade (x1, y1, x2, y2 : int, col : int)
    for i : min (x1, x2) .. max (x1, x2) by 3
        for j : min (y1, y2) .. max (y1, y2) by 3
            Draw.Dot (i, j, col)
        end for
    end for
    % etc
end shade


Neat, eh?

Now, for your main loop, look into Mouse.ButtonWait() and Mouse.ButtonMoved(). Specifically, look at the example that comes with F10. You should be able to edit that to get something. The best I was able to come up with (without too much work) was one where you click at one point, drag, release, and a clean shading is drawn. The only set back was that there was no indicator as to where the box would start and end...but that's not too difficult to get around.

No, not posting my code was not a mistake...I'll let you mull over it a little bit before I do that. Uh, if I do...
MihaiG




PostPosted: Mon Feb 27, 2006 6:41 pm   Post subject: (No subject)

well...you read my mind... i am working on that kind of program like drag and release...but i want to make it so when you draw and move the mouse the shading gradient thingy doesn change and it doesnt look like grey lines but grey dots.. Arrow
batman




PostPosted: Thu Mar 02, 2006 9:00 pm   Post subject: Shading program

Your shading program didn"t work on my computer. Nothing was outputed on the output screen.
[Gandalf]




PostPosted: Thu Mar 02, 2006 9:43 pm   Post subject: (No subject)

If it doesn't work, that is your computer's fault. More likely, you didn't check to see what the program does. It doesn't output anything by default, try clicking around with the mouse, clicking and dragging.
batman




PostPosted: Thu Mar 02, 2006 9:50 pm   Post subject: shading program

Oh! Ok after I clicked around and did it the right way this time, the program is pretty cool. Its easier for some reason to shade in the middle part of the screen then in the far end corners though.
DaftPunk




PostPosted: Thu Mar 02, 2006 11:45 pm   Post subject: Cool

This little code is pretty cool. Although on my screen it only shows up the first time I drag and drop. What are you planning on doing with it? Just shading pics?
Booya




PostPosted: Sun Mar 05, 2006 7:08 pm   Post subject: Shading Program

Awesome shading program your really talented at turing.
Sponsor
Sponsor
Sponsor
sponsor
do_pete




PostPosted: Tue Mar 07, 2006 1:47 pm   Post subject: (No subject)

You could try something like this, but it is too slow to be practicle
code:
proc shade (x1, y1, x2, y2 : int, col : int)
    for i : min (x1, x2) .. max (x1, x2)
        for j : min (y1, y2) .. max (y1, y2)
            var Colour : int
            var r, g, b : real
            var Colour2 : int
            Colour := whatdotcolour (i, j)
            RGB.GetColour (Colour, r, g, b)
            Colour2 := RGB.AddColour (r / 2, g / 2, b / 2)
            Draw.Dot (i, j, Colour2)
        end for
    end for
end shade
MihaiG




PostPosted: Tue Mar 07, 2006 8:18 pm   Post subject: (No subject)

ya...ur combining olours...thats really slow...and u rdoing it for eveyr pixel


do it for eveyr other one and i twould run way faster.. Smile
MysticVegeta




PostPosted: Wed Mar 08, 2006 10:47 pm   Post subject: (No subject)

yes but then it loses its effect too =\
do_pete




PostPosted: Thu Mar 09, 2006 12:37 pm   Post subject: (No subject)

Is there a way to make it quicker without losing the effect?
MihaiG




PostPosted: Thu Mar 09, 2006 6:50 pm   Post subject: (No subject)

think about it


if u drag a box 10x10 its 100 pixels so ur doing that calculation 100 times...ok.



lets say ur box is 100,100 = 10,000

that starts to get really slow

and finaly if our box is 400,700

its 280,000 pixels it has to calculate


so its gonna be very inneficient Sad
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  [ 13 Posts ]
Jump to:   


Style:  
Search: