0.1.0 • Published 4 years ago

@danscan/modular-scale v0.1.0

Weekly downloads
1
License
MIT
Repository
-
Last release
4 years ago

Modular Rem Scale

Easily configure and generate modular scales in rems.

Configuration

The ModularRemScale constructor takes a config object with the following properties:

propertytypedescription
firstPowernumberThe power value of the first step in the scale.
rationumber | RatioNameThe ratio to use for the scale.
rootFontSizePxnumberThe root font size to use when converting rem values to px.

Methods

methodtypedescription
getMap(steps: number) => ModularRemScaleMapGenerate an object of steps entries, mapping step numbers (starting at 1) to rem values on the scale.
getStepPx(step: number) => stringGet the px value of a step on the scale.

Named Ratios

KeyValueDecimal Value
minor-second16 / 151.0667
major-second9 / 81.125
minor-third6 / 51.2
augmented-fourth√21.4142
perfect-fifth3 / 21.5
minor-sixth8 / 51.6
golden1.618033...1.61803398875
phi1.618033...1.61803398875
major-sixth5 / 31.6667
minor-seventh16 / 91.7778
major-seventh15 / 81.875
octave22
major-tenth5 / 22.5
major-eleventh8 / 32.6667
major-twelfth33
double-octave44

Example

import ModularRemScale from '@danscan/modular-scale';

const scale = new ModularRemScale({
  firstPower: -1,
  ratio: 'perfect-fifth',
  rootFontSizePx: 12,
});

scale.getMap(15);
// {
//   '1': '0.67rem',
//   '2': '1.00rem',
//   '3': '1.50rem',
//   '4': '2.25rem',
//   '5': '3.38rem',
//   '6': '5.06rem',
//   '7': '7.59rem',
//   '8': '11.39rem',
//   '9': '17.09rem',
//   '10': '25.63rem',
//   '11': '38.44rem',
//   '12': '57.67rem',
//   '13': '86.50rem',
//   '14': '129.75rem',
//   '15': '194.62rem'
// }

scale.getStepPx(2);
// 12px

scale.getStepPx(3);
// 18px

scale.getStepPx(4);
// 27px