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

Username:   Password: 
 RegisterRegister   
 Questions about View.Update and process
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Hannah




PostPosted: Tue Dec 27, 2005 4:40 pm   Post subject: Questions about View.Update and process

Hello guys! My name is Hannah and I just registered in Compsci.

I started Turing about four months ago. But I don't know a lot about

turing. So I need some help.

First of all, I am working on my current project. And I need to make a car-

crash-program.

Here's my code:
code:

%-------------------
%Visuals Start Here
%-------------------
put "Loading. Please Wait"
%ROAD SETTINGS
%Draws the Background
var dot : int
var col : int
View.Set ("offscreenonly")
%Declares red, green and blue variables
var r, g, b : int
%Loop allows you where to draw the dots
for x : 1 .. maxx
    for y : 1 .. 400
        %Randomize red colour
        randint (r, 116, 146)
        %Randomize green color
        randint (g, 143, 170)
        %Radomize blue colour
        randint (b, 12, 23)
        %RBG Set colour program allows to you to mix the colours
        RGB.SetColour (2, r / 255.0, g / 255.0, b / 255.0)
        %draws randomized dots
        Draw.Line (x, y, x, y, 2)
    end for
end for
View.Update
%-------ROAD________________
%Declares red, green and blue variables
var rr, gg, bb : int
%Loop allows you where to draw the dots
for x1 : 0 .. 640
    for y1 : 66 .. 203
        %Randomize red colour
        randint (rr, 120, 140)
        %Randomize green color
        randint (gg, 120, 140)
        %Radomize blue colour
        randint (bb, 110, 140)
        %RBG Set colour program allows to you to mix the colours
        RGB.SetColour (20, rr / 255.0, gg / 255.0, bb / 255.0)
        %draws randomized dots
        Draw.Dot (x1, y1, 20)
    end for
end for
View.Update
%Declares red, green and blue variables
var aa, ga, bsa : int
%Loop allows you where to draw the dots
for x1sa : 350 .. 475
    for y1sa : 200 .. 400
        %Randomize red colour
        randint (aa, 120, 140)
        %Randomize green color
        randint (ga, 120, 140)
        %Radomize blue colour
        randint (bsa, 110, 140)
        %RBG Set colour program allows to you to mix the colours
        RGB.SetColour (20, aa / 255.0, ga / 255.0, bsa / 255.0)
        %draws randomized dots
        Draw.Dot (x1sa, y1sa, 20)
    end for
end for
View.Update

%Declares red, green and blue variables
var rra, gga, bba : int
%Loop allows you where to draw the dots
for x1a : 95 .. 205
    for y1a : 200 .. 400
        %Randomize red colour
        randint (rra, 120, 140)
        %Randomize green color
        randint (gga, 120, 140)
        %Radomize blue colour
        randint (bba, 110, 140)
        %RBG Set colour program allows to you to mix the colours
        RGB.SetColour (20, rra / 255.0, gga / 255.0, bba / 255.0)
        %draws randomized dots
        Draw.Dot (x1a, y1a, 20)
    end for
end for
View.Update
%Declares red, green and blue variables
var rra1, gga1, bba1 : int
%Loop allows you where to draw the dots
for x1a1 : 365 .. 475
    for y1a1 : 0 .. 95
        %Randomize red colour
        randint (rra1, 120, 140)
        %Randomize green color
        randint (gga1, 120, 140)
        %Radomize blue colour
        randint (bba1, 110, 140)
        %RBG Set colour program allows to you to mix the colours
        RGB.SetColour (20, rra1 / 255.0, gga1 / 255.0, bba1 / 255.0)
        %draws randomized dots
        Draw.Dot (x1a1, y1a1, 20)
    end for
end for
%End of the program
View.Update

%Road Line
Draw.ThickLine (0, 195, 90, 195, 5, white)
Draw.ThickLine (195, 195, 350, 195, 5, white)
Draw.ThickLine (475, 195, maxx, 195, 5, white)
Draw.ThickLine (0, 75, 365, 75, 5, white)
Draw.ThickLine (479, 75, maxx, 75, 5, white)
%Road Line 2
%Road Drawings End

%---------
%TRAFFIC DRAWINGS
%Draws traffic lights  Frame
drawfillbox (340, 290, 312, 215, 27)

drawline (334, 215, 334, 181, black)
drawfillbox (256, 61, 330, 30, 27)
drawbox (256, 61, 330, 30, black)
drawline (330, 30, 364, 30, black)
%Traffic Lights Lights
drawoval (325, 229, 7, 7, black)
drawoval (325, 250, 7, 7, black)
drawoval (325, 272, 7, 7, black)
drawoval (314, 45, 7, 7, black)
drawoval (294, 45, 7, 7, black)
drawoval (271, 45, 7, 7, black)
%Stop sign
%Draws stop sign

