block by nitaku 8270950

Random pronounceable strings

Full Screen

This example uses a predefined syllabary to produce random pronounceable strings. Reload to create new strings.

index.js

(function() {

  window.main = function() {
    var body, i, j, randlen, randsy, syllables, _results;
    syllables = ['bi', 'bo', 'bu', 'ta', 'se', 'tri', 'su', 'ke', 'ka', 'flo', 'ko', 'pi', 'pe', 'no', 'go', 'zo', 'fu', 'fo', 'si', 'pa', 'ar', 'es', 'i', 'kya', 'kyu', 'fle', 'o', 'ne', 'na', 'le', 'lu', 'ma', 'an'];
    randlen = function() {
      return 2 + Math.floor(Math.random() * 4);
    };
    randsy = function() {
      return syllables[Math.floor(Math.random() * syllables.length)];
    };
    body = d3.select('body');
    _results = [];
    for (i = 0; i < 11; i++) {
      _results.push(body.append('div').text(((function() {
        var _ref, _results2;
        _results2 = [];
        for (j = 0, _ref = randlen(); 0 <= _ref ? j < _ref : j > _ref; 0 <= _ref ? j++ : j--) {
          _results2.push(randsy());
        }
        return _results2;
      })()).join('')));
    }
    return _results;
  };

}).call(this);

index.html

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>Random names</title>
        <link type="text/css" href="index.css" rel="stylesheet"/>
        <script src="//d3js.org/d3.v3.min.js"></script>
        <script src="index.js"></script>
    </head>
    <body onload="main()">
    </body>
</html>

index.coffee

window.main = () ->
    syllables = ['bi','bo','bu','ta','se','tri','su','ke','ka','flo','ko','pi','pe','no','go','zo','fu','fo','si','pa','ar','es','i','kya','kyu','fle','o','ne','na','le','lu','ma','an']
    
    randlen = () -> 2+Math.floor(Math.random()*4)
    randsy = () -> syllables[Math.floor(Math.random()*syllables.length)]
    
    body = d3.select('body')
    
    for i in [0...11]
        body.append('div')
            .text((randsy() for j in [0...randlen()]).join(''))
            

index.css

body {
  margin-top: 40px;
  margin-left: 60px;
}

div {
  text-transform: capitalize;
  font-size: 22pt;
  color: #333333;
  margin-bottom: 4px;
}

index.sass

body
    margin-top: 40px
    margin-left: 60px
    
div
    text-transform: capitalize
    font-size: 22pt
    color: #333
    margin-bottom: 4px