Saturday 11 February 2017

Responsive - CodeChef

For responsive i could have just made 3 animations for various competitions but seeing as i have started to learn programming and have shown why it is important for me to learn it, and its uses in the industry in my PPP blog. I thought i would search for a competition where i could exercise my programming skills, whilst also relating to the responsive brief. I also needed tangible evidence that the skills i am learning through the programming competition are of use in the process of animation.

Regardless of whether i end up following down a road of being a technical developer or just using programming occasionally in my work, i feel that it is important to build up some programming skills. The animation industry, or rather, the world is advancing towards a technological future and learning how to speak to computers is a very useful, employable skill to have.

My goal is to be well rounded, with an abundance of traditional skill sets and CG skill sets. I do not think technology takes away from the art of animation, i think it enhances it. Or if not enhances, then provides the artist with a better way of producing artwork, therefore extending the artists creative potential.

To hate technology in my opinion is ignorance, fear that it nullifies the process. Stubbornness to not use CG methods is not healthy as change is inevitable and using CG methods is like using any tool traditionally. If the tool is used by a skilled draughtsman who understands that he needs to be in a state of peace and oneness with his instruments of creativity, the work will be beautiful. However if the tool is used by someone who doesn't know the underlying fundamentals of his craft and is disconnected, absent from his work, then his work will be absent and disconnected, as he is.      

Therefore embracing technology and learning as much of it as i can, will help me to achieve greater quality in my work.

The programming competition i found is called CodeChef, it is a non-profit, educational programing competition created by Directi, an Indian software company.

The 'long' competitions have a structure in which there are various problems in order of difficulty. Technically submitting to the competition, means completing at least one of the problems but i am going to try solve as many as i can before the competition deadline.

Because this was my first time programming anything substantial, i was throwing myself in the deep end abit, mainly because i had no idea if i would have the skills necessary to solve the problems set. Luckily the internet is an overflowing resource of help for programming queries. Because of the ability to look up the syntax i needed and to research any errors i faced, i found that participating in this competition was a really amazing way of learning programming skills. Learning through active practice is what the competition is and i found this a very effective way of extending my programming knowledge.

The way the competition works when you submit a problem is that inputs specified in the constraints of the problem are run through your code. Whether the outputs match the correct outputs determines whether the code is the correct answer or not.

When starting on the first problem of the January long competition, i thought it didn't sound too difficult. However coding the answer was quite a challenge.

When working on the project i used a mix of the python interpreter inside of Maya and the Python IDLE, this allowed me to easily test bits of code independently.


I had to test the code using a wide range of inputs, when i got an output which was wrong and i had no idea why, this is where the problems started.

I found a few effective ways of solving these problems. One method was to put in what i believe are called break points. These are lines of code that print certain variables at different times in the code, this is very useful to pinpoint where in the code the problem is occurring. If this is unclear, please refer to the image below.


Another useful method i found for solving the more general core of the problem was to visually represent the problem in my sketchbook, like so.


I found that relating the problem to a visual representation really helped me understand the problems i had to solve and helped me get my head round the problem.

When i had tested the code thoroughly and the outputs were all correct, i submitted the problem to the CodeChef website. The first few times i submitted the problem, i got incorrect answer. This was only because i put text such as 'Enter number of test cases...' before the inputs, whereas to test the code, the tester needs raw input/output data.

Once i realized this, i removed the text and got the correct answer. This problem took me about 1 day to complete.




The second problem was more challenging. However this problem was a more visual one. The problem was that if the visual representation of a resivour is unstable then print "no" to the screen, if the resivour is stable then print "yes". An example of a resivour is as follows:

BBAABB
BBWWBB
BBBBBB

Where "B" is a solid block, "W" is water and "A" is air. With a working solution the example above would print "yes" to the screen because it is stable, the example below would print a "no" to the screen because the water would flow into the air beneath and the block would submerge in the water.

BBBBWWBBB
BBAAAAWBB
BBBBBBBBBB   

I will give a very brief overview of the code i wrote for this solution and then talk about why the skills learnt from this problem can be applied to the animation industry.

First of all i had to work out how to store the lines of characters in lists which can then be compared together through for loops to look for situations which would make the resivour unstable. For example if a "A" was in a list and a "W" was in the above list at the same position in the list then this would make the resivour unstable because, as stated before, the water would flow into the air below.

This doesn't sound too difficult but what i found hard was applying responses for all the possible situations and combinations of the three characters.



To work out why i wasn't getting the outputs i wanted, i used my sketchbook to manually run the variables through the program, performing the functions by hand. This method makes it a lot easier to see what exactly is going wrong and why.

Below is my finished code, according to the tester it was the right answer but i only got 15 points. I tried improving the code, i tested it thoroughly but i could find any false outputs.




******

The skills i learnt whilst competing in the codechef competition can be further developed into skills for use in the animation industry.

Some practical examples would be, developing new tools for 2d and 3d software, developing tools to make the pipeline more efficient and speed up processes.

Rigging and programming go hand in hand to create great rigs which are easy for the animator to work with. programming is commonly used during the rigging process, especially in big studios such as Pixar. 


Above is an example of a shading artist applying an animated texture to the character Hank from the recent Pixar film 'Finding Dory'. Scripting would most likely have been implemented in making this feature of the model.

I wanted to try make my own python script to play around with this idea of having objects take on the colours of objects around them depending on certain factors.

i made a very very simple script in which the user selects two objects a background plane and a cube. If the cube is in front of the plane and the script is run, the cube adopts the planes colour (shader node). If the cube is returned to outside of the plane then its default shader is applied.


 



Scripting is also a very useful skill to have when faced with technical problems. For example in my responsive collaborative module, we were working on dragonframe on two's and it exported the frames not sequentially (e.g. 221,223,225). Due to this i could not import them as an image sequence in premier. To solve this problem i used the python IDE on maya to make a script that renamed the files sequentially.

I later found out this could have been done on bridge but the methods used in this renaming script could have been used more practically to apply an effect to all vertices on a model or perform a block of code for every edge. The possibilities are vast.



Creative coding languages such as Processing make it easier to blur the line between programming and art. Processing is a good language for creating artistic creations with code.

Using the skills i learned through the codechef competition i studied the basics of the processing language and started experimenting with the visual and creative applications of the language. I started off with a very simple composition just to get used to the syntax and the functions.


I then ventured further into the software and started to employ the setup() and draw() methods which are prominent methods in many high level languages such as C++ and Java. The processing language is basically a simplified version of languages such as C++ and Java. These high level languages are often used in animation/games production so it is a useful scope of knowledge to have.

Below is an example of a more complex program i created with Processing.





I then developed the code further to create a more helpful interface by having the circle displayed on the crosshairs and i also added a control for the size of the circle, this is controlled by the mouse scroll wheel.

 

                                     

No comments:

Post a Comment