Draw image using JavaScript

1)


function dist(pixel,x,y){
    var dx = pixel.getX() - x;
    var dy = pixel.getY() - y;
    
    return Math.sqrt(dx*dx + dy*dy);
}

var output = new SimpleImage(320,320);

for (var pix of output.values()){
    if(dist(pix,100,100) < 50){
        pix.setRed(255 - 4*dist(pix,100,100));
    }
    else if(dist(pix,200,200)  0.995){
        pix.setRed(255);
        pix.setGreen(255);
        pix.setBlue(255);
    }
    pix.setBlue(Math.max(1.5*pix.getY() - pix.getX(), pix.getX() - 1.5*pix.getY()));
}
print(output);
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s