Rockbox.org home
release
dev builds
extras
themes manual
wiki
device status forums
mailing lists
IRC bugs
patches
dev guide



Rockbox mail archive

Subject: snow screensaver
From: Itai (Itais_at_newmail.net)
Date: 2002-08-28


a screen saver (for the recorder, duh) that simulates snow/dust/small
particles going down the screen


/*
snow screen saver

by Itai Shaked
*/

#include "lcd.h"
#include "config.h"
#include "kernel.h"
#include "menu.h"
#include "button.h"
#include <stdlib.h>

short particles[2000][2];

bool particle_exists (int particle) {
    if (particles[particle][0]>=0 && particles[particle][1]>=0 && particles[particle][0]<=111 && particles[particle][1]<=63) return true;
    else return false;
}

int create_particle (void) {
    int i;
    for (i=0; i<1500; i++) {
        if (!particle_exists(i)) {
            particles[i][0]=(rand()%112);
            particles[i][1]=0;
            return i;
        }
    }
    return -1;
}

void snow_move(void) {
    int i;
    if (!(rand()%2)) create_particle();
    for (i=0; i<2000; i++) {
        if (particle_exists(i)) {
            lcd_clearpixel(particles[i][0],particles[i][1]);
            switch ((rand()%5)) {
                case 0:
                    particles[i][0]++;
                    break;
                case 1:
                    particles[i][0]--;
                    break;
                case 2:
                    break;
                default:
                    particles[i][1]++;
                    break;
            }
        if (particle_exists) lcd_drawpixel(particles[i][0],particles[i][1]);
        }
    }
}

void snow_init(void) {
    int i;
    for (i=0; i<2000; i++) {
        particles[i][0]=-1;
        particles[i][1]=-1;
    }
    lcd_clear_display();
}

Menu snow (void) {
    snow_init();
    while (1) {
        snow_move();
        lcd_update();
        sleep(HZ/10);
        if (button_get(false)==BUTTON_OFF) return MENU_OK;
    }
}



Page was last modified "Jan 10 2012" The Rockbox Crew
aaa