-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLoremIpsumBlocks.coffee
More file actions
54 lines (46 loc) · 1.71 KB
/
LoremIpsumBlocks.coffee
File metadata and controls
54 lines (46 loc) · 1.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# LoremIpsumBlocks Module
# Ray
# 2015-10-22 17:53:53
range = [1..23]
chances = [
0.027, 0.679, 4.730, 7.151, 10.804,
13.674, 14.751, 13.616, 11.356, 8.679,
5.913, 3.792, 2.329, 1.232, 1.268
] # http://norvig.com/mayzner.html
skewRadomNumber = (range, chances) ->
finalArray = []
for key, value of range
for i in [1..chances[key] * 100]
finalArray.push value
return Utils.randomChoice finalArray
class exports.Blocks extends Layer
constructor: (options={}) ->
options.width ?= Screen.width - 20*2
options.backgroundColor ?= "transparent"
super options
options.wordCount ?= 24
options.wordSpacing ?= 6
options.letterHeight ?= 12
options.letterWidth ?= 6
options.lineSpacing ?= 6
options.color ?= "silver"
linesCreated = 0
lastWordRight = 0
for i in [0...options.wordCount]
r = skewRadomNumber(range, chances) * options.letterWidth
lineBreaking = lastWordRight + r > options.width
if lineBreaking
lastWordRight = 0
linesCreated++
new Layer
superLayer: @
height: options.letterHeight
width: r
x: lastWordRight
y: linesCreated * (options.lineSpacing + options.letterHeight)
backgroundColor: options.color
name: "word_#{i}"
# html: i
lastWordWidth = @subLayersByName("word_#{i}")[0].width + options.wordSpacing
lastWordRight += lastWordWidth
@height = linesCreated * (options.letterHeight + options.lineSpacing) + options.letterHeight