Fixed and List Values
Fixed Values
All rules may take fixed values. A fixed value is just a string with the value you would apply to the CSS directive if you were writing the CSS by hand. As when writing CSS by hand, if you supply an string with an invalid value it will not work. It's your responsibility to provide correct values.
Note: Fixed values are very useful when dealing with compound rules (which we'll see later). For general rules (like the following example) it's always better to use a general CSS rule targeting the spans on the element than using fixed rules.
Example
On the following example we are using a fixed value on the border-bottom-style and border-bottom-color, while generating the border-bottom-width.
var rules = {
borderBottomColor: "#303030",
borderBottomStyle: "solid",
borderBottomWidth: {
min: 1,
max: 21,
steps: true
}
}
var growingBorderBottom = new generativeText(rules);
growingBorderBottom.applyToElementById("example1");
List Values
All rules may take List values. A List value is just an array of strings with values to be applied to the CSS directive. generativeText will randomly pick the value from the list.
Example
List Values with steps
If you add the steps option the value will be picked sequentially from the beginning of the array of values. When the end of the array is reached, the count will restart from the first element. This can be used to alternate between 2 (or more) values.
Example
List Values with stepFunctions
A stepFunction is a function that is applied on each step of the process. When using Lists an stepFunction must return the index of the value on the list. An stepFunction on a List value will have access the the following variables:
this.totalSteps //Contains the total number of steps
this.currentStep //Contains the current step
this.valuesLength //The lenght of the list of values
Example
var rules4 = {
textTransform: {
values:["lowercase", "uppercase"],
stepFunction: function() {
if(this.currentStep == 1 || (this.currentStep % 5 == 0) ||
(this.currentStep % 7 == 0) || (this.currentStep % 11 == 0) ) {
return 1;
}
return 0;
},
},
}
var schizo = new generativeText(rules4);
schizo.applyToElementById("example4");
#example4 { font-family: 'Lora'; }
Rules that may take only Fixed or List Values
All Rules may take Fixed o List values, however there are some rules that can only take Fixed or List values. This is the list:
- animation
- animationDirection
- animationFillMode
- animationName
- animationPlayState
- animationTimingFunction
- backfaceVisibility
- background
- backgroundAttachment
- backgroundBlendMode
- backgroundClip
- backgroundOrigin
- backgroundImage
- backgroundRepeact
- border
- borderBottom
- borderBottomStyle
- borderCollapse
- borderImage
- borderImageOutset
- borderImageRepeat
- borderImageSlice
- borderImageSource
- borderLeft
- borderLeftStyle
- borderRight
- borderRightStyle
- borderStyle
- borderTop
- borderTopStyle
- borderDecorationBreak
- boxSizing
- clear
- clipPath
- columns
- cursor
- display
- float
- font
- fontFamily
- fontStretch
- fontStyle
- fontVariant
- fontWeight
- listStyle
- listStyleImage
- listStylePosition
- listStyleType
- mixBlendMode
- outline
- outlineStyle
- textAlign
- textDecoration
- textDecorationLine
- textDecorationStyle
- textTransform
- transition
- verticalAlign
- visibility