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

Username:   Password: 
 RegisterRegister   
 need help to reduce flickering
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Ghostblade




PostPosted: Wed May 15, 2013 12:59 pm   Post subject: need help to reduce flickering

What is it you are trying to achieve?
reduce flickering


What is the problem you are having?
flickering like a mofo


Describe what you have tried to solve this problem
added cls, view.update, offscreenonly all dont work when i try them.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


%####SETSCREEN###%
setscreen("graphics:max;max")
View.Update

%#######VARS#######%
var posy1 :int:=200
var posx2 : int:= 400
var motorboat : int := Pic.FileNew ("motor boat.bmp")
var handwavex : int := maxx - 270
var handwavey : int := 265
var handwave : int := 5
var T : int := 14
var p, SunCount : int := 0

process boat
loop
cls
View.Update


    %%################ SUN ###############%
Draw.FillOval (300, 550, 85, 85, T)
    Draw.Oval (300, 550, 90, 90, T)
    Draw.Oval (300, 550, 97, 97, T)
    Draw.Oval (300, 550, 107, 107, T)

   if SunCount <= 40 then
        T := 14
    elsif SunCount <= 80 then
        T := 43
    elsif SunCount <= 120 then
        T := 42
    end if
    if SunCount = 120 then
        SunCount := 0
    end if
    SunCount := SunCount + 1

Draw.FillOval (470,-20,900,200,66)
drawfillbox (0,425,maxx,120,9)

%####BOAT#####%
Pic.Draw (motorboat,posx2,posy1,picMerge)
posx2 := posx2-1

delay (100)
end loop
end boat

View.Update

%###############Hand Wave Variables###################%


process person
loop
 
%##############Person#################%
    drawfillbox (maxx - 200, 100, maxx - 250, 225, 2) %Top
    drawfilloval (maxx - 225, 225, 50, 50, 90) %Head
    Draw.ThickLine (maxx - 200, 170, maxx - 185, 125, 5, 7) %Left Arm
    drawfilloval (maxx - 245, 225, 5, 5, 7) %Left Eye
    drawfilloval (maxx - 205, 225, 5, 5, 7) %Right Eye
    drawarc (maxx - 225, 205, 5, 5, 180, 360, 7) %Smile
    drawarc (maxx - 220, 210, 5, 5, 180, 360, 7)
    drawarc (maxx - 230, 210, 5, 5, 180, 360, 7)
    Draw.ThickLine (maxx - 200, 100, maxx - 190, 50, 5, 7) %Left Leg
    Draw.ThickLine (maxx - 250, 100, maxx - 260, 50, 5, 7) %Right Leg
   
    delay (100)

    %######################Waving Arm####################%

    Draw.ThickLine (maxx - 250, 170, handwavex, handwavey, 5, 7)
   
   handwavex := handwavex - handwave

   handwavey := handwavey - handwave

if handwavex < maxx - 300 then
        handwave := -handwave

        elsif handwavex > maxx - 260 then
        handwave := -handwave
   
end if


end loop
end person
fork person
fork boat




Please specify what version of Turing you are using
latest?
Sponsor
Sponsor
Sponsor
sponsor
Ghostblade




PostPosted: Wed May 15, 2013 1:00 pm   Post subject: RE:need help to reduce flickering

please fix i've been trying forever to fix!!1
Panphobia




PostPosted: Wed May 15, 2013 1:02 pm   Post subject: RE:need help to reduce flickering

code:
setscreen("offscreenonly")
Tony




PostPosted: Wed May 15, 2013 2:52 pm   Post subject: Re: need help to reduce flickering

Ghostblade @ Wed May 15, 2013 12:59 pm wrote:

added cls, view.update, offscreenonly all dont work when i try them.
...
fork person
fork boat

You don't understand View.Update and/or forks.

This is particularly interesting.
Quote:

cls
View.Update
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Ghostblade




PostPosted: Thu May 16, 2013 12:51 pm   Post subject: RE:need help to reduce flickering

a friend added the forks (this guy knows his stuff) not me and yea i dont understand a thing... my teacher goes on the method of learn yourself and ive been here for like two months. i just need help, this is my summative its due in a week!!!
Nathan4102




