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

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




PostPosted: Tue May 18, 2004 5:51 pm   Post subject: Drawing Program

How do i make it so that the pen does not erase the lines that you already draw?

code:
setscreen ("graphics:640;480")

var drawx : int := 320
var drawy : int := 150
var draw : int := 0

%pictures
var penOut : int := Pic.FileNew ("penOut.bmp")
var penIn : int := Pic.FileNew ("penIn.bmp")
var blank : int := Pic.FileNew ("blank.bmp")

% The array used to check the keys
var keys : array char of boolean

proc control
    if keys (KEY_LEFT_ARROW) then
        drawx -= 1
    end if
    if keys (KEY_UP_ARROW) then
        drawy += 1
    end if
    if keys (KEY_RIGHT_ARROW) then
        drawx += 1
    end if
    if keys (KEY_DOWN_ARROW) then
        drawy -= 1
    end if
    if keys (KEY_CTRL) then
        draw := 1
    end if
    if keys (KEY_ALT) then
        draw := 0
    end if
end control


%-------------------------------------------------------------------------------------------

setscreen ("offscreenonly")
loop
    Input.KeyDown (keys)
    locatexy (550, 470)
    put "x:", drawx, " y:", drawy ..
    control
    if draw = 0 then
        Pic.Draw (penIn, drawx, drawy, picMerge)
    elsif draw = 1 then
        Pic.Draw (penOut, drawx, drawy, picMerge)
        drawdot (drawx-1, drawy-1,black)
    end if
    delay (3)
    View.Update
end loop



PenIn.bmp
 Description:
first pic
 Filesize:  24.65 KB
 Viewed:  2566 Time(s)

PenIn.bmp



PenOut.bmp
 Description:
second pic
 Filesize:  24.65 KB
 Viewed:  2566 Time(s)

PenOut.bmp


Sponsor
Sponsor
Sponsor
sponsor
mynameisbob




PostPosted: Tue May 18, 2004 5:52 pm   Post subject: (No subject)

i forgot to add, press CTRL to start drawing
Dan




PostPosted: Wed May 19, 2004 1:06 pm   Post subject: (No subject)

this is not as easy as it used to be to do since sprites where taken away, but since i have been working on remaking i have lreaned a few tricks to get past this.

what you got to do is save the drawing made by the pen but not the pen b/c it will draw over the drawing.

I tryed this trick in your code and it worked:

code:

setscreen ("graphics:640;480")

var drawx : int := 320
var drawy : int := 150
var draw : int := 0

%pictures
var penOut : int := Pic.FileNew ("penOut.bmp")
var penIn : int := Pic.FileNew ("penIn.bmp")
var blank : int := Pic.FileNew ("blank.bmp")

% The array used to check the keys
var keys : array char of boolean

proc control
    if keys (KEY_LEFT_ARROW) then
        drawx -= 1
    end if
    if keys (KEY_UP_ARROW) then
        drawy += 1
    end if
    if keys (KEY_RIGHT_ARROW) then
        drawx += 1
    end if
    if keys (KEY_DOWN_ARROW) then
        drawy -= 1
    end if
    if keys (KEY_CTRL) then
        draw := 1
    end if
    if keys (KEY_ALT) then
        draw := 0
    end if
end control


%-------------------------------------------------------------------------------------------

setscreen ("offscreenonly")
var back:int:=Pic.New (0, 0, maxx, maxy)

loop
    Input.KeyDown (keys)
    locatexy (550, 470)
    put "x:", drawx, " y:", drawy ..
    control
   
    Pic.Draw(back,0,0,picCopy)
    if draw = 1 then
        drawdot (drawx-1, drawy-1,black)
    end if
    Pic.Free(back)
    back := Pic.New(0,0,maxx,maxy)
   
    if draw = 0 then
        Pic.Draw (penIn, drawx, drawy, picMerge)
    elsif draw = 1 then
        Pic.Draw (penOut, drawx, drawy, picMerge)
       
    end if
   
    delay (3)
    View.Update
end loop


cool eh? and that is also the basick idea behind sprites.
Computer Science Canada Help with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
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: