Book Image

Less Web Development Cookbook

Book Image

Less Web Development Cookbook

Overview of this book

Table of Contents (19 chapters)
Less Web Development Cookbook
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Using mathematical functions


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.

Getting ready

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.

How to do it…

  1. 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...