Creating a Image Algorithmic-ally

function dist(pixel,x,y){
    var dx = pixel.getX() - x ;
    var dy = pixel.getY() - y ;
    return Math.sqrt(dx * dx + dy * dy);
}
// start with a blank image
var output = new SimpleImage(320,320);
// write something here
for (var pixel of output.values()){
    if (dist(pixel,100,100) < 50 ){
        pixel.setRed(255 - 4 * dist (pixel,100,100));
    }
    else if (dist(pixel,200,200) < 80 ){
        pixel.setGreen(255 - 4 * dist (pixel,200,200));
    }  
 
     
    else if (Math.random() > 0.995 ){
        pixel.setRed(255);
        pixel.setGreen(255);
    }
    pixel.setBlue(Math.max(1.05 * pixel.getY() - pixel.getX() ,  pixel.getX() - 1.5 * pixel.getY() ))
}
print (output);




OR


//all the points here are numbered in the same way the numbers are displayed in code as comments
// Since The Function Is Called It runs And creates a circle
function dist(pixel,x,y){
    
    var dx = pixel.getX() - x ;
    var dy = pixel.getY() - y ;
    return Math.sqrt(dx * dx + dy * dy);
}
// I started with a blank image of size 256*256 as shown in the code below with Comment as 1  
var output = new SimpleImage(256,256);
// now will will take the cordinates of the image(which i consider as mercury) as 80,80 & green(earth) as 255,255 blue(venus) as 150,150 and so on and create a circle of size 25 by calling the function dist 
for (var pixel of output.values()){
    if (dist(pixel,80,80) < 25 ){
        pixel.setRed(255 - 4 * dist (pixel,80,80));
    }
    else if (dist(pixel,255,255) < 80 ){
        pixel.setGreen(255 - 2.5 * dist (pixel,255,255));
    }  
    else if  (dist(pixel,150,150) < 60 ){
        pixel.setBlue(255 - 3.5 * dist (pixel,150,150));
    }  
    else if  (dist(pixel,1,1) < 80 ){
        (pixel.setGreen(205)+pixel.setRed(205)) - 3.5 * dist (pixel,1,1);
    }  
       
    else if (Math.random() > 0.995 ){
        pixel.setRed(255);
        pixel.setGreen(255);
    }
    //pixel.setBlue(Math.max( 1.05 * pixel.getX() - pixel.getY() ,  pixel.getY() -  1.05 * pixel.getX() ))
    
}
print (output);




No comments:

Post a Comment

కరోనా కోవిడ్ -19 గురించి ఏ వికీపీడియా మీకు చెప్పలేము?

కరోనా కోవిడ్ -19 గురించి ఏ వికీపీడియా మీకు చెప్పలేము? మిమ్మల్ని మీరు రక్షించుకోండి  Your మీ చేతులను తరచుగా కడగాలి Eyes మీ కళ్ళు, న...