Next: Interacción y Sensores Up: Ejercicio-1 Previous: Ejercicio-1


Solución-1


 		 
 

/***************************************************************************
/***
/***
/***
/***  Programa para prender y apagar luces de dos colores cada 2 segundos
/***
/***  Processing V.0119B   juanig_at_Maginvent.ORG 30/10/06
/***  
/***
/***
/***
*****************************************************************************/
//
// variables globales
//

int t=0, reit=0;

void setup() {
    size(512,256);
    frameRate(24);
}

void draw()
{
    int size=30;
    t=second();
    background(255);
    
    row(size);
    if(t%2==0){sequence(size,reit);}
    if(reit>5){reit=1;} else{reit++;}
}

//
// Dibujo una fila sin colores
//
void row (int s) {
    for(int j=1; j<6; j++) {
	rombo((100+(j*2*s)),100,s,255);
    }
}
//
// Sucesión de luces prendidas y apagadas
//                   notar los condicionales
//

void sequence (int s, int iter) {
    int c=255;
    switch(iter) {
    case 1:
	for(int j=1; j<6; j++) {
	    if(j==1){c=71;} else{c=255;}
	    rombo((100+(j*2*s)),100,s,c);
	}
	break;
    case 2:
	for(int j=1; j<6; j++) {
	    if(j==2){c=71;} else{c=255;}
		rombo((100+(j*2*s)),100,s,c);
	}
	break;
    case 3:
	for(int j=1; j<6; j++) {
	    if(j==3){c=71;} else{c=255;}
		rombo((100+(j*2*s)),100,s,c);
	}
	break;
    case 4:
	for(int j=1; j<6; j++) {
	    if(j==4){c=71;} else{c=255;}
	    rombo((100+(j*2*s)),100,s,c);
	}
	break;
    case 5:
	for(int j=1; j<6; j++) {
	    if(j==5){c=71;} else{c=255;}
	    rombo((100+(j*2*s)),100,s,c);
	}
	break;
    default:
	for(int j=1; j<6; j++) {
	    rombo((100+(j*2*s)),100,s,c);
	}
    }
}

//
// función para dibujar un rombo basada en la mas flexible diamond
//
void rombo (int x, int y, int s, int c)
{ 
    fill(c);
    diamond(x,y,s,s);}

void diamond (int x, int y, int a, int b) 
{
    quad((x-a),y,x,(y-b),(x+a),y,x,(y+b));
}

next up previous
Next: Interacción y Sensores Up: Ejercicio-1 Previous: Ejercicio-1

© Copyright 2001-2008 CCRMA, Stanford University. All rights reserved.
Created and Mantained by Juan Reyes