Linescapes Iteration 9

Sep 07 2011 Published by under Uncategorized

Send to Kindle

A different gety function:

$(function() {
    var canvas, linescape, hills;
    
    canvas = $("#canvas").get(0);
    linescape = new LineScape(canvas);
    linescape.xres = 1;
    linescape.zres = 0.5;
    
    hills = [];
    for(var i = 0; i < 100; i += 1) {
        hills[i] = {x:Math.random() * 1000 - 500, z: Math.random() * 2000, force:Math.random() * 2000 + 1000};
    }
    
    linescape.gety = function(x, z) {
        var y = 600;
        for(var i = 0; i < 100; i += 1) {
            var hill = hills[i];
            var dx = hill.x - x;
            var dz = hill.z - z;
            var dist = Math.sqrt(dx * dx + dz * dz);
            y -=  Math.sin(1 / dist * 1000) * 10;
        }
        return this.ycenter + y;
    }

    linescape.draw();
});

Result.

Send to Kindle

3 responses so far. Comments will be closed after post is one year old.