%Houses
%Draws blue house
drawfillbox (63, 218, 0, 400, blue)
drawline (63, 218, 0, 371, black)

%Draws ivory house
drawfillbox (500, 265, 640, 400, 89)
drawbox (500, 265, 640, 400, black)
drawline (499, 265, 584, 350, black)
drawline (584, 350, 639, 291, black)
drawline (584, 399, 584, 350, black)
%Draws velvet house
drawfillbox (495, 50, 640, 0, 133)
%Draws orange House
drawfillbox (5, 0, 160, 50, 52)
View.Update

%CAr1
%--------------------------
%----------CARS------------
%--------------------------
proc movcar
    drawfillbox (5, 100, 80, 150, 64)
end movcar
movcar
var face : array 1 .. sizepic (0, 99, 85, 152) of int
process a
    takepic (0, 99, 85, 152, face)
    for x : 0 .. 308 by 3
        drawpic (x, 100, face, 0)
        delay (5)
        exit when x = 308
    end for
end a
%------CAr2-----------------
process movcar2
    drawfillbox (390, 2, 455, 50, 64)
end movcar2

fork movcar2
fork a
var car : array 1 .. sizepic (380, 0, 456, 53) of int

takepic (380, 0, 456, 53, car)
for x : 0 .. 400
    drawpic (380, x, car, 0)
    delay (5)
    exit when x = 98
end for
[/quote]

So I wanted to make it fancy and I used RGB Setcolour command and

I drew roads. Then I took a picture of the box and moved

 it. But the program simply does not work. So, my question is, "How can I move the boxes like the example below?"


[quote]
drawfillbox (0,0,maxx,maxy,2)
drawfillbox (0,63,640,165,grey)
drawfillbox (350,0,460,165,grey)
%--------------------------
%----------CARS------------
%--------------------------

%----------CAR1----------

proc movcar
    drawfillbox (5, 100, 80, 150, 64)
end movcar
movcar
var face : array 1 .. sizepic (0, 99, 85, 152) of int
process a
    takepic (0, 99, 85, 152, face)
    for x : 0 .. 308 by 3
        drawpic (x, 100, face, 0)
        delay (100)
        exit when x = 308
    end for
end a
%------CAr2-----------------
process movcar2
    drawfillbox (390, 2, 455, 50, 64)
end movcar2

fork movcar2
fork a
var car : array 1 .. sizepic (380, 0, 456, 53) of int

takepic (380, 0, 456, 53, car)
for x : 0 .. 400
    drawpic (380, x, car, 0)
    delay (100)
    exit when x = 98
end for



Thank You very much and have a nice day!

P.S I read the "How to ask questions" article but I don't know if I followed proper format.-.-;;
Sponsor
Sponsor
Sponsor
sponsor
iker




PostPosted: Tue Dec 27, 2005 7:18 pm   Post subject: (No subject)

Maby a View.Update would help seeing as how you are using offscreenonly. Try putting it somewhere in the last set of lines and it should work Very Happy
Geminias




PostPosted: Thu Dec 29, 2005 2:51 pm   Post subject: (No subject)

first of all, nice program. I really like the graphics, you must have spent a lot of time.

your problem is the amount of delay between your two cars movement. You need to have some delay... But it doesn't end there, because you forked the process of the cars movement.

There are many ways to fix your problem, but i strongly advise changing the fundamental of your program and remove the forks and processes.

Instead put the cars movement in a procedure and use the view.update to update a certain part of the screen (the part of the screen your cars are moving in) That way your entire background wont have to keep reloading and things will run smoothly, and the best thing of all, you wont need processes and forks.

good luck
Albrecd




PostPosted: Fri Dec 30, 2005 1:56 pm   Post subject: (No subject)

Quote:
your problem is the amount of delay between your two cars movement


No, It's not.

Quote:
Maby a View.Update would help seeing as how you are using offscreenonly


Yes, It would. You need to put View.Update at the end of the last procedure, then the cars will move. The cars move quite quickly, so you may want to put in a delay for that (I think that's what Geminias may have been talking about) but just to slow them down, that's not the problem.

code:
%------CAr2-----------------
process movcar2
drawfillbox (390, 2, 455, 50, 64)
end movcar2

fork movcar2
fork a
var car : array 1 .. sizepic (380, 0, 456, 53) of int

takepic (380, 0, 456, 53, car)
for x : 0 .. 400
drawpic (380, x, car, 0)
delay (5)
exit when x = 98
View.Update
end for
Hannah




PostPosted: Sun Jan 01, 2006 6:44 pm   Post subject: Thanks

Thanks so much!
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  [ 5 Posts ]
Jump to:   


Style:  
Search: