任何人可以幫助我瞭解如何作出正確的正多邊形(本圖必須有20角)創建於SCSS
我在這裏做的第一步http://codepen.io/anon/pen/MpbeLB
(對不起,這code.The計算器這麼想的支持SCSS)
我使用這個公式http://ru.wikipedia.org/wiki/Правильный_многоугольник找到正多邊形的頂部。
$colorBackground: #121d1e;
$colorC: #ace9ae;
$colorW: #fff;
$h: 600px;
$w: $h /0.75;
@mixin br($radius) {
-webkit-border-radius: $radius;
-moz-border-radius: $radius;
-ms-border-radius: $radius;
border-radius: $radius;
}
@mixin br50 {
-webkit-border-radius: 50%;
-moz-border-radius: 50%;
-ms-border-radius: 50%;
border-radius: 50%;
}
@function pi() {
@return 3.14159265359;
}
@function pow($number, $exp) {
$value: 1;
@if $exp > 0 {
@for $i from 1 through $exp {
$value: $value * $number;
}
} @else if $exp < 0 {
@for $i from 1 through -$exp {
$value: $value/$number;
}
}
@return $value;
}
@function fact($number) {
$value: 1;
@if $number > 0 {
@for $i from 1 through $number {
$value: $value * $i;
}
}
@return $value;
}
@function rad($angle) {
$unitless: $angle/($angle * 0 + 1);
$unitless: $unitless/180 * pi();
@return $unitless;
}
@function sin($angle) {
$sin: 0;
$angle: rad($angle);
// Iterate a bunch of times.
@for $i from 0 through 10 {
$sin: $sin + pow(-1, $i) * pow($angle, (2 * $i + 1))/fact(2 * $i + 1);
}
@return $sin;
}
@function cos($angle) {
$cos: 0;
$angle: rad($angle);
// Iterate a bunch of times.
@for $i from 0 through 10 {
$cos: $cos + pow(-1, $i) * pow($angle, 2 * $i)/fact(2 * $i);
}
@return $cos;
}
@function tan($angle) {
@return sin($angle)/cos($angle);
}
.mainBlock {
position: relative;
display: inline-block;
width: $w;
height: $h;
border: 1px solid #f00;
}
.centralCircle {
position: absolute;
top: 50%;
left: 50%;
margin-top: (-$h*0.1);
margin-left: (-$h*0.1);
width: $h *0.2;
height: $h * 0.2;
background-color: $colorC;
@include br50;
animation: centralWrapperMove 1s ease-in infinite alternate;
}
@keyframes centralDotMove {
0% {
transform: scale(1);
transform-origin: center center;
}
100% {
transform: scale(0);
transform-origin: center center;
}
}
@keyframes centralWrapperMove {
0% {
transform: scale(1);
transform-origin: center center;
}
100% {
transform: scale(0.2);
transform-origin: center center;
}
}
$workW: $w;
$workH: ($h/0.75);
$maxScale: 0.03;
$borderScale: 0.2;
$workerHeight: $workH*$maxScale;
$workerWidth: $workW*$maxScale;
.workerCircle {
position: absolute;
top: 50%;
left: 50%;
width: $workerWidth;
height: $workerHeight;
margin: (-$workH*$maxScale/2) 0 0 (-$workW*$maxScale/2);
@include br50;
border: ($workerWidth*$borderScale) solid red;
z-index: 2;
$n: 20;
$r: 180px;
$mygrad: 18; /// angels
$fi: (pi())/2;
@for $i from 1 through 20 {
&:nth-of-type(#{$i}) {
$j: ($i - 1);
transform: translate(($r* cos(($mygrad*$j)+ ((2*pi()*$j)/$n))), ($r* sin(($mygrad*$j)+ ((2*pi()*$j)/$n))));
/// This formula works wrong
}
}
.workerDot {
position: absolute;
top: 50%;
left: 50%;
width: $workerWidth/4;
height: $workerHeight/4;
margin: (-$workerWidth/8) 0 0 (-$workerHeight/8);
@include br50;
background: #fff;
}
}
.wrappen {
position: relative;
width: 100%;
height: 100%;
margin: 0;
padding: 0;
}
<div class="mainBlock">
<div class="workerCircle"></div>
<div class="workerCircle"></div>
<div class="workerCircle"></div>
<div class="workerCircle"></div>
<div class="workerCircle"></div>
<div class="workerCircle"></div>
<div class="workerCircle"></div>
<div class="workerCircle"></div>
<div class="workerCircle"></div>
<div class="workerCircle"></div>
<div class="workerCircle"></div>
<div class="workerCircle"></div>
<div class="workerCircle"></div>
<div class="workerCircle"></div>
<div class="workerCircle"></div>
<div class="workerCircle"></div>
<div class="workerCircle"></div>
<div class="workerCircle"></div>
<div class="workerCircle"></div>
<div class="workerCircle"></div>
</div>
我固定代碼。那個更好嗎? – BlackStar1991
您可以將SCSS轉換成CSS和其添加在這裏的工作演示的緣故。你能否更好地解釋你的問題,還有一個圖像(你想在輸出中獲得什麼)。 –
我想在SCSS上獲得正確的公式。這個公式應該畫正多邊形(20個角)這個角度的頂部應該是圓的中心。 – BlackStar1991