Loop through array with LESS - Modify values - Get new array -


i loop through array, modify each item, , spit out new array modified items.

i have strong distaste foobar examples since they're abstract.. seems strangely applicable here:

note: half pseudo code, since don't know how work.

.loop (@var)     @array: (@var + 1), (@var + 2), (@var + 3);     // outputs @array: var1, var2 var3; (when @var = var)      .-(@i: length(@array)) when (@i > 0) {         @item: e(extract(@array, @i));          @newitem: @item + bar;      .-((@i - 1));      @newarray:@newitem,@newitem,@newitem;// ???? ).-;  .test {     .loop ('foo'); } 

in above example, calling loop foo should output foo1bar, foo2bar, foo3bar

or something... last bit tricky/confusing part. that's not how access array, that...

to summarize: want pass single variable through loop. within loop, define array based on variable (imagine splitting single color separated values). using new array, want loop through each item within it, modify (imagine darkening each value), , new array new modified values.

another example:

.loop (@color: red) {     @separations: red(@color), green(@color), blue(@color);     // outputs 255, 0, 0      .-(@i: length (@array)) when (@i > 0) {         @sep: e(extract(@array, @i));          @newsep: floor(@sep / 2);     .-((@i - 1));      } .-;      @newarray: @item{i};     //outputs @newarray: 127, 0, 0; } 

and no, i'm not trying change hue of color. i'm trying relative luminosity of given color, requires defining color, separating array of it's individual rgb values, doing conditional math each one, , getting new array of modified values - need plugged formula.

hope that's vague/detailed enough.

thanks input/advice!

here's example of being achieved in scss

@function color_luminance($color) {     // adapted from: https://github.com/leaverou/contrast-ratio/blob/gh-pages/color.js     // formula: http://www.w3.org/tr/2008/rec-wcag20-20081211/#relativeluminancedef     $rgba: red($color), green($color), blue($color);     $rgba2: ();      @for $i 1 through 3 {         $rgb: nth($rgba, $i);         $rgb: $rgb / 255;          $rgb: if($rgb < .03928, $rgb / 12.92, pow(($rgb + .055) / 1.055, 2.4));          $rgba2: append($rgba2, $rgb);     }      @return .2126 * nth($rgba2, 1) + .7152 * nth($rgba2, 2) + 0.0722 * nth($rgba2, 3); } 


Comments