logoTh!nk Again


¿Cómo empezar a programar aplicaciones para el iPhone?

Posted in Tutoriales, iPhone by admin on the May 17th, 2009

Después de aplicarle el JailBreak al iPhone y darme cuenta que se pueden instalar aplicaciones de terceros (no solo de la tienda de iTunes), me di a la tarea de buscar un SDK para el iPhone. Me econtré con el blog de Tim Layton y sus video tutoriales. Entonces pensé en que sería buen idea subtitular el video y después contactarlo para que subiera el archivo .srt a youtube.

Para crear los subtítulos utilicé subtitle Editor, en ubuntu se instala con esta línea:

dennys@dell-desktop:~$ sudo apt-get install subtitleeditor


Con esta herramienta podemos cargar el video, pausar, establecer los tiempos de inicio y fin del subtítulo, entre otras cosas. Al final solo tuve que exportarlo como un archivo SubRib (.srt), el cual es soportable por youtube.


Este es el video subtitulado, es la primera versión de los subtítulos, si alguien está interesado en mejorarlo aquí está el archivo fuente.

Guía para subir subtítulos en youtube

Nota, si tienen problemas para activar los subtítulos revisen esto.

Librería msound para Mobile Processing en acción

Posted in Ejemplos, Mobile Processing by admin on the May 16th, 2009

Existen un grupo de librerías para Mobile Processing que no pertenecen al nucleo, hechas por terceros para extender sus funcionalidades. Existe en un apartado de Referencias en la página oficial de Mobile Processing en donde se detallan estas librearías.

En esta ocasión se mostrarán los midlets corriendo en un n95, para ejemplificar el uso de la librería msound.

Cada tecla está asociada a una frecuencia diferente.

Presentación Introducción a Mobilie Processing

Posted in Mobile Processing, Tutoriales by admin on the May 16th, 2009

Importar contactos a partir de un .txt

Posted in Ejemplos, Mobile Processing, Processing, Tutoriales by admin on the May 4th, 2009

Aquí esta el complemento, muy útil cuando cambiamos de teléfono. En el archivo de entrada, cada línea es un contacto, el primer campo es el nombre del contacto y el segundo el número telefónico correspondiente. Los campos se separan por tabuladores, este es un ejemplo del archivo de entrada “contactos.txt”:

