Close

functions

A project log for JS "Art"

Javascript Generated "Art"

ivan-lazarevicIvan Lazarevic 06/08/2015 at 19:220 Comments
/**
 * Create random dots
 * @param  {[type]} no number of dots
 * @return {[type]}    [description]
 */
function random(no) {
    var dots = [
        [0, 0],
        [0, height],
        [width, 0],
        [width, height]
    ]; // corner dots

    for (var i = 0; i < no / 20; i++) {
        dots.push([0, Math.random() * height]);
        dots.push([Math.random() * width, height]);
        dots.push([width, Math.random() * height]);
        dots.push([Math.random() * width, 0]);

    }

    for (var i = 0; i < no - no / 20; i++) {
        dots.push([Math.random() * width, Math.random() * height]);
    }

    return dots;

}
/**
 * Put dots in spiral
 * @param  {[type]} no     [description]
 * @param  {[type]} factor [description]
 * @return {[type]}        [description]
 */
function spiral(no, factor) {

    var dots = [];

    no = no || 1000;
    factor = factor || 1;

    for (i = 0; i < no; i++) {
        angle = factor * i;
        x = (20 + angle) * Math.cos(angle);
        y = (40 + angle) * Math.sin(angle);
        dots.push([x + width / 2, y + height / 2]);
    }

    return dots;

};

Discussions