PostPosted: Thu May 16, 2013 12:58 pm   Post subject: RE:need help to reduce flickering

That's what happens when you slack off in class. You should read the Turing Docs pages on "fork", "View.Update" and "View.Set", specifically the "offscreenonly" section. Forks aren't the best method, but they'll work. My personal preference is to have procedures for both events inside a conditional loop (The "loop/end loop" loop). Good luck!
Ghostblade




PostPosted: Thu May 16, 2013 1:22 pm   Post subject: RE:need help to reduce flickering

the guy isnt in my class..... he does courses in the summer during his own free time. I dont slack off, as i said earlier, i must teach myself. ive found a way to reduce the flicker but i need to add some sort of cls because my animations leave a trail. this is my code:
%############Loading Screen#############%

var loadPercent : int := 0
var loadingMessage : string := ""


proc load1 ()
loadingMessage := "Loading Screen"
delay (10)
loadPercent += 10
end load1

proc load2 ()
loadingMessage := "Loading Objects"
delay (15)
loadPercent += 15
end load2

proc load3 ()
loadingMessage := "Loading Animations"
delay (20)
loadPercent += 50
end load3

proc load4 ()
loadingMessage := "Loading Pure Awesomeness"
delay (25)
loadPercent += 25
end load4


process loadGameProcess ()
load1 ()
load2 ()
load3 ()
load4 ()
loadingMessage := "DONE"
end loadGameProcess


proc loadGame ()
fork loadGameProcess

% Display Loading Bar
var loadingPercentFont : int := Font.New ("sans serif:16:bold")
var loadingMessageFont : int := Font.New ("sans serif:24:bold")

loop
View.Update ()
Time.DelaySinceLast (100)
Draw.Cls

Font.Draw ( loadingMessage, 30, maxy div 2 + 40, loadingMessageFont, black )

% The actual bar and the percentage listed for it
Draw.FillBox (0, maxy div 2 + 15, maxx, maxy div 2 + 20, black )
Draw.FillBox (0, maxy div 2 - 15, maxx, maxy div 2 - 20, black )
Draw.FillBox (0, maxy div 2 - 15, round (maxx / 100 * loadPercent), maxy div 2 + 15, darkgrey)
Font.Draw ( intstr(loadPercent)+"%", maxx div 2 - 8, maxy div 2 - 8, loadingPercentFont, brightred )

exit when loadPercent >= 100
end loop


end loadGame


loadGame


%####SETSCREEN###%
setscreen("graphics:max;max")
View.Update

%#######VARS#######%
var posy1 :int:=200
var posx2 : int:= 400
var motorboat : int := Pic.FileNew ("motor boat.bmp")
var handwavex : int := maxx - 270
var handwavey : int := 265
var handwave : int := 5
var newcolour : int := 205

%################ MOON ###############
process moon
loop
View.Update
Draw.FillOval (470,-20,900,200,66)
drawfillbox (0,425,maxx,120,9)
drawfillbox (0,800,maxx,400,104)

RGB.SetColor (newcolour, 0, 0, 53)

for T : 44..68

Draw.FillOval (110,550,100,100, T)
Draw.FillOval (140,550,80,80,104)


newcolour -= RGB.AddColor (0, 0, 2)

delay (100)

end for
end loop
end moon

%####BOAT#####%
process boat
loop

View.Update

Pic.Draw (motorboat,posx2,posy1,picMerge)
posx2 := posx2-1

delay (100)
end loop
end boat

View.Update

%#######PERSON#########%
process person
loop

drawfillbox (maxx - 200, 100, maxx - 250, 225, 2) %Top
drawfilloval (maxx - 225, 225, 50, 50, 90) %Head
Draw.ThickLine (maxx - 200, 170, maxx - 185, 125, 5, 7) %Left Arm
drawfilloval (maxx - 245, 225, 5, 5, 7) %Left Eye
drawfilloval (maxx - 205, 225, 5, 5, 7) %Right Eye
drawarc (maxx - 225, 205, 5, 5, 180, 360, 7) %Smile
drawarc (maxx - 220, 210, 5, 5, 180, 360, 7)
drawarc (maxx - 230, 210, 5, 5, 180, 360, 7)
Draw.ThickLine (maxx - 200, 100, maxx - 190, 50, 5, 7) %Left Leg
Draw.ThickLine (maxx - 250, 100, maxx - 260, 50, 5, 7) %Right Leg

