import processing.serial.*;
Serial port;
int linefeed = 13; // Linefeed in ASCII
float x=230;
float y=320;
float j=1024;
float l=768;
int xbola1=10;
int ybola1=400;
int resX = 1024;
int resY = 500;
int incrementoBola = 10;
PImage Dia;
PImage Noche;
int donde_estoy = 0;
int donde_antes = 0;
int comoEsta = 0; //0=dia 1=Noche
void setup(){
size(resX, resY);
Dia = loadImage ("ABC.jpg");
Noche = loadImage ("NOCHE.jpg");
println(Serial.list());
int unPuerto = 1;
print("Puerto=");
println(Serial.list()[unPuerto]);
port = new Serial(this, Serial.list()[unPuerto], 9600);
port.bufferUntil(linefeed);
}
void draw(){
if(mousePressed == true){
//background(102);
//x=mouseX;
//y=mouseY;
xbola1 = xbola1 + incrementoBola;
if (xbola1 >= resX){
//xbola1 = 10;
ybola1 = ybola1 + 50;
incrementoBola = - 10;
}
if (xbola1 < 0){
ybola1 = 400;
incrementoBola = 10;
}
}
else{
background(0);
image(Dia, 0, 0, j, l);
comoEsta = 0;
}
if(xbola1 <0){
image(Dia, 0, 0, j, l);
comoEsta = 0;
}
if (xbola1 > 1000){
image (Noche, 0, 0, j, l);
comoEsta = 1;
}
fondoPaisaje();
dibujaCarro();
dibujaCarro1();
if (encimarect() == true){
if ((donde_estoy != donde_antes) && (donde_estoy == 1)) {
println("Estoy en la ventana" + donde_estoy);
port.write('1');
donde_antes = donde_estoy;
}
else if ((donde_estoy != donde_antes) && (donde_estoy == 2)) {
println("Estoy en cuadro" + donde_estoy);
port.write('2');
donde_antes = donde_estoy;
}
else if ((donde_estoy != donde_antes) && (donde_estoy == 3)) {
println("Estoy en cuadro" + donde_estoy);
port.write('3');
donde_antes = donde_estoy;
}
else if ((donde_estoy != donde_antes) && (donde_estoy == 4)) {
println("Estoy en cuadro" + donde_estoy);
//port.write('4');
donde_antes = donde_estoy;
}
else if ((donde_estoy != donde_antes) && (donde_estoy == 5)) {
println("Estoy en cuadro" + donde_estoy);
//port.write('5');
donde_antes = donde_estoy;
}
else if ((donde_estoy != donde_antes) && (donde_estoy == 6)) {
println("Estoy en cuadro" + donde_estoy);
//port.write('6');
donde_antes = donde_estoy;
}
else if ((donde_estoy != donde_antes) && (donde_estoy == 7)) {
println("Estoy en cuadro" + donde_estoy);
//port.write('7');
donde_antes = donde_estoy;
}
else if ((donde_estoy != donde_antes) && (donde_estoy == 8)) {
println("Estoy en cuadro" + donde_estoy);
//port.write('8');
donde_antes = donde_estoy;
}
else if ((donde_estoy != donde_antes) && (donde_estoy == 9)) {
println("Estoy en cuadro" + donde_estoy);
//port.write('9');
donde_antes = donde_estoy;
}
}
else{
donde_antes = donde_estoy;
}
}
void fondoPaisaje(){
//Rectangulo Principal
fill(53,150,150);
rect(x, y, 55, 55);
//Rectangulo Continuo
fill(53,150,150);
rect(x + 55, y, 70, 55);
//Techo 1
fill(150, 80, 0);
triangle(x, y, x + 55/2, y - 55, x + 55, y);
//Techo 2
fill(150, 80, 0);
quad(x + 55, y, x + 90 + 35, y, x + 100, y - 55, x + 25, y - 55);
//Ventana 1
fill(200, 230, 260);
rect(x + 55 + 80/2 - 50/2, y + 55/2 - 30/2, 20, 30);
//Ventana 2
fill(200, 230, 260);
rect(x + 90, y + 55/2 - 30/2, 20, 30);
//Puerta
fill(200,200,200);
rect(x + 10, y + 25, 20, 30);
//Ventana Circulo
fill(200, 150, 0);
ellipse(x + 20+6, y+20-45 +20/2, 20, 20);
dibujaEdificio();
//Edificio
/*
//edicio
*/
//Carretera
fill(200, 200, 200);
rect(x - 90*2 - 50, y + 50, 1025, 120 + 20);
//anden
fill(0, 96, 0);
rect(x - 90*2 - 50, y + 50, 1025, 20);
//Lineas Carretera 1
fill(255, 255, 0);
rect(900, y + 120, 20*5, 10);
//Lineas Carretera 2
fill(255, 255, 0);
rect(750, y + 120, 20*5, 10);
//Lineas Carretera 3
fill(255, 255, 0);
rect(600, y + 120, 20*5, 10);
//Lineas Carretera 4
fill(255, 255, 0);
rect(450, y + 120, 20*5, 10);
//Lineas Carretera 5
fill(255, 255, 0);
rect(300, y + 120, 20*5, 10);
//Lineas Carretera 6
fill(255, 255, 0);
rect(150, y + 120, 20*5, 10);
//Lineas Carretera 7
fill(255, 255, 0);
rect(0, y + 120, 20*5, 10);
}
void dibujaCarro(){
//Carro Parte 1
fill(255, 0, 255);
ellipse(xbola1 + 50, ybola1 - 2, 70, 55);
//Ventana
fill(255, 255, 255);
ellipse(xbola1 + 50, ybola1 - 2, 50, 40);
//Separador Ventana
fill(255, 0, 255);
rect(xbola1 + 50, ybola1 - 22, 5, 40);
//Carro Parte 2
fill(255, 0, 255);
rect(xbola1 + 10, ybola1 + 13, 80, 15);
//Llanta 1
fill(0,0,0);
ellipse(xbola1 + 30, ybola1+28, 20, 20);
//Llanta 2
fill(0,0,0);
ellipse(xbola1 + 70, ybola1+28, 20, 20);
}
void dibujaCarro1(){
//Carro Parte 1
fill(10, 250, 0);
rect(xbola1 + 270 , ybola1 - 20, 70, 45);
//Ventana1
fill(255, 255, 255);
rect(xbola1 + 270 + 30, ybola1 - 10, 30, 25);
//Ventana2
fill(255, 255, 255);
rect(xbola1 + 90 + 90 + 90 + 10, ybola1 - 10, 20, 25);
//Carro Parte 2
fill(10, 250, 0);
rect(xbola1 + 90 + 90 + 70, ybola1 +10, 90 + 30, 20);
//Llanta 1
fill(155, 80, 80);
ellipse(xbola1 + 90 + 90 + 90, ybola1+28, 20, 20);
//Llanta 2
fill(155, 80, 80);
ellipse(xbola1 + 90 + 90 + 90 + 70, ybola1+28, 20, 20);
}
void dibujaEdificio(){
fill(255, 255, 255);
rect(x + 125, y - 110, 90, 90 + 90 + 20);
//Ventana 2
if (donde_estoy == 1){
if (comoEsta == 0){
fill(0, 139, 188);
}
else{
fill(255, 255, 0);
}
}
else{
fill(#666660);
}
rect(x + 130, y - 100, 20, 20);
//Ventana 3
if (donde_estoy == 2){
if (comoEsta == 0){
fill(0, 139, 188);
}
else{
fill(255, 255, 0);
}
}
else{
fill(#666660);
}
rect(x + 160, y - 100, 20, 20);
//medio ventana 2.1
if (donde_estoy == 3){
if (comoEsta == 0){
fill(0, 139, 188);
}
else{
fill(255, 255, 0);
}
}
else{
fill(#666660);
}
rect(x + 190, y - 100, 20, 20);
//ventana 2,2
if (donde_estoy == 4){
if (comoEsta == 0){
fill(0, 139, 188);
}
else{
fill(255, 255, 0);
}
}
else{
fill(#666660);
}
rect(x + 130, y - 60, 20, 20);
//ventana 2,3
if (donde_estoy == 5){
if (comoEsta == 0){
fill(0, 139, 188);
}
else{
fill(255, 255, 0);
}
}
else{
fill(#666660);
}
rect(x + 160, y - 60, 20, 20);
// 3 ventana 3,1
if (donde_estoy == 6){
if (comoEsta == 0){
fill(0, 139, 188);
}
else{
fill(255, 255, 0);
}
}
else{
fill(#666660);
}
rect(x + 190, y - 60, 20, 20);
// 3 ventana 3,2
if (donde_estoy == 7){
if (comoEsta == 0){
fill(0, 139, 188);
}
else{
fill(255, 255, 0);
}
}
else{
fill(#666660);
}
rect(x + 130, y - 20, 20, 20);
// 3 ventana 3,3
if (donde_estoy == 8){
if (comoEsta == 0){
fill(0, 139, 188);
}
else{
fill(255, 255, 0);
}
}
else {
fill(#666660);
}
rect(x + 160, y - 20, 20, 20);
// 3 ventana 3,3
if (donde_estoy == 9){
if (comoEsta == 0){
fill(0, 139, 188);
}
else{
fill(255, 255, 0);
}
}
else{
fill(#666660);
}
rect(x + 190, y - 20, 20, 20);
//Puerta
fill(200,200,200);
rect(x + 90 + 60, y + 40 - 30/2, 20, 30);
//Puerta 2
fill(200,200,200);
rect(x + 90 + 80, y + 40 - 30/2, 20, 30);
}
boolean encimarect()
{
if ((mouseX >= x + 130)&&(mouseX <= x + 130 +20 )&&(mouseY >= y - 100)&&(mouseY <= y - 100 + 20)){
donde_estoy = 1;
return true;
}
else if((mouseX >= x + 160)&&(mouseX <= x + 160 +20 )&&(mouseY >= y - 100)&&(mouseY <= y - 100 + 20)){
donde_estoy = 2;
return true;
}
else if((mouseX >= x + 190)&&(mouseX <= x + 190 +20 )&&(mouseY >= y - 100)&&(mouseY <= y - 100 + 20)){
donde_estoy = 3;
return true;
}
else if((mouseX >= x + 130)&&(mouseX <= x + 130 +20 )&&(mouseY >= y - 60)&&(mouseY <= y - 60 + 20)){
donde_estoy = 4;
return true;
}
else if((mouseX >= x + 160)&&(mouseX <= x + 160 +20 )&&(mouseY >= y - 60)&&(mouseY <= y - 60 + 20)){
donde_estoy = 5;
return true;
}
else if((mouseX >= x + 190)&&(mouseX <= x + 190 +20 )&&(mouseY >= y - 60)&&(mouseY <= y - 60 + 20)){
donde_estoy = 6;
return true;
}
else if((mouseX >= x + 130)&&(mouseX <= x + 130 +20 )&&(mouseY >= y - 20)&&(mouseY <= y - 20 + 20)){
donde_estoy = 7;
return true;
}
else if((mouseX >= x + 160)&&(mouseX <= x + 160 +20 )&&(mouseY >= y - 20)&&(mouseY <= y - 20 + 20)){
donde_estoy = 8;
return true;
}
else if((mouseX >= x + 190)&&(mouseX <= x + 190 +20 )&&(mouseY >= y - 20)&&(mouseY <= y - 20 + 20)){
donde_estoy = 9;
return true;
}
else{
donde_estoy = 0;
return false;
}
}
void serialEvent(Serial myPort) {
if (myPort.available() > 0){
// read the serial buffer:
String myString = myPort.readStringUntil('\n');
//String myString = myPort.readString();
// if you got any bytes other than the linefeed:
if (myString != null) {
myString = trim(myString);
if ( myString.equals("0")){
println("Llego una 0");
}
}
}
}
No hay comentarios:
Publicar un comentario