Math 最大到0到最大算法

Math 最大到0到最大算法,math,compass-sass,sass,Math,Compass Sass,Sass,首先,让我警告你,我的数学知识相当有限(因此我来这里问这个问题) 这是一个愚蠢的例子,但我本质上想要的是有一个可变的行数,并且能够设置一个最大值,然后对于每一个渐进的行,将该值减小到一半,在这一点上,开始将值再次增加到最后一行的最大值 为了说明这一点。。。考虑到:maxValue=20,以及rows=5,我需要能够获得行值的以下值(是的,甚至是0): 但也有一些限制,因为我试图在Compass中使用SASS来实现这一点。有关可用的操作,请参见,但为了向您提供其要点,只有基本操作可用 我能够循环遍

首先,让我警告你,我的数学知识相当有限(因此我来这里问这个问题)

这是一个愚蠢的例子,但我本质上想要的是有一个可变的行数,并且能够设置一个最大值,然后对于每一个渐进的行,将该值减小到一半,在这一点上,开始将值再次增加到最后一行的最大值

为了说明这一点。。。考虑到:
maxValue=20
,以及
rows=5
,我需要能够获得行值的以下值(是的,甚至是0):

但也有一些限制,因为我试图在Compass中使用SASS来实现这一点。有关可用的操作,请参见,但为了向您提供其要点,只有基本操作可用

我能够循环遍历这些行,所以只需要对序列中的每一行进行计算。这是我能够使用的循环类型:

$maxValue:20;
$rows:5;

@for $i from 1 through $rows {
    // calculation here.
}

我以前没有真正使用过SASS,但是使用基本的if和floor函数尝试一下类似的方法,不确定是否会起作用

// set various variables
$maxValue:20;
$rows:5;
// get row number before middle row, this instance it will be 2
$middleRow = floor( $maxValue / $rows )
// get increment amount, this instance should be 10
$decreaseValue = ( max / floor( rows / 2) )

@for $i from 0 through $rows - 1 {

   @if $i <= $middleRow {

      ( $maxValue- ( $decreaseValue * $i ) )

    }

   @else{

    // times by -1 to make positive value
       ( $maxValue - ( $decreaseValue * -$i ) ) * -1

    }
}
//设置各种变量
$maxValue:20;
$rows:5;
//在中间行之前获取行号,此实例将为2
$middleRow=楼层($maxValue/$rows)
//获取增量金额,此实例应为10
$decreaseValue=(最大/楼层(第2排))
@对于从0到$1行的$i{

@如果$i Sass真的有地板功能的话:工作起来很有魅力!万分感谢!
// set various variables
$maxValue:20;
$rows:5;
// get row number before middle row, this instance it will be 2
$middleRow = floor( $maxValue / $rows )
// get increment amount, this instance should be 10
$decreaseValue = ( max / floor( rows / 2) )

@for $i from 0 through $rows - 1 {

   @if $i <= $middleRow {

      ( $maxValue- ( $decreaseValue * $i ) )

    }

   @else{

    // times by -1 to make positive value
       ( $maxValue - ( $decreaseValue * -$i ) ) * -1

    }
}