final code

mail@pastecode.io avatar
unknown
javascript
6 days ago
21 kB
5
Indexable
Never
/*
*** FUNCTION NAMING FORMAT***
1)   fill - complete function that fills the area with color 
     loopThru - when it is filling a square it iterates and fills each pixel 
     reset - compliments the loopThru function to help fill each pixel 
     paintColor - compliements the fill function to paint with correct color 

2)  There will be either T,M,B at the end of each basic function name 
    This is to indicate wheater the function corresponds to the
    Top, Middle, or Bottom 
    
3) There Will be either R,L,C after the previous top, middle, or bottom to 
    indicate weather it is Right, Left, or Center 
    
4) If there are multiple functions in the same area of the picture, 
   For example) two functions that paint the bottom left. 
   They are distinguisehed by a spelled out number after the function 


*/ 

// length 14, idk height, right bottom - BR function 

function start(){
    
    
     fillBottom();
     fillLake();
     fillMountains();
     fillRiver();
     fillTreestwo();
     fillSky();
     fillSky2();
}

function fillBottom(){
    // BOTTOM LEFT CORNER OF THE IMAGE (8*8) back square 
    
    // Fills up all each line with color until it reaches top of image 
    for (var i = 0; i < 8; i++){
        
        loopThruBL();
    }
    while(notFacingEast()){
        
        turnRight();
    }
    for (var i = 0; i < 9; i++){
        
        move();
    }
    while(notFacingSouth()){
        
        turnRight();
    }
    for (var i = 0; i < 8; i++){
        
        move();
    }
    while(notFacingEast()){
        
        turnRight();
    }
    for (var i = 0; i < 5; i++){
        
        loopThruBLtwo();
    }
    while(notFacingEast()){
        
        turnRight();
    }
    for (var i = 0; i < 12; i++){
        
        move();
    }
    while(notFacingSouth()){
        
        turnRight();
    }
    for (var i = 0; i < 5; i++){
        
        move();
    }
    while(notFacingEast()){
        
        turnRight();
    }
    move();
    paintColorBLtwo();
    move();
    paintColorBLtwo();
    while(notFacingNorth()){
        
        turnLeft();
    }
    move();
    while(notFacingWest()){
        
        turnLeft();
    }
    move();
    paintColorBLtwo();
    while(notFacingSouth()){
        
        turnLeft();
    }
    move();
    while(notFacingEast()){
        
        turnLeft();
    }
    for (var i = 0; i < 12; i++){
        
        move();
    }
    for (var i = 0; i < 6; i++){
        
        loopThruBR();
    }
    while(notFacingSouth()){
        
        turnRight();
    }
    for (var i = 0; i < 6; i++){
        
        move();
    }
    while(notFacingWest()){
        
        turnLeft();
    }
    for (var i = 0; i < 3; i++){
        
        move();
        paintColorBR();
    }
    turnAround();
    for (var i = 0; i < 2; i++){
        
        move();
    }
    while(notFacingNorth()){
        
        turnLeft();
    }
    move();
    paintColorBR();
    move();
    paintColorBR();

} 

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

    
}
/* Once Karel reaches the end of the row, 
    resets Karel to start on a new row 
*/
function resetBL(){
    
    while (notFacingWest()){
        
        turnRight();
    }
    
    for(var i = 0; i < 8; i++ ){
            
           move(); 
        
    }
    while (notFacingNorth()){
        
        turnLeft();
    }
    if (frontIsClear()){
        
        move();
        paintColorBL(); 
    }
    while (notFacingEast()){
        
        turnRight();
    }
    
}
// we can make this like a bigger function and put 27 line functions inside 
// maybe use if else to check 
function paintColorBL(){
    
    if (colorIs(Color.red)){
        paint(Color.blue);
    }else{
        paint(Color.createFromRGB(13, 25, 8, 255));
    } 
}
function paintColorBLtwo(){
    
    if (colorIs(Color.red)){
        paint(Color.blue);
    }else{
        paint(Color.createFromRGB(55,45,58,255));
    }
}
function loopThruBLtwo(){
    // moves through each pixel in line and colors it 
    for(var i = 0; i < 12; i++ ){
        
        paintColorBLtwo(); 
        move(); 
        paintColorBLtwo(); 
    }
    resetBLtwo(); 
}
function resetBLtwo(){
    
    while (notFacingWest()){
        
        turnRight();
    }
    
    for(var i = 0; i < 12; i++ ){
            
           move(); 
        
    }
    while (notFacingNorth()){
        
        turnLeft();
    }
    if (frontIsClear()){
        
        move();
        paintColorBLtwo(); 
    }
    while (notFacingEast()){
        
        turnRight();
    }
    
}
function paintColorBR(){
    
    if (colorIs(Color.red)){
        paint(Color.blue);
    }else{
        paint(Color.createFromRGB(49,66,42,255));
    }
}
function loopThruBR(){
    // moves through each pixel in line and colors it 
    for(var i = 0; i < 13; i++ ){
        
        paintColorBR(); 
        move(); 
        paintColorBR(); 
    }
    resetBR(); 
}
function resetBR(){
    
    while (notFacingWest()){
        
        turnRight();
    }
    
    for(var i = 0; i < 13; i++ ){
            
           move(); 
        
    }
    while (notFacingNorth()){
        
        turnLeft();
    }
    if (frontIsClear()){
        
        move();
        paintColorBR(); 
    }
    while (notFacingEast()){
        
        turnRight();
    }
    
}
function fillLake(){
    
    while(notFacingSouth()){
        
        turnLeft();
    }
    for (var i = 0; i < 2; i++){
        
        move();
    }
    while(notFacingWest()){
        
        turnLeft();
    }
    move();
    move(); 
    for (var i = 0; i < 8; i++){
        
        paintColorBC();
        move();
    }
    while(notFacingNorth()){
        
        turnLeft();
    }
    move();
    while(notFacingEast()){
        
        turnLeft();
    }
    for (var i = 0; i < 10; i++){
        
        paintColorBC();
        move();
    }
    while(notFacingNorth()){
        
        turnLeft();
    }
    move();
    while(notFacingWest()){
        
        turnLeft();
    }
    for (var i = 0; i < 12; i++){
        
        paintColorBC();
        move();
    }
    while(notFacingNorth()){
        
        turnLeft();
    }
    move();
    while(notFacingEast()){
        
        turnLeft();
    }
    move();
    for (var i = 0; i < 12; i++){
        
        paintColorBC();
        move();
    }
    while(notFacingNorth()){
        
        turnLeft();
    }
    move();
    while(notFacingWest()){
        
        turnLeft();
    }
    move();
    for (var i = 0; i < 12; i++){
        
        paintColorBC();
        move();
    }
    
    
}
function paintColorBC(){
    
    if (colorIs(Color.red)){
        paint(Color.blue);
    }else{
        paint(Color.createFromRGB(84,147,217,255));
    }
}
function fillMountains(){
    while(notFacingWest()){
        
        turnLeft();
    }
    while(frontIsClear()){
        
        move();
    }
    while(notFacingNorth()){
        
        turnRight();
    }
    for (var i = 0; i < 4; i++){
        
        move();
    }
    while(notFacingEast()){
        
        turnRight();
    }
    for (var i = 0; i < 10; i++){
        
        loopThruML();
    }
    for (var i = 0; i < 3; i++){
        
        loopThruMLtwo();
    }
    move();
    paintColorML();
    move();
    paintColorML();
    while(notFacingSouth()){
        
        turnRight();
    }
    for (var i = 0; i < 3; i++){
        
        move();
    }
    while(notFacingEast()){
        
        turnRight();
    }
    
    move();
    
    for (var i = 0; i < 3; i++){
        
        loopThruMLthree();
    }
    
    while(notFacingSouth()){
        
        turnRight();
    }
    move();
    move();
    move();
    while(notFacingEast()){
        
        turnRight();
    }
    move();
    paintColorML();
    move();
    paintColorML();
    move();
    paintColorML();
    for (var i = 0; i < 3; i++){
        
        move();
    }
    while(notFacingSouth()){
        
        turnRight();
    }
    for (var i = 0; i < 13; i++){
        
        move();
    }
    while(notFacingEast()){
        
        turnRight();
    }
    for (var i = 0; i < 4; i++){
        
       loopThruMC(); 
    }
    for (var i = 0; i < 3; i++){
        
       loopThruMCtwo(); 
    }
    move();
    move();
    move();
    for (var i = 0; i < 3; i++){
        
       loopThruMC(); 
    }
    for (var i = 0; i < 3; i++){
        
       loopThruMCtwo(); 
    }
    
    
    
} 
function paintColorML(){
    
    if (colorIs(Color.red)){
        paint(Color.blue);
    }else{
        paint(Color.createFromRGB(109,109,71,255));
    }
}
function loopThruML(){
    // moves through each pixel in line and colors it 
    for(var i = 0; i < 8; i++ ){
        
        paintColorML(); 
        move(); 
        paintColorML(); 
    }
    resetML(); 
}
function resetML(){
    
    while (notFacingWest()){
        
        turnRight();
    }
    
    for(var i = 0; i < 8; i++ ){
            
           move(); 
        
    }
    while (notFacingNorth()){
        
        turnLeft();
    }
    if (frontIsClear()){
        
        move();
        paintColorML(); 
    }
    while (notFacingEast()){
        
        turnRight();
    }
    
}
function loopThruMLtwo(){
    // moves through each pixel in line and colors it 
    for(var i = 0; i < 3; i++ ){
        
        paintColorML(); 
        move(); 
        paintColorML(); 
    }
    resetMLtwo(); 
}
function resetMLtwo(){
    
    while (notFacingWest()){
        
        turnRight();
    }
    
    for(var i = 0; i < 2; i++ ){
            
           move(); 
        
    }
    while (notFacingNorth()){
        
        turnLeft();
    }
    if (frontIsClear()){
        
        move();
        paintColorML(); 
    }
    while (notFacingEast()){
        
        turnRight();
    }
    
}
function loopThruMLthree(){
    // moves through each pixel in line and colors it 
    for(var i = 0; i < 2; i++ ){
        
        paintColorML(); 
        move(); 
        paintColorML(); 
    }
    resetMLthree(); 
}
function resetMLthree(){
    
    while (notFacingWest()){
        
        turnRight();
    }
    
    for(var i = 0; i < 3; i++ ){
            
           move(); 
        
    }
    while (notFacingNorth()){
        
        turnLeft();
    }
    if (frontIsClear()){
        
        move();
        paintColorML(); 
    }
    while (notFacingEast()){
        
        turnRight();
    }
    
}
function paintColorMC(){
    
    if (colorIs(Color.red)){
        paint(Color.blue);
    }else{
        paint(Color.createFromRGB(183,157,43,255));
    }
}
function loopThruMC(){
    // moves through each pixel in line and colors it 
    for(var i = 0; i < 38; i++ ){
        
        paintColorMC(); 
        move(); 
        paintColorMC(); 
    }
    resetMC(); 
}
function resetMC(){
    
    while (notFacingWest()){
        
        turnRight();
    }
    
    for(var i = 0; i < 38; i++ ){
            
           move(); 
        
    }
    while (notFacingNorth()){
        
        turnLeft();
    }
    if (frontIsClear()){
        
        move();
        paintColorMC(); 
    }
    while (notFacingEast()){
        
        turnRight();
    }
    
}
function loopThruMCtwo(){
    // moves through each pixel in line and colors it 
    for(var i = 0; i < 37; i++ ){
        
        paintColorMC(); 
        move(); 
        paintColorMC(); 
    }
    resetMCtwo(); 
}
function resetMCtwo(){
    
    while (notFacingWest()){
        
        turnRight();
    }
    
    for(var i = 0; i < 38; i++ ){
            
           move(); 
        
    }
    while (notFacingNorth()){
        
        turnLeft();
    }
    if (frontIsClear()){
        
        move();
        paintColorMC(); 
    }
    while (notFacingEast()){
        
        turnRight();
    }
    
}
function fillRiver(){
    
    for (var i = 0; i < 26; i++){
        
        move();
    }
    
    for (var i = 0; i < 15; i++){
        
        paintColorMR();
        move();
        paintColorMR();
    }
    while(notFacingSouth()){
        
        turnRight();
    }
    move();
    while(notFacingWest()){
        
        turnRight();
    }
    for (var i = 0; i < 15; i++){
        
        paintColorMR();
        move();
        paintColorMR();
    }
    while(notFacingSouth()){
        
        turnRight();
    }
    move();
    while(notFacingEast()){
        
        turnRight();
    }
    for (var i = 0; i < 13; i++){
        
        paintColorMR();
        move();
        paintColorMR();
    }
    while(notFacingSouth()){
        
        turnRight();
    }
    move();
    while(notFacingWest()){
        
        turnRight();
    }
    move();
    move();
    move();
    for (var i = 0; i < 13; i++){
        
        paintColorMR();
        move();
        paintColorMR();
    }
     while(notFacingSouth()){
        
        turnRight();
    }
    move();
    while(notFacingEast()){
        
        turnRight();
    }
    move();
    move();
    move();
    for (var i = 0; i < 11; i++){
        
        paintColorMR();
        move();
        paintColorMR();
    }
     while(notFacingSouth()){
        
        turnRight();
    }
    move();
    while(notFacingWest()){
        
        turnRight();
    }
    move();
    move();
    move();
    move();
    move();
    move();
    for (var i = 0; i < 10; i++){
        
        paintColorMR();
        move();
        paintColorMR();
    }
    while(notFacingSouth()){
        
        turnRight();
    }
    move();
    while(notFacingEast()){
        
        turnRight();
    }
    move();
    move();
    move();
    for (var i = 0; i < 8; i++){
        
        paintColorMR();
        move();
        paintColorMR();
    }
     while(notFacingSouth()){
        
        turnRight();
    }
    move();
    while(notFacingWest()){
        
        turnRight();
    }
    move();
    move();
    move();
    move();
    move();
    move();
    for (var i = 0; i < 15; i++){
        
        paintColorMR();
        move();
        paintColorMR();
    }
     while(notFacingSouth()){
        
        turnRight();
    }
    move();
    while(notFacingEast()){
        
        turnRight();
    }
    move();
    move();
    move();
    for (var i = 0; i < 4; i++){
        
        paintColorMR();
        move();
        paintColorMR();
    }
     while(notFacingSouth()){
        
        turnRight();
    }
    move();
    while(notFacingWest()){
        
        turnRight();
    }
    move();
    move();
    move();
    for (var i = 0; i < 4; i++){
        
        paintColorMR();
        move();
        paintColorMR();
    }
     while(notFacingSouth()){
        
        turnRight();
    }
    move();
    while(notFacingEast()){
        
        turnRight();
    }
    move();
    for (var i = 0; i < 4; i++){
        
        paintColorMR();
        move();
        paintColorMR();
    } while(notFacingSouth()){
        
        turnRight();
    }
    move();
    while(notFacingWest()){
        
        turnRight();
    }
    move();
    move();
    move();
    for (var i = 0; i < 11; i++){
        
        paintColorMR();
        move();
        paintColorMR();
    }
     while(notFacingSouth()){
        
        turnRight();
    }
    move();
    while(notFacingEast()){
        
        turnRight();
    }
    move();
    move();
    for (var i = 0; i < 13; i++){
        
        paintColorMR();
        move();
        paintColorMR();
    } while(notFacingSouth()){
        
        turnRight();
    }
    move();
    while(notFacingWest()){
        
        turnRight();
    }
    move();
    move();
    move();
    for (var i = 0; i < 3; i++){
        
        paintColorMR();
        move();
        paintColorMR();
    }
     while(notFacingSouth()){
        
        turnRight();
    }
    move();
    while(notFacingEast()){
        
        turnRight();
    }
    move();
    for (var i = 0; i < 15; i++){
        
        paintColorMR();
        move();
        paintColorMR();
    }
    
    
    
    
    
    
    
    
    
    
    
    
    
}
function paintColorMR(){
    
    if (colorIs(Color.red)){
        paint(Color.blue);
    }else{
        paint(Color.createFromRGB(183,227,255,255));
    }
}
function fillTreestwo(){
    
    
    fillTrees(); 
    
    while(notFacingSouth()){
        
        turnRight();
    }
    while(frontIsClear()){
        
        move();
    }
    while(notFacingEast()){
        
        turnRight();
    }
    for(var i = 0; i < 9; i++ ){
        
        move(); 
    }
    while(notFacingNorth()){
        
        turnRight();
    }
    for(var i = 0; i < 4; i++ ){
        
        move(); 
    }
    
    fillTrees(); 


}
function fillTrees(){
    
    while(notFacingWest()){
        
        turnRight();
    }
    while(frontIsClear()){
        
        move();
    }
    turnAround();
    for(var i = 0; i < 5; i++ ){
        
        move(); 
    }
    for(var i = 0; i < 4; i++ ){
        
        loopThruTree();
    }
  
    for(var i = 0; i < 4; i++ ){
        
        loopThruTreetwo();
        loopThruTreethree();
    }
    move(); 
    paintColorTree();
    move(); 
    paintColorTree();
    move(); 
    paintColorTree();
    while(notFacingNorth()){
        
        turnRight();
    }
    move();
    while(notFacingWest()){
        
        turnLeft();
    }
    move(); 
    paintColorTree();
    move(); 
    paintColorTree();
    while(notFacingNorth()){
        
        turnRight();
    }
    move();
    while(notFacingEast()){
        
        turnLeft();
    }
    move(); 
    paintColorTree();
}
function paintColorTree(){
    
    if (colorIs(Color.red)){
        paint(Color.blue);
    }else{
        paint(Color.createFromRGB(47,49,51,255));
    } 
}
function loopThruTree(){
    // moves through each pixel in line and colors it 
    for(var i = 0; i < 4; i++ ){
        
        paintColorTree(); 
        move(); 
        paintColorTree(); 
    }
    resetTree(); 
}
function resetTree(){
    
    while (notFacingWest()){
        
        turnRight();
    }
    
    for(var i = 0; i < 4; i++ ){
            
           move(); 
        
    }
    while (notFacingNorth()){
        
        turnLeft();
    }
    if (frontIsClear()){
        
        move();
        paintColorTree(); 
    }
    while (notFacingEast()){
        
        turnRight();
    }
    
}
function loopThruTreetwo(){
    // moves through each pixel in line and colors it 
    for(var i = 0; i < 5; i++ ){
        
        paintColorTree(); 
        move(); 
        paintColorTree(); 
    }
    resetTreetwo(); 
}
function resetTreetwo(){
    
    while (notFacingWest()){
        
        turnRight();
    }
    
    for(var i = 0; i < 6; i++ ){
            
           move(); 
        
    }
    while (notFacingNorth()){
        
        turnLeft();
    }
    if (frontIsClear()){
        
        move();
        paintColorTree(); 
    }
    while (notFacingEast()){
        
        turnRight();
    }
    
}
function loopThruTreethree(){
    // moves through each pixel in line and colors it 
    for(var i = 0; i < 5; i++ ){
        
        paintColorTree(); 
        move(); 
        paintColorTree(); 
    }
    resetTree(); 
}
function resetTreethree(){
    
    while (notFacingWest()){
        
        turnRight();
    }
    
    for(var i = 0; i < 4; i++ ){
            
           move(); 
        
    }
    while (notFacingNorth()){
        
        turnLeft();
    }
    if (frontIsClear()){
        
        move();
        paintColorTree(); 
    }
    while (notFacingEast()){
        
        turnRight();
    }
    
}
function goToTopRight() {
    while (frontIsClear()) {
        move();
    }
    turnLeft();
    
    while (frontIsClear()) {
        move();
    }
    
    turnLeft();
}
function fillSky() {
    goToTopRight();
    for (var i = 0; i < 5; i++) {
        for (var j = 0; j < 48; j++) {
            paint(Color.createFromRGB(250,228,209,255));
            if (j < 47) {
                move();
            }
        }
        
        if (i < 4) {
            turnLeft();
            move();
            turnLeft();
            
            for (var k = 0; k < 47; k++) { 
                move();
            }
            
            turnLeft();
            turnLeft();
        }
    }
    turnAround();
    for (var i = 0; i < 11; i++){
        move();
    }
    turnRight();
    for (var i = 0; i < 3; i++){
        move();
    }
    turnLeft();
}
function fillSky2() {
    for (var i = 0; i < 3; i++) {
        for (var j = 0; j < 37; j++) {
            paint(Color.createFromRGB(219,204,213));
            if (j < 36) {
                move();
            }
        }
        
        if (i < 3) {
            turnLeft();
            move();
            turnLeft();
            
            for (var k = 0; k < 36; k++) {
                move();
            }
            
            turnLeft();
            turnLeft();
        }
    }
}
Leave a Comment