CoffeeScript for Framer by Tessa Thornton Flashcards

1
Q

Which character do we use for decimal numbers?

A

The point (not the comma)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to insert a string

A

Strings come in quotation marks.

“This is a string”

‘This is also a string’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to concatenate strings?

A

Using a + sign: “My name is “ + “Tessa” # => “My name is Tessa

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Which type of data is this: “40”

A

This is a string (because inside quotation marks)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

“50” + “50”

A

=> “5050”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to assign a variable?

A

Variables are assigned using the = operator.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is a variable?

A

Variables let you assign a value to an arbitrary symbol for later reference. A variable is a box you can put values into. Any kind of value, like a string or a number.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Variables can’t…

A

Variables • can’t contain spaces • can’t start with numbers • can’t contain punctuation or symbols other than _

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the common naming convention for variable names?

A

CamelCase

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How do we make a string interpolation? (a variable inside a string)

A

We can embed the variable right in the string if we surround it with #{} print “my favorite color is #{color}, what’s yours?”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are boolean values?

A

Booleans are values that are either true or false. They’re indicated with just the words true or false without quotation marks. myBoolean = true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Which operator do we use to indicate that two values are the same?

A

is or ==

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What do we use to negate a condition?

A

To negate a condition you use the keyword “is not”. In place of “is not” you can use the shortform “isnt”.

num = 5

num isnt 10

=> true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Which syntax for conditional statements?

A

if/else

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

CoffeeScript avoids using symbols like semi-colons and parentheses. But in return, we need to follow certains rules about…

A

… indentation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do we insert comments in Coffee Script?

A

Using #

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

myObjectA =

name: “Framer”
age: 12

How to target the name property here? (2 ways)

A

2 options:

  • myObjectA.name
  • myObjectA[“name”]
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

How do we indicate that we’re putting a function in CoffeeScript?

A

Using the -> arrow

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

checkAge()

What do the brackets mean?

A

The () part basically means “go”. It tells the computer “run the function in the checkAge variable”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

Functions can be even more useful if we can give them values to work with. These values are called…

A

Parameters when creating the function. Arguments when calling the function and assigning values to those parameters.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

In CoffeeScript, we can give a function the ability to accept arguments. How do we do that?

A

By adding parenthesis containing the argument name before the -> sign

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What are arrays?

A

Arrays are lists or collections of multiple items

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Arrays have some built in methods (functions that they can use) for finding out information about them, like length.

fruits = [“apples”, “oranges”, “bananas”]

How to get the length of this array?

A

fruits.length()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

You can access elements in an array by their index. The index is the element’s position within the array. But there’s a warning! Which one?

A

Arrays are zero-indexed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Q

How do we access an element in an array?

A

We use square brackets containing the index of the element we’re looking for.

Ex: fruits [1]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
26
Q

How do we add to arrays?

A

