3D Time Clock DIY Using Blender and Animation Node |
Quicky Digital Clock |
Blender Animation Node O'Clock
Above screen shot is another quick snippet experiment I did yesterday.Understanding and appreciating time is crucial for both animator and programmer, and people in general. Making a LIVE clock is a nice exercise to learn AN and Python programming, I reckon.
I will write my step by step notes to make clock using AN and programming logic. I will use AN Script node for this case. You will see why.
DIGITAL CLOCK
My brain said that a real clock should be a TIME that we can customize and then run from that point. That is something that I would like to think to do at some point using Modulus.However, for our convenience, we will just use Python "current time". I found a hint from this link at Blender Artist forum:
http://blenderartists.org/forum/archive/index.php/t-99106.html
Great! I think we can use Python "time" module!
There is one super convenient AN node we can use to "copy paste" script or to write our own Python script and it will do the processing and running looping calculation on the go: SCRIPT node.
I fall in love with this node, the moment I understand how it works.
A bit about this Script node...
Firstly, you create a Script node in AN node tree. Then you create a Text inside Text Editor. And you can start typing Python script.You may notice that nothing really happens, NOT UNTIL you actually "summon" the actual script.
NOTE: AN has this kind of "behind the screen" LEGO brick. Maybe you can call it the thinking block of script for you to customize, then later to use that brick you actually call it.
Supposed I want Script node to continuously printing "hello" in the console like below.
The script will not run, until you call the script.
You got the idea? Now, let's try using Python "import time" module.
Here, I assign the output of time.localtime() into a variable called "mytime". You can use any variable name for this.
time.localtime() will return a list of tuple and each element is correspond to: year, month, and so on.
How do we use these DATA? We can just use Script node convenient INPUT and OUTPUT slots creations. On the fly!
We just need OUTPUT for now, and I will use "Integer" data value for each output slots:
It will not work yet, but we have provided an empty containers output to pass our "time" data. You can use Python quick unpack and assign value like below:
NOTE: I accidentally make mistake here and assigning "minute" variable twice :) Correction below |
We have 7 variables and we are assigning 7 different values from time.localtime() into those variables. Now, everything is actually already working. We can close Text Editor and "forgot" about the running processing in the background. Remember that our "time" is LIVE program.
DATA OUTPUT: Text Object(s)
Let's spit out the time as Text Object. And we can use AN to pass our text/string data into it. Starting with "year" variable.Everything is pretty straight forward, but I want to just mention a couple of useful things. Ensure that for each Text Object, you only pipe in one data, otherwise you have things clashing. But don't worry, you are allowed to make mistake.
At the moment, the output will be all numbers:
There are a couple of things:
- Perhaps for months and weekday, you want to use your own text in your own language? Yes, you can.
- Maybe you want the HH MM SS always displayed as 2 digits.
EXTRA: Display as 2 Digits
You could use Python to zfill the number into X digit you want. 2 Digits: 01, 02, 03, ....
But I just use AN Fill node for Text String to do the job. Just simply fill with "zero" on the left:
EXTRA: Display Useful Text Instead Of Number
For 7 days of the week / weekday, we should show it as:Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday (In English).
What important here is THE ORDER of the list. From our Python time script, weekday started from Monday (index 0) until index 6, and back to index 0.
0 => Monday
1 => Tuesday
2 => Wednesday
3 => Thursday
4 => Friday
5 => Saturday
6 => Sunday
I think it's pretty cool how SIMPLE all of these become using Animation Nodes AN in Blender!
The rest you can "decorate" and design layout your clock. Perhaps using different fonts? Perhaps make a falling rain clock?
ANALOG WATCH
For analog watch, we can simply use Map Range node. For example, we know that our "number" for our second goes from 0 - 59 (60 ticks), and so we just need to map range those to 360 degree.Below, I am using Suzanne's long CHIN as pointer for "second".
If you are using your own "TIME" like FRAME to create clock, you can use Math MODULUS or Repeat Time node. Sometimes that is preferrable, and easier to offset time as you need.
Post a Comment