shortening code: loading bar
Author |
Message |
iii
|
Posted: Sun Jan 10, 2010 7:18 pm Post subject: shortening code: loading bar |
|
|
What is it you are trying to achieve?
Making lines that displays like a loading bar.
What is the problem you are having?
I believe that my code is simply too long and complicated. I want to know if there's any way to shorten the code.
Describe what you have tried to solve this problem
I read in the forum that loading bars use for counters. I tried that and ended up getting mutiple errors. I don't really get how counters work in a loading bar though.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing: |
<proc border
Draw.FillBox (600, 450, 550, 451, black)
Draw.FillBox (0, 50, 50, 51, black)
delay (1000)
cls
Draw.FillBox (600, 450, 500, 451, black)
Draw.FillBox (0, 50, 100, 51, black)
delay (1000)
cls
Draw.FillBox (600, 450, 450, 451, black)
Draw.FillBox (0, 50, 150, 51, black)
delay (1000)
cls
Draw.FillBox (600, 450, 400, 451, black)
Draw.FillBox (0, 50, 200, 51, black)
delay (1000)
cls
Draw.FillBox (600, 450, 350, 451, black)
Draw.FillBox (0, 50, 250, 51, black)
delay (1000)
cls
Draw.FillBox (600, 450, 300, 451, black)
Draw.FillBox (0, 50, 300, 51, black)
end border>
|
Please specify what version of Turing you are using
4.1.1 |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Euphoracle
![](http://compsci.ca/v3/uploads/user_avatars/11170373664bf5f25f636f1.png)
|
|
|
|
![](images/spacer.gif) |
iii
|
Posted: Sun Jan 10, 2010 7:40 pm Post subject: Re: shortening code: loading bar |
|
|
Turing: |
for i: 0 .. 100
drawFrame(i)
sleep(50)
end for
|
Thank you for the link but can you please explain it? I'm afraid I don't quite get what 'sleep' stands for and why the counter is used. |
|
|
|
|
![](images/spacer.gif) |
syntax_error
![](http://compsci.ca/v3/uploads/user_avatars/196798963948cf16794b6e5.jpg)
|
Posted: Sun Jan 10, 2010 9:14 pm Post subject: RE:shortening code: loading bar |
|
|
Have you learned for loops if not F2 or the turing walkthough is your friend! |
|
|
|
|
![](images/spacer.gif) |
iii
|
Posted: Sun Jan 10, 2010 9:31 pm Post subject: Re: shortening code: loading bar |
|
|
Yeah, I have learnt it in school and already read the tutorial beforehand.
I still don't get how to use it for the loading bar.... |
|
|
|
|
![](images/spacer.gif) |
TheGuardian001
|
Posted: Sun Jan 10, 2010 9:47 pm Post subject: Re: shortening code: loading bar |
|
|
I think you may have missed the point of the article... |
|
|
|
|
![](images/spacer.gif) |
iii
|
Posted: Sun Jan 10, 2010 9:50 pm Post subject: Re: shortening code: loading bar |
|
|
Mine is technically not a loading bar but is used for decoration; there are things for the user to do. I just think my code is too long. |
|
|
|
|
![](images/spacer.gif) |
iii
|
Posted: Sun Jan 10, 2010 9:58 pm Post subject: Re: shortening code: loading bar |
|
|
I decided you guys are right. Argh, without a loading bar, life is so much easier. Thank you for your help and sorry I kinda wasted your time. |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
Euphoracle
![](http://compsci.ca/v3/uploads/user_avatars/11170373664bf5f25f636f1.png)
|
Posted: Sun Jan 10, 2010 10:35 pm Post subject: RE:shortening code: loading bar |
|
|
My post was trying to convey the point that unless you are loading something, you needn't use a loading bar.
However, I will give a more general explanation of animating a line.
I'm going to use a counter to repeat some code, its commented for explanation:
Turing: | % stops flickering; use with View.Update
setscreen ("offscreenonly")
% this is what i use to draw the animated circle border
proc animate_circle_border
(ox, oy, rad,
start_color, end_color, color_span, % these are the paramters i use so i can customize
roughness, thickness, tick : int) % the output without changing the function
for i : 0 .. 360 by roughness % this is my counter. it lets me repeat something while
% keeping track of how much ive done thus far. by x
% just tells it to skip every x numbers
% this is just circular math stuff dont worry about it
var x1 := round (sind (i + tick ) * rad )
var y1 := round (cosd (i + tick ) * rad )
var x2 := round (sind (i + tick + roughness ) * rad )
var y2 := round (cosd (i + tick + roughness ) * rad )
% #! im adding tick here because it
% lets me make my animation look different each time
% i call this draw function... think of it as the frame
% counter in a movie
% picking a color
var c := start_color + ((i div roughness ) div color_span )
if (c > end_color ) then
c := end_color
end if
% draw my shape
Draw.ThickLine (ox + x1, oy + y1, ox + x2, oy + y2, thickness, c )
end for
end animate_circle_border
% this keeps track of my animation progress i use this in my drawing
% function to make it draw differently each call (illusion of motion)
var tick := 0
% this is my drawing loop
loop
% clear the screen
cls
% incriment my progress; dont worry about this - 15 mod 360 stuff thats
% just how i want my progress to be for the math to work in my drawing function
% you would be perfectly fine increasing/decreasing however you wish
tick := (tick - 15) mod 360
% draw my frame, note im passing tick to it... this is so in my function i can
% let it draw differently (see #!)
animate_circle_border (maxx div 2, maxy div 2, 100, 21, 31, 15, 1, 3, tick )
% update the screen
View.Update
% delay for a while (so it doesn't all happen as fast as turing can draw)
% im usign delaysincelast here because if the animation takes longer to draw
% i want to delay less (so it looks like its moving at a uniform speed)
Time.DelaySinceLast (30)
end loop
|
|
|
|
|
|
![](images/spacer.gif) |
iii
|
Posted: Sun Jan 10, 2010 11:17 pm Post subject: Re: shortening code: loading bar |
|
|
Thank you so much! |
|
|
|
|
![](images/spacer.gif) |
|
|