delay (100)

%######################Waving Arm####################%

Draw.ThickLine (maxx - 250, 170, handwavex, handwavey, 5, 7)

handwavex := handwavex - handwave

handwavey := handwavey - handwave

if handwavex < maxx - 300 then
handwave := -handwave

elsif handwavex > maxx - 260 then
handwave := -handwave

end if


end loop
end person

fork person
fork boat
fork moon
Nathan4102




PostPosted: Thu May 16, 2013 1:32 pm   Post subject: RE:need help to reduce flickering

I don't think it's possible to remove the trail without excessive flickering using forks. All these processes are running independent of eachother, so you can't say "Once they've all been drawn, update the screen and clear the buffer". Again, I suggest procedures.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu May 16, 2013 1:46 pm   Post subject: Re: RE:need help to reduce flickering

Ghostblade @ Thu May 16, 2013 12:51 pm wrote:
a friend added the forks (this guy knows his stuff) not me and yea i dont understand a thing...

Don't forget to add a citation for his contributions to your project.

You can then ask him to explain why forks can't work with view.update without implementing synchronization.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Ghostblade




PostPosted: Fri May 17, 2013 11:34 am   Post subject: RE:need help to reduce flickering

ok thanks guys!
Raknarg




PostPosted: Fri May 17, 2013 11:45 am   Post subject: RE:need help to reduce flickering

Is it possible to synchronize processes, tony?
Ghostblade




PostPosted: Fri May 17, 2013 12:06 pm   Post subject: RE:need help to reduce flickering

im using loops now and all is good no flickering but for some reason ONLY my first loop and background show up? should i put them all in one large loop with procs inside?
Ghostblade




PostPosted: Fri May 17, 2013 12:15 pm   Post subject: RE:need help to reduce flickering

current code:


%############Loading Screen#############%

var loadPercent : int := 0
var loadingMessage : string := ""


proc load1 ()
loadingMessage := "Loading Mohammed's Summative"
delay (10)
loadPercent += 10
end load1

proc load2 ()
loadingMessage := "Loading Objects"
delay (15)
loadPercent += 15
end load2

proc load3 ()
loadingMessage := "Loading Animations"
delay (20)
loadPercent += 50
end load3

proc load4 ()
loadingMessage := "Loading Background"
delay (25)
loadPercent += 25
end load4


process loadGameProcess ()
load1 ()
load2 ()
load3 ()
load4 ()
loadingMessage := "DONE"
end loadGameProcess


proc loadGame ()
fork loadGameProcess

% Display Loading Bar
var loadingPercentFont : int := Font.New ("sans serif:16:bold")
var loadingMessageFont : int := Font.New ("sans serif:24:bold")

loop
View.Update ()
Time.DelaySinceLast (100)
Draw.Cls

Font.Draw ( loadingMessage, 30, maxy div 2 + 40, loadingMessageFont, black )

% The actual bar and the percentage listed for it
Draw.FillBox (0, maxy div 2 + 15, maxx, maxy div 2 + 20, black )
Draw.FillBox (0, maxy div 2 - 15, maxx, maxy div 2 - 20, black )
Draw.FillBox (0, maxy div 2 - 15, round (maxx / 100 * loadPercent), maxy div 2 + 15, darkgrey)
Font.Draw ( intstr(loadPercent)+"%", maxx div 2 - 8, maxy div 2 - 8, loadingPercentFont, brightred )

exit when loadPercent >= 100
end loop


end loadGame


loadGame


%####SETSCREEN###%
setscreen("graphics:max;max")
View.Update
setscreen ("offscreenonly")
cls
%#######VARS#######%
var posy1 :int:=200
var posx2 : int:= 400
var motorboat : int := Pic.FileNew ("motor boat.bmp")
var handwavex : int := maxx - 270
var handwavey : int := 265
var handwave : int := 5
var newcolour : int := 205
var X, Y : int := 700
var R1, R2 : int := 1
var DX, DY : int := -1

