Og code - Mahima

mail@pastecode.io avatar
unknown
javascript
4 months ago
1.1 kB
1
Indexable
function start(){
    
    // Fills up all each line with color until it reaches top of image 
    for (var i = 0; i < 27; i++){
        
        loopThru();
        
    }

} 

// Does not allow nested for loop so it is in a functon
function loopThru(){
    // moves through each pixel in line and colors it 
    for(var i = 0; i < 47; i++ ){
        
        move(); 
        paintColor(); 
    }
    reset(); 

    
}
/* Once Karel reaches the end of the row, 
    resets Karel to start on a new row 
*/
function reset(){
    
    while (notFacingWest()){
        
        turnRight();
    }
    
    for(var i = 0; i < 47; i++ ){
            
           move(); 
        
    }
    while (notFacingNorth()){
        
        turnLeft();
    }
    if (frontIsClear()){
        
        move();
        paintColor(); 
    }
    while (notFacingEast()){
        
        turnRight();
    }
    
}
// we can make this like a bigger function and put 27 line functions inside 
// maybe use if else to check 
function paintColor(){
    
    if (colorIs(Color.red)){
        paint(Color.blue);
    }else{
        paint(Color.red);
    } 
    }
Leave a Comment