Welcome back.
In this last step, we're going to create the clock animation that lasts.
All right, let's get started.
All right, let's take a look at the goals first.
All right, now we have five goals.
After we finish, we'll be animating the clock by clearing the screen every second as a bonus.
We're also going to blink the separators between the digits.
Our first goal is creating an infinite loop to update the clock.
Let's start with that.
This task is easy.
I just need to wrap this court with an infinite for loop like this, limerence?
Wow, this doesn't look good.
Let me add a new line here right after I draw the clock.
Better, but it's still updates the clock too fast, by the way, if you are using your playground's,
it won't allow you to use this infinite loop.
So instead of this infinite loop, you can loop here like this is almost the same, only that this loops
for limited steps.
All right.
Let me take this back.
This brings us to our second call.
Let's check it out now, I'm going to update the clock every second.
To do that, I need to use a function from the time package.
It's called sleep.
Let me write it first.
And this function stops the world for a specific duration.
As you can see, it takes a time that duration value.
I want to update the clock for each second, so I'm going to sleep for one second here like this.
Remember time, that second is a duration value, as you can see here, if you don't remember this,
you might want to check out the constant S.A.G..
OK.
All right.
Limerence.
Better right now, it's slower, it only draws the clock every second coup.
This is good.
However, it doesn't update the clock in place, I mean, it throws a new clock under another clock,
right, to make it look animated.
We need to draw the clock in the same place.
To do that, I need to clear the screen and move the cursor position to the top left position of the
screen.
By the way, this is our third call.
All right, let's do it.
Let's first start with clearing the screen.
Clearing the screen on Basche comments prompts Orango playground is easy.
However, it is not so on Windows command prompts.
So I have created a special package to do that.
My package works on Windows and bash commands prompts.
I'll explain.
The inner mechanics of this package in the later sections is kind of advanced for now.
OK, so to use my package we need to get it from GitHub.
So now I'm going to call, go get comment and I'm going to type the path or my package on get up like
this.
This that you argument is for updating the package if you have already downloaded, by the way.
OK, now I can use the package in my code.
Just before drawing the clock, I'm going to call screen that clear function like this in here.
This will clear the screen.
By the way, if you are using your playground, do not call this function here, OK?
OK, let me show you what it looks like, the screen is full of characters right now.
When I ran the God, it will clear all of them like this.
As you can see, first, it has cleared the screen and then it has started drawing the clocks, however,
it has started printing the clock on the bottom part of the screen.
This is because the cursor is actually at the bottom of the screen.
So we need to move it to the top.
By the way, this is our fourth goal.
Let's take a look.
Here, before each step of the loop, I need to move the cursor to the top left corner, as I said,
this is because I wanted to print the clock always in the same position.
By the way, if you are using your playground, just print, backslash f here like this, backslash
F is the form feed character, it simply clears the console.
OK, all right.
Let me take this back.
All right.
But now I'm not using your playground, so now I'm going to call my screen packages, move top left,
function like this.
This will simply move the cursor to the top left corner of the console screen.
OK, let's try it.
Cool, right now, the clock always animates in the same position, it looks like as if the clock animates
actually it just redraws the whole clock on each step of the loop over and over again, first clears
the screen, then it moves the cursor to the top left corner.
And lastly, it throws the clock in that position.
Cool.
Let's check out our next call.
This is our last call, so now I'm going to blink the separators between the digits, to do that, we
need to hide and display the separators every two seconds.
So in this court, we need to decide when to print the separators to make things easier.
Down the road.
I'm going to put the next line that we are going to print into a variable.
Now, I'm going to cut this part from here, then just rideable.
I'm going to pass it here and I'm going to put it inside a variable called Next like this.
And lastly, I'm going to print the next line in here.
All right, let me run it.
Cool.
The card steelworks.
OK, now it's time to do the blinking.
First of all, I need to detect whether the current digit is a separator or not.
Remember this clock array here stores the separators as well here.
These colored variables are actually separator arrays.
Right.
And as you know, we can compare arrays.
So here I'm just going to compare where the next digit is a column or not like this.
However, here it is, an index variable, which is an inert variable, but the column is a placeholder
array.
This is because I'm getting the next index in this range claws into the digit variable.
Now, instead of doing it like this, let's introduce another variable, as you can see now, the index
variable stores, the indexes and the digit variable stores the next digit.
OK, let me also change this to the index variable.
Let's take a look at this if statement up.
So whenever I get a cullin from the closer, I'm going to hide it here in this if statement.
By the way, each line in a placeholder has three characters, right?
So now I'm going to assign a shrink with three empty spaces to the next variable like this, this will
help us to keep printing the digit if it's a column or in other words, if it's a separator, OK.
All right.
Let me try it this time.
It never prints the columns.
This is because here, whenever it detects that the next digit is a column, then it overrides its lines
with empty spaces.
So it doesn't print anything.
But we wanted the blink to do that.
And we're add another condition here like this.
Remember, SEC is the current second here.
I'm checking whether the second is divisible by two or not.
So now this card will only run every two seconds.
Let me show you.
Cool, right?
By the way, this court is not the best court that you can write, however, at the current stage of
the court.
I can't give you more details, but no worries in the upcoming sections, I'm going to show you how
to make this court more efficient.
All right.
That's all for now.
We are created a cool digital clock that runs entirely in the comment line.
I have prepared awesome some exercises for you to extend this project further.
You can find them in the next lecture.
All right.
Thank you for watching so far.
See you in the next section, Bhabhi.