var A, B : int :=700
var C1, C2 : int :=1
var DA, DB : int :=-1

%################ MOON ###############

loop

loop
View.Update
Draw.FillOval (470,-20,900,200,66)
drawfillbox (0,425,maxx,120,9)
drawfillbox (0,800,maxx,400,104)

RGB.SetColor (newcolour, 0, 0, 53)

for T : 44..68

Draw.FillOval (110,550,100,100, T)
Draw.FillOval (140,550,80,80,104)


newcolour -= RGB.AddColor (0, 0, 2)


View.Update
delay (100)


end for
end loop


%####BOAT#####%


loop

Pic.Draw (motorboat,posx2,posy1,picMerge)
posx2 := posx2-1

delay (200)
end loop


View.Update

%#######PERSON#########%

loop

drawfillbox (maxx - 200, 100, maxx - 250, 225, 2) %Top
drawfilloval (maxx - 225, 225, 50, 50, 90) %Head
Draw.ThickLine (maxx - 200, 170, maxx - 185, 125, 5, 7) %Left Arm
drawfilloval (maxx - 245, 225, 5, 5, 7) %Left Eye
drawfilloval (maxx - 205, 225, 5, 5, 7) %Right Eye
drawarc (maxx - 225, 205, 5, 5, 180, 360, 7) %Smile
drawarc (maxx - 220, 210, 5, 5, 180, 360, 7)
drawarc (maxx - 230, 210, 5, 5, 180, 360, 7)
Draw.ThickLine (maxx - 200, 100, maxx - 190, 50, 5, 7) %Left Leg
Draw.ThickLine (maxx - 250, 100, maxx - 260, 50, 5, 7) %Right Leg

delay (100)

%######################Waving Arm####################%

Draw.ThickLine (maxx - 250, 170, handwavex, handwavey, 5, 7)

handwavex := handwavex - handwave

handwavey := handwavey - handwave

if handwavex < maxx - 300 then
handwave := -handwave

elsif handwavex > maxx - 260 then
handwave := -handwave

end if


end loop


%####SHOOTINGSTAR####%

loop

drawfilloval (X, Y, R1, R2, 31)
delay (2)
drawfilloval (X, Y, R1, R2, 31)
X := X + DX
Y := Y + DY
exit when X=400
end loop
delay (200)
loop
drawfilloval (A, B, C1, C2, 127)
delay (2)
drawfilloval (A, B, C1, C2, 127)
A :=A+DA
B :=B+DB
exit when A=400
end loop

end loop
DemonWasp




PostPosted: Fri May 17, 2013 1:56 pm   Post subject: Re: RE:need help to reduce flickering

Raknarg @ Fri May 17, 2013 11:45 am wrote:
Is it possible to synchronize processes, tony?


Possible? Yes. You can use either Dekker's algorithm if Turing's assignment isn't atomic or Peterson's algorithm is assignment is atomic. These are typically covered by a university-level CS course (CS343 Concurrent and Parallel, at UWaterloo)

Based on those, you can implement critical sections. With critical sections, you should be able to implement a Barrier, and Locks, which should allow you to synchronize these methods.

However, it's completely pointless because Turing doesn't actually provide multithreaded execution of Turing code. The Turing runtime actually uses 3-4 threads but I expect that most of those are internal (to handle playing music and Turing's own GUI), while one handles running the program running inside Turing.

You would be introducing a LOT of problems and complexity for a guaranteed loss in performance.

Just use procedures.

Edit: had to fix up links because the forum doesn't seem to like apostrophes or brackets (') in URL entries.
Nathan4102




PostPosted: Fri May 17, 2013 3:04 pm   Post subject: RE:need help to reduce flickering

@Demon, are you sure Turing uses a dedicated thread for forked music? I've made programs that run at 25% speed when music is playing, it's horrible!

@Ghost, could you put the code with indentation in turing syntax tags?
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 2  [ 17 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: