Skip to content

Commit ebce2b9

Browse files
committed
Fix the flag of China stars rotating issue #11
1. Create helper function to link polygen points. 2. Draw five angle stars with polygen() for css clip-path.
1 parent bf5971a commit ebce2b9

File tree

4 files changed

+51
-96
lines changed

4 files changed

+51
-96
lines changed

app/styles/_flags/bra.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
// // top: ($height - $circle-width) / 2;
7979
// // left: ($width - $circle-width) / 2;
8080
// // background-color: $white;
81-
// clip-path: five-pointed-star($circle-width, 100px, 100px);
81+
// clip-path: polygon(five-pointed-star($circle-width, 100px, 100px));
8282
// }
8383
};
8484

app/styles/_flags/chn.scss

+14-12
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,22 @@
66
$red: #de2910;
77
$yellow: #FDDA24;
88
$star-size: 6 * $unit;
9-
$star-offset-top: 5 * $unit;
10-
$star-offset-left: 5 * $unit;
119
$star-size-small: 2 * $unit;
12-
$star-offset-top-small: 2 * $unit;
13-
$star-offset-left-small: 10 * $unit;
1410

1511
background-color: $red;
1612
&:before {
17-
@include star($yellow, $star-size, $star-offset-left, $star-offset-top);
13+
content: '';
14+
display: block;
15+
position: relative;
16+
width: $width;
17+
height: $height;
18+
background: $yellow;
19+
clip-path: polygon(link_list(
20+
five-pointed-star($star-size, 5 * $unit, 5 * $unit),
21+
five-pointed-star($star-size-small, 10 * $unit, 2 * $unit, -120.96),
22+
five-pointed-star($star-size-small, 12 * $unit, 4 * $unit, -98.13),
23+
five-pointed-star($star-size-small, 12 * $unit, 7 * $unit, -74.055),
24+
five-pointed-star($star-size-small, 10 * $unit, 9 * $unit, -54.34)
25+
));
1826
}
19-
&:after {
20-
@include star($yellow, $star-size-small, $star-offset-left-small, $star-offset-top-small);
21-
text-shadow:(2 * $unit) (2 * $unit) 0px $yellow,
22-
(2 * $unit) (5 * $unit) 0px $yellow,
23-
(0) (7 * $unit) 0px $yellow;
24-
}
25-
};
27+
};

app/styles/_helpers/helper.scss

+23
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,29 @@
55
@return $value / ($value * 0 + 1);
66
}
77

8+
// Link polygen point lists to a single one
9+
// @args: lists with positions
10+
// @returns: New single list which can be used in polygen()
11+
@function link_list($args...) {
12+
$result: ();
13+
$len: length($args);
14+
15+
@for $i from 1 to $len + 1 {
16+
$list: nth($args, $i);
17+
$result: append($result, $list, comma);
18+
}
19+
20+
@if ($len <= 2) {
21+
@return $result;
22+
}
23+
24+
@for $i from $len - 1 to 1 {
25+
$list: nth($args, $i);
26+
$result: append($result, nth($list, 1), comma);
27+
}
28+
@return $result;
29+
}
30+
831
// Sets the flag ratio and update all magic variables
932
// @args ratio: Ratio of height / width
1033
@mixin ratio($ratio:1) {

app/styles/_helpers/stars.scss

+13-83
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
// http://www.mathalino.com/sites/default/files/images/005-planegeom-pentagram.jpg
66
// http://musicians4freedom.com/wp-content/uploads/2014/06/phi-dimentions-in-pentagram_0.gif
77
//
8-
@function five-pointed-star($diameter, $left, $top) {
8+
@function five-pointed-star($diameter, $left, $top, $rotate:0) {
9+
$result: ();
910
$radius: _($diameter / 2);
1011
$golden-ratio: 1.618;
1112
// There are two circles that make a five pointed star.
@@ -14,86 +15,15 @@
1415
// Both radius have a ratio equal to the golden ratio
1516
$inner-radius: $radius - $radius / $golden-ratio;
1617

17-
// Whatever the size of the star, the inner angle of the peaks is always 36°
18-
$teta: 36deg;
19-
// The other angles of the triangles are 72°
20-
$beta: 72deg;
21-
$pentagram-side: 2 * (sin($teta) * $inner-radius);
22-
// teta is also equal to the angle from the center of the star to one inner
23-
// peak and with a right angle to the base of one of the triangles
24-
$inner-top-padding-x: $pentagram-side / 2;
25-
$inner-top-padding-y: cos($teta) * $inner-radius;
26-
$outer-top-padding-x: sqrt($radius * $radius - $inner-top-padding-y * $inner-top-padding-y);
27-
$outer-top-padding-y: $inner-top-padding-y;
28-
$inner-bottom-padding-x: ($pentagram-side / 2) + (cos($beta) * $pentagram-side);
29-
$inner-bottom-padding-y: sqrt($inner-radius * $inner-radius - $inner-bottom-padding-x * $inner-bottom-padding-x);
30-
$outer-bottom-padding-x: sin($teta) * $radius;
31-
$outer-bottom-padding-y: cos($teta) * $radius;
32-
33-
// We'll name the points of the star starting from the top and in clockwise
34-
// order
35-
$A-x: 0;
36-
$A-y: -$radius;
37-
38-
$B-x: $inner-top-padding-x;
39-
$B-y: -$inner-top-padding-y;
40-
41-
$C-x: $outer-top-padding-x;
42-
$C-y: -$outer-top-padding-y;
43-
44-
$D-x: $inner-bottom-padding-x;
45-
$D-y: $inner-bottom-padding-y;
46-
47-
$E-x: $outer-bottom-padding-x;
48-
$E-y: $outer-bottom-padding-y;
49-
50-
$F-x: 0;
51-
$F-y: $inner-radius;
52-
53-
$G-x: -$outer-bottom-padding-x;
54-
$G-y: $outer-bottom-padding-y;
55-
56-
$H-x: -$inner-bottom-padding-x;
57-
$H-y: $inner-bottom-padding-y;
58-
59-
$I-x: -$outer-top-padding-x;
60-
$I-y: -$outer-top-padding-y;
61-
62-
$J-x: -$inner-top-padding-x;
63-
$J-y: -$inner-top-padding-y;
64-
65-
// Converting to px and placing relative to origin
66-
$A-x: $A-x * 1px + $left;
67-
$A-y: $A-y * 1px + $top;
68-
$B-x: $B-x * 1px + $left;
69-
$B-y: $B-y * 1px + $top;
70-
$C-x: $C-x * 1px + $left;
71-
$C-y: $C-y * 1px + $top;
72-
$D-x: $D-x * 1px + $left;
73-
$D-y: $D-y * 1px + $top;
74-
$E-x: $E-x * 1px + $left;
75-
$E-y: $E-y * 1px + $top;
76-
$F-x: $F-x * 1px + $left;
77-
$F-y: $F-y * 1px + $top;
78-
$G-x: $G-x * 1px + $left;
79-
$G-y: $G-y * 1px + $top;
80-
$H-x: $H-x * 1px + $left;
81-
$H-y: $H-y * 1px + $top;
82-
$I-x: $I-x * 1px + $left;
83-
$I-y: $I-y * 1px + $top;
84-
$J-x: $J-x * 1px + $left;
85-
$J-y: $J-y * 1px + $top;
86-
87-
@return polygon(
88-
$A-x $A-y,
89-
$B-x $B-y,
90-
$C-x $C-y,
91-
$D-x $D-y,
92-
$E-x $E-y,
93-
$F-x $F-y,
94-
$G-x $G-y,
95-
$H-x $H-y,
96-
$I-x $I-y,
97-
$J-x $J-y
98-
);
18+
$ang: $rotate;
19+
@for $i from 0 to 11 {
20+
$r: $radius;
21+
@if ($i % 2 == 1) {
22+
$r: $inner-radius;
23+
}
24+
$result: append($result, ($left + $r * sin($ang) $top - $r * cos($ang)), comma);
25+
$ang: $ang + 36;
26+
}
27+
28+
@return $result;
9929
}

0 commit comments

Comments
 (0)