Main content

### Course: Pixar in a Box > Unit 9

Lesson 2: Code a character- Start here!
- 1. Creating objects
- 2. Representing a shape object in code
- Rigging a snowman 1 (building the body)
- 3. Putting shapes together
- Rigging a snowman 2 (adding a head)
- Rigging a snowman 3 (adding a hat)
- 4. Functions
- 5. Defining deformer functions in code
- Rigging a snowman 4 (coding deformers)
- 6. Connecting deformers and shapes with code
- Rigging a snowman 5 (adding and updating deformers)
- Project: Create your own character
- Project 2: Animate your character

© 2024 Khan AcademyTerms of usePrivacy PolicyCookie Notice

# 4. Functions

Snowman rigging involves scale, rotate, and translate deformers using functions. Functions perform operations on inputs like coordinates and transformation magnitudes. Different equations define scaling, rotation, and translation. Deformers transform vertices in shapes, and functions run multiple times for each vertex. Click here to review functions. Click here to review geometric transformations.

## Want to join the conversation?

- i really dont understand how to build a snowman. i need help.(5 votes)
- you should take a look at the basics of computer programming, here: https://www.khanacademy.org/computing/computer-programming/programming/drawing-basics/p/making-drawings-with-code

the first project is a snowman so it's cool!(6 votes)

- So the second input (value) is similar to having
`+= value`

?(3 votes) - I need help in this rotate functions

var translateXFunction = function(coordinate, value) {

coordinate.x = coordinate.x + value;

};

var translateYFunction = function(coordinate, value) {

coordinate.y = coordinate.y - value;

};

var scaleFunction = function(coordinate, value) {

coordinate.x = coordinate.x * value;

coordinate.y = coordinate.y * value;

};

var rotateFunction = function(coordinate, value) {

var x = coordinate.x;

var y = coordinate.y;

};(2 votes) - I dont reallly understand somebody help ples(2 votes)
- Does KA make units like a cartoon season?(2 votes)
- is there a program to make a 3D cheracter in khan?(2 votes)
- How to do you automatically know where each pixel/position is?(1 vote)
- You don't, you go through some trial and error, they probably memorized the positions(2 votes)

- i have snowman that i mad with my on two hands i type it out on a labtop i would work it out on paper(1 vote)
- Yes KA make units like a cartoon season(1 vote)
- Same, I cant make the codes(1 vote)

## Video transcript

- Alright, you finally have a
snowman to start working with. Now we can get to the real
guts of the rigging software. We need to define our scale, rotate, and translate deformers. To allow you to move your shapes around. And this is where
functions come into play. Remember, functions package
a series of operations or procedures we'll use many times. Functions are set input which they perform a set of operations on. Now, to build any deformer,
we'll need a function which intercepts two inputs. First they must intercept
a pair of coordinates which is the vertex in our shape. And lay a set of value which is a magnitude of
transformation you want to apply. For example, the translate x to full might intercept a coordinate 2,2. And for the 2nd input would
provide a value of say five. And so this translate x function, the math we'll do is quite simple. Hey that's five to the x coordinate which updates it to 7,2 and that's the process for transforming each vertex into shape. Of course, a shapes contain many vertices. For example, a hat has eight. That means its function
is run eight times. Once for each vertex. Order of the deformer
functions transform vertices using equations. And the transformation depends
on the types of equations used in your functions. The equations used for scaling,
rotate, and translation are all different from each other. We cover these equations in detail in our sets and staging lesson. In the next code review, we'll give you an example of
writing a translation function and then in the exercise,
we'll allow you to write free deformer functions on your own. Alright, I'm out of here. (chuckling)