Skip to content

Commit 4560a4c

Browse files
committed
Make the cube animation closer to logo
1 parent e68b94b commit 4560a4c

File tree

3 files changed

+65
-14
lines changed

3 files changed

+65
-14
lines changed

components/cube/cube-style.scss

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,17 @@
2323
position:absolute;
2424
width:100%;
2525
height:100%;
26-
border: 3px solid getColor(white);
26+
border: 1px solid getColor(white);
2727
}
2828

2929
.cube__outer .cube__face {
3030
background:transparentize(getColor(malibu), 0.5);
31+
transition: border-width 0.2s;
32+
transition-delay: 0.2s;
3133
}
3234

3335
.cube__inner .cube__face {
3436
background:getColor(denim);
37+
border: 2px solid getColor(white);
3538
}
3639
}

components/cube/cube.jsx

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export default class Cube extends React.Component {
1313
this.state = {
1414
x: 0,
1515
y: 0,
16-
z: 0
16+
z: 0,
17+
iteration: 0,
1718
};
1819
}
1920

@@ -47,7 +48,7 @@ export default class Cube extends React.Component {
4748
rotateY(${y}deg)
4849
rotateZ(${z}deg)`
4950
}}>
50-
{ this._getFaces() }
51+
{ this._getFaces('outer') }
5152
</figure>
5253
<figure
5354
className="cube__inner"
@@ -60,7 +61,7 @@ export default class Cube extends React.Component {
6061
rotateY(${-y}deg)
6162
rotateZ(${-z}deg)`
6263
}}>
63-
{ this._getFaces() }
64+
{ this._getFaces('inner') }
6465
</figure>
6566
</span>
6667
</div>
@@ -80,14 +81,9 @@ export default class Cube extends React.Component {
8081

8182
this._interval = setInterval(() => {
8283
let obj = {};
83-
let sign = Math.random() < 0.5 ? -1 : 1;
84-
8584
obj[axis] = degrees += 90;
8685

87-
// axis = axis === 'x' ? 'y' : axis === 'y' ? 'z' : 'x';
88-
89-
this.setState(obj);
90-
console.log('cube spin');
86+
this.setState({ ...obj, iteration: (this.state.iteration + 1) % 4 });
9187
}, repeatDelay);
9288
}
9389
}
@@ -107,9 +103,53 @@ export default class Cube extends React.Component {
107103
/**
108104
* Get all faces for a cube
109105
*
106+
* @param {'inner' | 'outer' } type
110107
* @return {array} - An array of nodes
111108
*/
112-
_getFaces() {
109+
_getFaces(type) {
110+
let { iteration } = this.state;
111+
112+
// Keep the thicker border on
113+
// the outside on each iteration
114+
const borderWidthMap = {
115+
0: {
116+
left: [1, 1, 1, 6],
117+
right: [6, 1, 1, 1],
118+
top: [1, 1, 1, 1],
119+
bottom: [6, 1, 1, 6],
120+
},
121+
1: {
122+
left: [1, 1, 1, 1],
123+
right: [1, 1, 1, 1],
124+
top: [1, 1, 1, 1],
125+
bottom: [1, 1, 1, 1],
126+
},
127+
2: {
128+
left: [1, 1, 6, 6],
129+
right: [6, 6, 1, 1],
130+
top: [6, 1, 1, 6],
131+
bottom: [1, 6, 6, 1],
132+
},
133+
3: {
134+
left: [6, 1, 1, 1],
135+
right: [1, 6, 1, 1],
136+
top: [1, 1, 1, 1],
137+
bottom: [6, 6, 1, 1],
138+
},
139+
4: {
140+
left: [1, 1, 6, 1],
141+
right: [1, 1, 1, 6],
142+
top: [1, 1, 1, 1],
143+
bottom: [1, 1, 6, 6],
144+
},
145+
5: {
146+
left: [1, 6, 1, 1],
147+
right: [1, 1, 6, 1],
148+
top: [1, 1, 1, 1],
149+
bottom: [1, 6, 6, 1],
150+
}
151+
};
152+
113153
return [
114154
'rotateX(0deg)',
115155
'rotateX(-90deg)',
@@ -118,12 +158,20 @@ export default class Cube extends React.Component {
118158
'rotateY(90deg)',
119159
'rotateY(180deg)'
120160
].map((rotation, i) => {
161+
const borderStyles = type === 'outer' ? {
162+
borderTopWidth: borderWidthMap[i].top[iteration],
163+
borderRightWidth: borderWidthMap[i].right[iteration],
164+
borderBottomWidth: borderWidthMap[i].bottom[iteration],
165+
borderLeftWidth: borderWidthMap[i].left[iteration],
166+
} : {};
167+
121168
return (
122169
<section
123170
key={ i }
124171
className="cube__face"
125-
style={{
126-
transform: `${rotation} translateZ(${ this.props.depth / 2 }px)`
172+
style={{
173+
transform: `${rotation} translateZ(${ this.props.depth / 2 }px)`,
174+
...borderStyles,
127175
}} />
128176
);
129177
});

components/splash-viz/splash-viz.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export default class SplashViz extends React.Component {
2222
<div className="splash-viz__modules">
2323
<img src={ Modules }/>
2424
</div>
25-
<Cube className="splash-viz__cube" depth={ 140 } repeatDelay={ 5000 } continuous/>
25+
<Cube className="splash-viz__cube" depth={ 120 } repeatDelay={ 5000 } continuous/>
2626
</section>
2727
);
2828
}

0 commit comments

Comments
 (0)