コード例 #1
0
ファイル: animation.cpp プロジェクト: AndreasBur/MaxMatrix
//RANDOM LIGHTS
uint8_t animation::randomExpand(cube &c){
    uint16_t count = 0;
	uint8_t rX, rY, rZ;
    
    slow++;
    if(slow < 20){
        return 0;
    }
    slow = 0;
    
    randomSeed(analogRead(0));
    rX = rand()%8+0;
    rY = rand()%8+0;
    rZ = rand()%8+0;
	
    //find an empty voxel
    while(c.getVoxel(rX, rY, rZ) == 1 && dir == 1){
        rX = random(0, 8);
        rY = random(0, 8);
        rZ = random(0, 8);
        count++;
        
        if(count > 200){
            dir *= -1;
        }
    }
    count = 0;

    //find a full voxel
    while(c.getVoxel(rX, rY, rZ) == 0 && dir == -1){
        rX = random(0, 8);
        rY = random(0, 8);
        rZ = random(0, 8);
        count++;

        if(count > 200){
            dir *= -1;
        }
    }

    //fill or clear the voxel found
    if(dir == 1){
        c.setVoxel(rX, rY, rZ);
    }else{
        c.clearVoxel(rX, rY, rZ);
    }
    
    return 1;
}
コード例 #2
0
ファイル: animation.cpp プロジェクト: AndreasBur/MaxMatrix
//CUBE PULSE
uint8_t animation::cubePulse(cube &c){
    uint8_t cubeSize = pos+1;
    uint8_t test = 0;
    uint8_t xCen = 0;
    uint8_t yCen = 0;
    uint8_t zCen = 0;
    
    slow++;
    if(slow < 150){
        return 0;
    }
    slow = 0;
    
    //build the cube with consitional statements, 
    //I feel like I could do this more elegantly but it works
    for(uint8_t x = 0; x < Xd; x++){
        for(uint8_t y = 0; y <Yd; y++){
            for(uint8_t z = 0; z < Zd; z++){
                test = 0;
                xCen = absA(2*(x-centre));
                yCen = absA(2*(y-centre));
                zCen = absA(2*(z-centre));
                
                if(xCen == cubeSize && yCen == cubeSize && zCen == cubeSize){
                    c.setVoxel(x, y, z);
                    test = 1;
                }
                if(xCen == cubeSize && yCen == cubeSize && zCen < cubeSize){
                    c.setVoxel(x, y, z);
                    test = 1;
                }
                if(xCen == cubeSize && zCen == cubeSize && yCen < cubeSize){
                    c.setVoxel(x, y, z);
                    test = 1;
                }
                if(zCen == cubeSize && yCen == cubeSize && xCen < cubeSize){
                    c.setVoxel(x, y, z);
                    test = 1;
                }
                
                if(!test && c.getVoxel(x, y, z)){
                    c.clearVoxel(x, y, z);
                }
            }
        }
    }
    
    pos += dir*2;
    
    if(pos > 6 || pos < 0){
        dir *= -1;
        pos += dir*2;
    }
    
    return 1;
}
コード例 #3
0
ファイル: animation.cpp プロジェクト: AndreasBur/MaxMatrix
//RAIN FUNCTION
uint8_t animation::rain(cube &c){
    uint16_t count = 0;
    uint8_t rX = 0;
    uint8_t rY = 0;
    uint8_t rZ = 0;
    
    slow++;
    if(slow < 200){
        return 0;
    }
    slow = 0;
    
    randomSeed(analogRead(0));
    
    //shift the rain down
    for(int x = 0; x < Xd; x++){
        for(int y = 0; y < Yd; y++){
            for(int z = 0; z < Zd-1; z++){
                if(z == 0 && c.getVoxel(x, y, z)){
                    c.clearVoxel(x, y, z);
                }
                
                if(c.getVoxel(x, y, z+1)){
                    c.clearVoxel(x, y, z+1);
                    c.setVoxel(x, y, z);
                }
            }
        }
    }
    
    //create some raindrops
    rX = random(0,8);
    rY = random(0,8);
    while(c.getVoxel(rX, rY, 7) != 0 && count < 100){
        rX = random(0,8);
        rY = random(0,8);
        count++;
    }
    c.setVoxel(rX, rY, 7);

    return 1;
}