Frequently used mathematical functions are also available in Less. These functions include, among others, functions for rounding and trigonometry. In this recipe, you will create a list of colors, which covers the visible spectrum, using the sin()
and floor()
functions.
In this recipe, you will compile the Less code using the client-side less.js
compiler, as described in the Downloading, installing, and integrating less.js recipe in Chapter 1, Getting to Grips with the Basics of Less. Finally, you will inspect the result in your browser. You will also need a text editor to edit your Less and HTML files.
Create a Less file named
rainbow.less
and write the following Less code into it:.rainbow(@number,@frequency:0) when (@number > 0) { .setfrequency() when (@frequency = 0) { @frequency: 5 / @number; } .setfrequency; .rainbow(@number - 1, @frequency); @red: floor(sin(@frequency * (@number - 1) + 0) * 127 + 128); @green...