yzpiqt{vxu  9121540154
pzo{phrrdw  3645688357
dwhvotiuul  9827914405
vfltjdlakf  0544231692
dkiimtwktg  2587469846
cdxibeuhgb  8662069239
jtjivwksvb  2151870224
dpbnjfpgzt  2950363356
esaooqfoun  9590050987
swmilkrg{0705686048
pdjzcgioeb  7049194677
{gvqwsmtmw  3441362136
ztqcnwibxg  1054659213
yblbwcebog  7803351735
n{qogrgwbd  8184444490

El código del midlet, es el siguiente:

//importa una lista de contactos desde un archivo
/*Importa contactos
   por Dennys Regalado Díaz
   Utilidad, 4 de Abril del 2009
*/

import mjs.processing.mobile.mfiles.*;
import mjs.processing.mobile.mpim.*;

String fileName = "file:///root1/contactos.txt";
// Create the PIM object
MPIM mPIM;
MContact mContact;
MContactList mContactList;

String lines[];
PFont fuente;
int i;
// Open the contact list in read mode and get all the contacts
MContact[] contacts;

void setup(){
  fuente = loadFont();
  textFont(fuente);
  textAlign(LEFT)
  // For each contact show name an phone number
  fill(0);
  i=0;

  try{
    lines = MFiles.loadStrings(fileName);
  }
  catch(Exception e){
    text("Error al intentar leer \"contactos.txt\"",width/2,height/2);
  }
  mPIM = new MPIM();
  mContactList = mPIM.contactList(MPIM.WRITE)

}
void draw(){
  background(255);
  if(i< length(lines)){
    mContact= mContactList.createContact();       

    String items[] = split(lines[i],"\t");
    mContact.name(items[0]);
    mContact.tel(items[1]);     

    mContact.save();


    int value = (i*(width-20))/length(lines);
    int percent = (i*100)/length(lines);

    text(items[0]+"...",20,15);   
    text(percent+"%",width/2,height/2-40);
    rect(10,height/2-30,value,10);


    i++; 
  }
  else{
    textAlign(CENTER)

    text("Hecho.",width/2,height/2)
    text("Se importaron " +length(lines) + " contacto(s)",width/2,height/2 + 15);
    text("de \"contactos.txt\"",width/2,height/2 + 35);
    noLoop();
  }
}

Exportar los contactos de mi teléfono a un archivo .txt

Posted in Ejemplos, Mobile Processing by admin on the May 4th, 2009

Aquí les dejo un pequeño sketch escrito en mobile processing para exportar la lista de contactos a un archivo de texto. La idea es que luego puedan enviar este archivo a su PC para respaldarlo.

Nota: cambien las variable fileName con la ruta de su teléfono!!!
Este es el código usando las librerias mfiles y mpim de Marlon:

/*Exportar Contactos
  por Dennys Regalado Díaz
  Utilidades, 4 de Abril del 2009
*/

import mjs.processing.mobile.mfiles.*;
import mjs.processing.mobile.mpim.*;

String fileName = "file:///root1/contactos.txt";
// Create the PIM object
MPIM mPIM = new MPIM();
String lines[];
PFont fuente;
int i;
// Open the contact list in read mode and get all the contacts
MContact[] contacts;

void setup(){
  fuente = loadFont();
  textFont(fuente);
  textAlign(LEFT)
  // For each contact show name an phone number
  fill(0);
  i=0;
  contacts = mPIM.contactList(MPIM.READ).contacts()
  lines = new String[length(contacts)];     
}
void draw(){
    background(255);
  if(i< length(contacts)){

    lines[i] = contacts[i].name() + "\t"+contacts[i].tel();

    int value = (i*(width-20))/length(contacts);
    int percent = (i*100)/length(contacts);
   
    text(contacts[i].name()+"...",20,15);   
    text(percent+"%",width/2,height/2-40);
    rect(10,height/2-30,value,10);
   
    //    text(contacts[i].name(),10,15*i);       
    i++;
  }
  else{
    textAlign(CENTER)
    try{
      MFiles.saveStrings(fileName,lines);   
      text("Hecho.",width/2,height/2)
      text("Se exportaron " +length(contacts) + " contacto(s)",width/2,height/2 + 15);
      text("a \"contactos.txt\"",width/2,height/2 + 35);
    }
    catch(Exception e){
      text("Ocurrio un error en la escritura",width/2,height/2);
    }
    noLoop();
  }
}

Cómo leer píxeles de una imagen y mostrarlos con un LED RGB

Posted in Arduino, Ejemplos, Processing by admin on the May 2nd, 2009

La idea de escribir este sketch surgió por un comentario de Pedro que recibí hace una semana. Después de ver unos ejemplos (Examples->Topics->Image Processing->PixelArray) me dí cuenta que el programa era muy sencillo de escribir.

El objetivo cargar una imagen en Processing y de acuerdo a la posición del cursor del mouse, leer ese pixel y enviarlo al Arduino para que éste lo muestre usando un LED RGB.

El código para el Arduino es el mismo que usé en el post Controlando led RGB al ritmo de la música, solo se encarga de descomponer el color (enviado en hexadecimal) y luego escribir los valores Red, Green, Blue a las salidas PWM 9, 10, 11.

Este es un extracto del código en el que se asignan los pines de salida al LED RGB:

#define R_LED 11
#define G_LED 9
#define B_LED 10

El código en Processing es el siguiente:

/**
 * PixelArray
 * por Dennys Regalado Díaz
 *
 * Posiciona el cursor del raton sobre la imagen, obtiene el color del pixel,
 * lo envía al Arduino y lo muestra con un LED RGB
 * 2 de Mayo del 2009
 */

import processing.serial.*;

PImage a;
int[] aPixels;
float signal;
String cs;
int last_color = -1;
Serial port;
void setup()
{
  a = loadImage("test.jpg");
  size(a.width, a.height);
 
  aPixels = new int[a.width*a.height];

  noFill();
  stroke(255);
  frameRate(10);
 
    //configura puerto serial
  println(Serial.list());
  port = new Serial(this, Serial.list()[0], 9600);

}

void draw()
{ 
  image(a,0,0);
 
  if(mouseY > height-1)
    mouseY = height-1;
   
  if(mouseY < 0)
    mouseY = 0;
 
  signal = mouseY*a.width + mouseX;

  rect(signal%a.width-5, int(signal/a.width)-5, 10, 10);
  point(signal%a.width, int(signal/a.width));

  color c = a.pixels[int(signal)];
// println(red(c)+","+green(c)+","+blue(c));
  //Envia datos al arduino
   if(c!=last_color){
    cs = "#" + hex(c,6); // Prepare a string to be sent to Arduino
    port.write(cs);
    last_color=c;
  }
 
  fill(c);
  rect(width-20,height-20,20,20);
  noFill();
}

Cómo utilizar tu GPS para obtener un mapa de tu posición actual

Posted in Ejemplos, Mobile Processing by admin on the May 1st, 2009
Juchitán de Zaragoza, Oaxacamapa_yahoo_

Juchitán de Zaragoza, Oaxaca

En este post se describe un sketch escrito en Mobile Processing para la navegación por GPS (ver nokia Maps). Empeceos con el GPS, gracias a la librería mlocation podemos accesar a las coordenas (latitud, longitud) de nuestra posición actual.

Después, hacemos uso del servicio de Yahoo! Maps, en el que podemos hacer consultas pasando como parámetros las coordenadas del GPS y obtenemos una imagen con el mapa correspondiente. Este servicio es gratuito, solo hay que registrarse para obtener un ID que se debe anexar a cada consulta.

La desventaja es que necesitamos un punto de acceso para conectarnos a Internet gratis, así que esto solo podrá ser útil en algunos lugares públicos, tiendas departamentales, hospitales, etc., que cuentan con este servicio.

Motivación

Código

import mjs.processing.mobile.mlocation.*;
PClient clientXML;
PClient clientMap;
PRequest requestXML;
PRequest requestMap;
PFont font;
PImage mapImage;
String xml;
String mapURL;
double[] coords = new double[2];

double latitude, longitude;

void setup(){
clientXML = new PClient(this,"local.yahooapis.com");
clientMap = new PClient(this,"gws.maps.yahoo.com");
font = loadFont();
textFont(font);
noLoop();

MLocation.location(coords);
latitude = coords[0];
longitude = coords[1];

}
void draw() {
background(0);
fill(255);
if( mapImage != null ) {
image(mapImage, width/2-mapImage.width/2, height/2- mapImage.height/2);
text("Imagen cargada",width/2,height/2);
}
else {
text("("+latitude+","+longitude+")",4,14);
text("Descargando mapa...",4,20,width-8,height-8);
requestXML = clientXML.GET("/MapsService/V1/mapImage?appid=ID--&amp;latitude=" + latitude + "&amp;longitude=" + longitude + "&amp;zoom=2&amp;image_height=" + height+ "&amp;image_width=" + width);
}
}
void libraryEvent(Object library, int event, Object data) {
if (library == requestXML) {
if (event == PRequest.EVENT_CONNECTED) {
requestXML.readBytes();
}
else if (event == PRequest.EVENT_DONE) {
xml = new String((byte[]) data);
int start = xml.indexOf("instance\"\&gt;;") + 10;      int end = xml.indexOf(
int end = xml.indexOf("\
mapURL = xml.substring(start, end);
requestXML.close();
requestMap = clientMap.GET(mapURL.substring(25));
}
}
if (library == requestMap) {
if (event == PRequest.EVENT_CONNECTED) {
requestMap.readBytes();
}
else if (event == PRequest.EVENT_DONE) {
mapImage = loadImage((byte[]) data);
requestMap.close();
redraw();
}
}
}

@ Post original Nokia Workshop