Giter VIP home page Giter VIP logo

modular-scale's Introduction

Sassy Modular Scale

Put down the calculator and let Sass do the work.

Sassy Modular Scale is a Sass based mixin that calculates the incremental values of the modular scale in proportion to a set size and ratio. It was inspired by and adapted from Tim Brown's modularscale.com.

Sassy Modular Scale can be used as a Compass extension and can be installed as a Ruby gem.

Installation

gem install modular-scale

Add require 'modular-scale' to your Compass config file.

Import the file into your stylesheets: @import 'modular-scale';

Usage

Modular-scale is used as a function. Simply pass it through in place of any value to generate a value based on a modular scale.

width: modular-scale(2); // two up the modular scale
width: ms(2); // Shorthand for the line above
width: modular-scale(2, 1em); // two up the modular scale with a base size of 1em
width: modular-scale(2, 1em, octave() ); // Same as above but on an octave scale

You can output a list to your terminal to help you find out what values are on your scale.

@include modular-scale-list($start, $end, $base-size, $ratio);

By default, it writes 0-20 on the scale. You can also use shorthand to make things more efficient.

@include ms-list; // shorthand without attributes
@include ms-list($start, $end, $base-size, $ratio); // shorthand with attributes

You can also write the output to your CSS file if you are using the terminal:

@include ms-list-output($start, $end, $base-size, $ratio);

As a side effect of the modular-scale functions a power function is also available.

@include power($base, $power);

Sassy Modular Scale can be used as a function, like so:

// Use as a function. Fill in the multiple, base-size, and ratio
height: modular-scale(7, 16px, golden() );

You can also 'lace' multiple ratios together by passing them in as a list (space-separated)

.lace {
  width: ms(7, 16px, golden() fourth() );
}

You can also set the $base-size variable to a list to interrelate two significant known sizes in your design note: the starting point of the scale will always be the lowest value in this list

.multibases {
  width: ms(7, 16px 300px, golden() );
}

You can use multiple $base-sizes and multiple $ratios together

.multibase-multiratio {
  width: ms(7, 16px 300px, golden() fourth() );
}

Ratios

Modular scale includes functions for a number of classic design and musical scale ratios. You can add your own ratios as well.

By default, the variable $ratio is set to golden().

FunctionRatioDecimal value
golden()1:1.6181.618
double-octave()1:44
major-twelfth()1:33
major-eleventh()3:82.667
major-tenth()2.52:5
octave()1:22
major-seventh()8:151.875
minor-seventh()9:161.778
major-sixth()3:51.667
minor-sixth()5:81.6
fifth()2:31.5
augmented-fourth()1:โˆš21.414
fourth()3:41.333
major-third()4:51.25
minor-third()5:61.2
major-second()8:91.125
minor-second()15:161.067

Add your own ratio in Sass by setting a variable and passing that to modular-scale.

$my-variable: 1 / 3.14159265;
$ratio: $my-variable;

Inspiration

Sassy Modular Scale was adapted from modularscale.com by Tim Brown (@nicewebtype). Tim also wrote a supporting article at A List Apart titled "More Meaningful Typography". Additional inspiration goes to Robert Bringhurst, author of "The Elements of Typographic Style" - specifically Chapter 8 titled "Shaping the Page"

License

Copyright (c) 2011 Scott Kellum (@scottkellum), Adam Stacoviak (@adamstac) and Mason Wendell (@codingdesigner)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

modular-scale's People

Contributors

scottkellum avatar codingdesigner avatar adamstac avatar robwierzbowski avatar bookcasey avatar edwardoriordan avatar snugug avatar

Watchers

James Cloos avatar Jason Newton avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.