You can add new items to an array with the method push. push adds the item you specify to the end of the array. Ex: fruits.push(“kiwis”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q

Why arrays can be very powerful in CoffeeScript?

A

Because they let you repeat certain functionality over and over with different items by using loops. Loops let you do something for every item in an array.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q

Which method would we use to uppercase the first string elements of our fruits array?

A

fruits [0]. toUpperCase ()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
29
Q

How would we uppercase all our string elements inside our fruits array?

A

for fruit in fruits fruit.toUpperCase()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
30
Q

What is an object?

A

An object is a collection of properties. In programming, a property is an association between a name and a value. If something has properties, you can store them in an object.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
31
Q

Can we store arrays and booleans in objects?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
32
Q

Can we store objects inside objects?

A

Yes

33
Q

book =

Author:

name: “Kurt Vonnegut” born: 1922
died: 2007

What is this? And what is the difference between = and :

A

This is an object inside another object. Note that we use = and : in the above example. Note the difference: “=” assigns a variable name (book) to an object, and “:” matches up names and values. “author” is the name, and the object containing name, born, and died is the value.

34
Q

What punctuation sign do we use to access properties in an object?

A

We use dots. Ex: book.title

35
Q

book =

author:

name: “Kurt Vonnegut” born: 1922
died: 2007

How to print the date of birth?

A

print book.author.born # => 1922

36
Q

book =

pages: 256
genres: [“Science Fiction”, “Satire”]
fiction: true

How to print “Satire” ?

A

print book.genres[1]

=> “Satire”

37
Q

What is a method?

A

Since we can store any kind of data in an object’s properties, we can also store functions as properties. When a function is the property of an object, it is called a method.

38
Q

book =

title: “Slaugherhouse Five”
read: -> print “All this happened, more or less.”

What is the read property and how to call it?

A

The read property is a method (a function that is the property of an object) that belongs to our book object. We can call it like we would call any function: book.read()

=> “All this happened, more or less.” This is how the toUpperCase method works. It’s a method that belongs to all string objects.

39
Q

What is new Layer() ?

A

This is a special kind of function that creates an object. square = new Layer () By default, in Framer it will create a 100*100 square with semi transparent blue color: rgba(0, 124, 255, .5)

40
Q

square = new Layer(

width: 200
height: 200
x: 100
y: 100 )

What’s inside the brackets?

A

An argument (of the new Layer function). And this argument is a configuration object. And the properties inside this configuration object are the attributes like width, height, x, y, etc.). To make that code a bit easier to read, we can get rid of the parentheses

41
Q

How can we modify a layer’s appearance using CSS properties in Framer ? (simple way)

A

You can modify a layer’s coordinates (x, y), as well as appearance by using camel-cased (camelCased) versions of most CSS properties, as well as some built-in framer properties. For example, color is just color but border-radius becomes borderRadius. If you want to rotate an element, you can modify the rotation property framer provides.

42
Q

Which method do we use to animate a layer ?

A

layer.animate()

43
Q

What do we need to specify so that the animate method will do something ?

A

By itself, .animate() isn’t goint to do anything. We need to pass it a configuration object to tell it what to animate, and how to animate it.

A configuration object will follow this format:

configObject =

properties:

property: value
property: value
time: 1
curve: “ease”
delay: 2

44
Q

Time-related properties (delay and time), are specified in seconds. By default, animations in Framer take…

A

1 second

45
Q

layer.animate

properties:

opacity: 0

Time: .2

What do you see here ? (elements hierarchy)

A

“properties” is an object (it’s an object nested inside an object).

“Opacity” is a property, so it’s indented one level further than “properties” to indicate the relationship. Time is a property of the animation, not a property of the object animating. Hence the outdent. Whitespace is significant here.

46
Q

How do we add repeat and delay properties to our layer animation ?

A

layer.animate

properties:

opacity: 0
repeat: 4
delay: 2

47
Q

Which method do we use to “listen” for events triggered by the user ?

A

We use the « on » method

48
Q

Does the « on method » takes arguments ? If yes, which ones ?

A

This is actually a method being called with two arguments, though it may not look like it. The format for the on method is on(eventName, function), where the function is the code that gets run when the event is triggered. It might make more sense if we leave on the parentheses:

button.on(Events.Click , →)

49
Q

When you use a function as an argument (like in the « on method »), it’s called a…

A

…callback

50
Q

In plain english, calling the “on method” with a callback is like saying…

A

…“listen for and do

The two arguments are:

  • the thing that you’re listening for
  • the thing that you should then do
51
Q

What is the syntax in CoffeeScript to indicate a function ? Let’s say we want to declare functioName as a function

A

FunctionName = →

52
Q

When we give the “on method” a function as an argument, it doesn’t need…

A

…a name or an equals sign. We just need the -> part

53
Q

button.on(Events.Click , →) Why the comma ?

A

The comma is the separation between the first argument (the name of the event), and the second (the function).

54
Q

How do we access the properties of the screen we’re working on, in Framer?

A

Framer.Device.screen

Ex:

Framer.Device.screen.width Framer.Device.screen.height

