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

Username:   Password: 
 RegisterRegister   
 Making a Paint Program
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
NappingCondor




PostPosted: Wed May 30, 2012 8:12 am   Post subject: Making a Paint Program

Making a Paint Program

What is the problem you are having?
I have the basic gist of it, I think. I'm very new to turing (Gr. 11 Computer Science class...), and I've got your basic paint brush, colour selection, eraser, etc.. But when I go and try adding things like a circle that follows the mouse that shows exactly where you're drawing, and a "size scroller" (I don't know what else to call it... it's like that little scrolly guage thing in Photoshop that you can click and drag at the top of the screen to change the size), I run into the problem of needing to keep the picture the user is drawing on screen, but needing to clear other parts of the screen in order to keep the above mentioned functions working without leaving a trail of obtrusive, useless images. I hope that made sense ^^;. I'll post some code at the bottom so it's a little clearer.

Describe what you have tried to solve this problem
I know that the cls command won't do me any good, because that erases the picture that the user is working on. One person in my class reccomended that I save the screen as an image and reload it every time the program goes through the loop. I went and figured out how to do that (clearing the screen at the end of the program, and reloading the image at the beginning of the loop), and it works, but the lag is so spectacularly slow that it's hardly worth it.

Code:
Below, I've posted the code I've been fiddling with in trying to find a solution to making the size scroller guage thing work. Without the parts in the comment range it works fine, but it would delete everything the user is drawing. When uncommented, it lags. Help, anyone?

Turing:


View.Set ("graphics:1000;750,offscreenonly")

var x, y : int := 100
var mousex, mousey, button : int
var size : int := 1

%var image : int
var size_scroller := Pic.FileNew ("Size Scroller.gif")


loop

    Mouse.Where (mousex, mousey, button)


    %Pic.ScreenSave (0, 0, maxx, maxy, "image.bmp")
    %image := Pic.FileNew ("image.bmp")
    %Pic.Save (image, "image.bmp")

    %Pic.Draw (image, 0, 0, picCopy)

    drawfillbox (99, 0, 100, maxy, blue)
    drawfillbox (310, 0, 311, maxy, blue)

    drawfilloval (500, 500, size, size, black)

    if (button = 1 and mousex > 100 and mousex < 300 and mousey > 600 and mousey < 610) then
        Pic.Draw (size_scroller, mousex, 600, picMerge)
        x := mousex
    else
        Pic.Draw (size_scroller, x, 600, picMerge)
    end if

    size := 2 * (1 + x - 99)

    View.Update

    cls

end loop


Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
jr5000pwp




PostPosted: Wed May 30, 2012 8:39 am   Post subject: RE:Making a Paint Program

All cls does is draw a filled box the size of the screen in the background colour, so what you can do is draw your own white boxes to clear parts of the screen.
Aange10




PostPosted: Wed May 30, 2012 10:33 am   Post subject: RE:Making a Paint Program

Well, your friend may have been onto something. You're making a new file everytime you want to save the screen, however Turing has a way to just take the screen and save it without making a new file. At first I figured it would be slow, but it seems it takes (on my computer) 4 to 5 miliseconds to both capture the picture, and free the picture.

Turing:

% Draw a few colors
for i : 0 .. maxy div 2
    drawfillbox (0 + i, 0 + i, maxx - i, maxy - i, 1 + i)
end for
var myPic : int

fcn timeTakes () : int
    var startingTime : int
    startingTime := Time.Elapsed ()
    myPic := Pic.New (0, 0, maxx, maxy)
    Pic.Free (myPic)
    result Time.Elapsed () - startingTime
end timeTakes

var times : array 0 .. 990 of int
for i : 0 .. 990
    times (i) := timeTakes ()
end for

View.Set ("text")
for i : 0 .. 990
    put times (i)
end for


So instead of using Pic.ScreenSave and Pic.FileNew, just use Pic.New. But do remember to Pic.Free just before you get a new picture, so that you don't waste memory/fill up memory, because after 1000 pictures turing will terminate.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: