Challenge [005]-Using Arrays to Simplify the Code:
http://ift.tt/2mMvT1v
I was inspired by David Lee’s medium post Code Less & Achieve More with Arrays in Framer in which he demonstrated the benefits of utilizing the “for loop” and “array” to simplify the code.
To practice what I just learned, I used 2 nested “for loop” to create a gradient matrix and defined the objects within an array. The great part about assigning each “item” into an array, is that we can later declare functions/animations of each “item” so they has the similar behavior, but each of them has slight variation corresponding to their array index. From the example, there’s a various delay for each cell.
Define Your Color Attribute with Math.
With challenge [005], I experimented with the color setting in Framer.
There are several ways to define the color in JavaScript. The most common formats are Hex Code and the rgb/rgba value.
HexColor = new Layer
backgroundColor = “#D24D57”
RGBColor = new Layer
backgroundColor = “rgba(210, 77, 87, 1)”
If we substitute the RGB value with a formula containing the for loop variable (i.e. i*20+55), we can have the background color of each object switches gradually from one value to the other.
for i in [0…10]
item = new Layer
width: 50
height: 50
x: i * 50
y: 100
backgroundColor: “rgba(“ + (i*20+55) + “,” + (i*10+80) + “,” + (i*10) + “,” + i*0.1 + “)”
Streamline the variables to make it a snippet.
In order to utilize this gradient matrix as a component in the future, I merged as many variables as possible into only 2, columns & the “R” value of backgroundColor. To achieve this, all the other values were defined in the functions that describe it’s relation to the two variable bases. (And that is why you might find some math describing the value a bit messy. )
You can see how changing the (2) attributes affect the Matrix in the pictures below.
Extended Read — Mathematical operators of JavaScript: http://ift.tt/2mMuLv2