1
00:00:05,892 --> 00:00:07,624
Hi, welcome to this new video.

2
00:00:07,624 --> 00:00:10,406
This is the final video of week four.

3
00:00:10,406 --> 00:00:13,626
We're going to be learning
how to save animations.

4
00:00:13,626 --> 00:00:17,114
So we're going to jump directly into
processing to discuss how we're

5
00:00:17,114 --> 00:00:17,916
going to do this.

6
00:00:17,916 --> 00:00:20,827
And we're going to continue
working on the script and

7
00:00:20,827 --> 00:00:23,274
the folder that we have from last session.

8
00:00:23,274 --> 00:00:27,801
So if you haven't covered the last two
sessions, we develop a simple script,

9
00:00:27,801 --> 00:00:32,052
a composition that we started to learn
how to save frames from it, right,

10
00:00:32,052 --> 00:00:34,046
using the keyPressed function.

11
00:00:34,046 --> 00:00:38,741
So if you haven't covered that video,
go back, check that one first, and

12
00:00:38,741 --> 00:00:40,142
then resume here.

13
00:00:40,142 --> 00:00:43,621
So we're going to discuss how we
can actually save an animation.

14
00:00:43,621 --> 00:00:48,360
So I've tried different techniques for
saving animations.

15
00:00:48,360 --> 00:00:52,977
You might want to just get an MP4 file or
an AVI file or MOV,

16
00:00:52,977 --> 00:00:57,430
right, directly a video that
you can execute, right?

17
00:00:57,430 --> 00:01:02,600
And while that might be great,
it might also not play and

18
00:01:02,600 --> 00:01:06,462
perform as the way you expect it, right?

19
00:01:06,462 --> 00:01:12,447
Many times processing, depending on how
much content you have in the screen,

20
00:01:12,447 --> 00:01:18,082
might slow down and might kind of play
at a suboptimal frame rate, right?

21
00:01:18,082 --> 00:01:23,306
So what we want to do is save every
frame and then reconstruct that

22
00:01:23,306 --> 00:01:28,826
video in different packages,
things like premiere automatically

23
00:01:28,826 --> 00:01:34,098
kind of understand sequence of
images as an animation, right?

24
00:01:34,098 --> 00:01:39,359
So I'll show you how to do that, how to
create a sequence of images that then you

25
00:01:39,359 --> 00:01:45,050
could actually import into a video editing
package to kind of produce a final video.

26
00:01:45,050 --> 00:01:46,583
So let's do that.

27
00:01:46,583 --> 00:01:50,396
We're going to use the same technique,
but this time,

28
00:01:50,396 --> 00:01:55,410
we're going to assign to a different
key the recording of an animation.

29
00:01:55,410 --> 00:02:00,701
And what we're going to do is basically
the idea that we can press a button,

30
00:02:00,701 --> 00:02:03,756
in this case the button r in the keyboard.

31
00:02:03,756 --> 00:02:09,677
And that will turn on a recording state or
a variable that would be a Boolean,

32
00:02:09,677 --> 00:02:12,928
true or false, that would be recording.

33
00:02:12,928 --> 00:02:15,697
While we are recording,
we are saving every frame.

34
00:02:15,697 --> 00:02:19,614
So at the end of the draw loop there
would be a line saving frame, right?

35
00:02:19,614 --> 00:02:22,280
So let's start by creating that variable.

36
00:02:22,280 --> 00:02:24,860
Let's call it a Boolean.

37
00:02:30,805 --> 00:02:34,968
A recording equals false.

38
00:02:34,968 --> 00:02:39,887
So there's going to be a Boolean
because we identify it as a false

39
00:02:39,887 --> 00:02:42,263
state to start with, right?

40
00:02:42,263 --> 00:02:45,599
And we're going to copy that,
and then here in the draw loop,

41
00:02:45,599 --> 00:02:46,998
we're going to use it.

42
00:02:46,998 --> 00:02:52,837
So let's declare it first as a global
recording, and towards the end,

43
00:02:52,837 --> 00:02:57,721
and you have to be clear and
careful with your indentation.

44
00:02:57,721 --> 00:03:03,329
Towards the end of the draw loop,
we're going to say, if recording, right?

45
00:03:03,329 --> 00:03:07,990
So if recording, this is a shorter
way of saying is true, right?

46
00:03:07,990 --> 00:03:12,863
You can omit the is true part by saying,
if recording, the language would

47
00:03:12,863 --> 00:03:18,808
automatically understand if this is true,
right, that's just for explicit reasons.

48
00:03:18,808 --> 00:03:25,170
Let's just do this, but many times you'll
see code without that equals true, right?

49
00:03:27,620 --> 00:03:30,193
Something happens, so what happens?

50
00:03:30,193 --> 00:03:33,222
What we've done before is,
we save the frame.

51
00:03:34,950 --> 00:03:40,327
And in this case,
let's save it into animation folder,

52
00:03:40,327 --> 00:03:45,592
and let's give it an animation,
the name of the frame,

53
00:03:45,592 --> 00:03:48,744
the number of the frame, right?

54
00:03:48,744 --> 00:03:55,252
So, currently, our recording variable
starts as false, but if it's true,

55
00:03:55,252 --> 00:04:00,487
we start recording and
basically saving every frame, right?

56
00:04:00,487 --> 00:04:05,254
Notice that the software or the program
will start running a little bit slower

57
00:04:05,254 --> 00:04:07,893
once we start saving every frame, right,

58
00:04:07,893 --> 00:04:12,456
because every frame, we are kind of
recording data to the drive, right?

59
00:04:12,456 --> 00:04:17,442
So you might see the performance
drop of your animation.

60
00:04:17,442 --> 00:04:21,110
But don't worry, because once
you reconstruct your animation,

61
00:04:21,110 --> 00:04:23,410
you're not going to notice that slowdown.

62
00:04:23,410 --> 00:04:26,797
The animation would play as if it
was perfectly smooth at, let's say,

63
00:04:26,797 --> 00:04:27,983
30 frames per second or

64
00:04:27,983 --> 00:04:31,946
whatever frame rate you decide that your
animation should be playing at, right?

65
00:04:31,946 --> 00:04:35,584
You can define that in your
video editing package.

66
00:04:35,584 --> 00:04:39,100
So let's go into if.

67
00:04:39,100 --> 00:04:43,954
So here, if key, Equals r, because

68
00:04:43,954 --> 00:04:48,273
what we're missing at this point is like
how do we turn on the recording, right?

69
00:04:48,273 --> 00:04:53,578
So we're going to create this with

70
00:04:53,578 --> 00:04:59,675
another key, or the key equals to R.

71
00:04:59,675 --> 00:05:04,422
In this case, instead of putting

72
00:05:04,422 --> 00:05:10,013
the safe frame function and the print,

73
00:05:10,013 --> 00:05:16,295
we can say recording equals not recording.

74
00:05:16,295 --> 00:05:18,988
And this line might be confusing,
so what is this line saying?

75
00:05:18,988 --> 00:05:23,050
It's saying, well,
we're using the not-operator, and

76
00:05:23,050 --> 00:05:28,320
not is kind of flipping a Boolean state
from true to false or from false to true.

77
00:05:28,320 --> 00:05:32,230
So if this is false,
this will become true.

78
00:05:32,230 --> 00:05:34,622
And if it's true,
it will become false, right?

79
00:05:34,622 --> 00:05:39,457
So it's kind of an inversion, and

80
00:05:39,457 --> 00:05:44,140
we could say, print recording.

81
00:05:48,400 --> 00:05:53,346
We have a little bit of an exclamation
mark for the drama there, right?

82
00:05:53,346 --> 00:05:58,313
But as you can see,
we are activating this Boolean

83
00:05:58,313 --> 00:06:02,224
at this point that would trigger here.

84
00:06:02,224 --> 00:06:05,625
We might also want to make sure that,

85
00:06:08,495 --> 00:06:13,114
We're using, in fact,
the recording from global variable here.

86
00:06:13,114 --> 00:06:15,190
Let's see if this works.

87
00:06:16,440 --> 00:06:18,860
So we have our composition.

88
00:06:18,860 --> 00:06:21,260
I'm going to press R.

89
00:06:21,260 --> 00:06:23,630
So recording starts being true.

90
00:06:23,630 --> 00:06:30,812
As you can see, my canvas starts
coming a little bit slower.

91
00:06:30,812 --> 00:06:36,818
And when I'm done,
I could press R again, or just close it.

92
00:06:36,818 --> 00:06:38,312
Let's go into the folder.

93
00:06:38,312 --> 00:06:40,540
And we have an animation folder.

94
00:06:42,720 --> 00:06:47,160
And as you can see here,
we've created a series of files.

95
00:06:47,160 --> 00:06:50,854
All of these files are simple images,
right?

96
00:06:50,854 --> 00:06:56,074
But if we try to open these files in
something like premiere, after effects,

97
00:06:56,074 --> 00:07:01,614
and many other packages, just by locating
this folder, you will see the option to

98
00:07:01,614 --> 00:07:07,222
understand all these files as a sequence
that's already an animation, right?

99
00:07:07,222 --> 00:07:12,261
So that shouldn't be too
much trouble to kind of edit

100
00:07:12,261 --> 00:07:16,996
using this sequence of
images as an animation.

101
00:07:16,996 --> 00:07:20,224
So I got very good results
from this technique.

102
00:07:20,224 --> 00:07:22,174
It actually works very well.

103
00:07:22,174 --> 00:07:24,398
So I invite you to try it.

104
00:07:24,398 --> 00:07:27,324
So with that,
we're going to be concluding week 4.

105
00:07:27,324 --> 00:07:29,486
I'll see you in our final week, week 5.

106
00:07:29,486 --> 00:07:31,140
See you then.