55
Q

When we specify the value of curve property, what is the data type expected in Framer ?

A

A string. Therefore it is specified in quotation marks. Ex : “ease-in”

56
Q

How to trigger something after one animation is finished ?

A

Layer.on Events.AnimationEnd, →

57
Q

As for Animation Curves, Spring is an alias for…

A

spring-rk4

58
Q

How many arguments does the spring function take ?

A

The spring function takes 4 arguments (the last one is optional):

  • 1 tension (Strength of the spring)
  • 2 friction (Weight of the spring)
  • 3 velocity (Velocity at the start)
  • 4 tolerance (Minimal threshold before the animation ends. (Optional))
59
Q

Which symbol means “not” in CoffeeScript ?

A

!

60
Q

How do we set a value to its opposite ?

A

We do = !

Ex :

is_open = ! is_open

61
Q

Which method do we use to add states to a layer ?

A

layer.states.add()

62
Q

Each state consists of…

A
  • a name (string)
  • and property pair(s)

States are configuration objects.

63
Q

Which method enables to switch to the next state(s) ?

A

layer.states.next()

64
Q

Animation between states has default settings (like 1 second for the time). How do we change this ?

A

We need to add and configure layer.states.animationOptions

Ex : layer.states.animationOptions = time: 0.2

65
Q

How to we make a layer draggable ?

A

layer.draggable.enabled = true

66
Q

How to make a layer draggable only horizontally (only on x axis) ?

A

layer.draggable.vertical = false (Same goes for layer.draggable.horizontal)

67
Q

Give 3 events based on Drag

A
  • DragStart
  • DragMove
  • DragEnd
68
Q

Which property relates to the horizontal center of a layer ?

A

It’s : midX

Ex :

layer.midX

69
Q

Which property relates to the vertical center of a layer ?

A

It’s : midY

Ex:

layer.midY

70
Q

What do we write if we want to repeat something 5 times ?

A

for i in [0…5]

This is the start of a loop. Note that the 3 dots stand for an exclusive range (otherwise we would end up with a length of 6)

71
Q

For i in [0…5]

It’s a bit of a convention to use i for the variable that gets re-assigned for each time through the loop. But what does the i stand for ?

A

iterator or index

72
Q

How do we assign an image (from “images” folder) to a layer ?

A

image : “images/myImage.png”

73
Q

How to center a layer horizontally in its superLayer ?

A

layer.centerX(offset)

Center this layer horizontally in its superLayer. If there is no superLayer it will be centered relative to the screen. The offset (argument of this method) is a pixel offset from the center and optional.

74
Q

How to center a layer vertically in its superLayer ?

A

layer.centerY(offset)

Center this layer vertically in its superLayer. If there is no superLayer it will be centered relative to the screen. The offset (argument of this method) is a pixel offset from the center and optional.

75
Q

How to center a layer?

A

layer.center()

Center this layer in its superLayer. If there is no superLayer it will be centered relative to the screen.

76
Q

The blur property is set in pixels, so you can…

A

…copy it right out of the Gaussian blur in Photoshop or Sketch.

77
Q

When we scale elements, we should keep in mind that the scaling won’t affect…

A

…the bounding box of the element that is being scaled. This is something to consider when positionning the scaled element with its x and y properties ! For instance, if you scale down and bring to zero the x and y properties of an object that is initially 200px wide and tall, you won’t have it touching the top-left corner because it’s scaled inside its bounding box. In case of doubt, printing the frame of the layer will give the necessary information

78
Q

The last created layer will always be on…

A

…top. Which means above the other layers. This can be confirmed by looking at the layer inspector.

79
Q

Let’s say you have a layer that isn’t positionned where you want in the layer inspector, which causes a bad overlapping. How can you deal with this ?

A

By managing either its:

  • superLayer (layer.superLayer <layer>)</layer>
  • subLayers (layer.subLayers <array>)</array>
  • index (layer.index)

(The layer index increases by order of insertion)