martes, 27 de noviembre de 2012

Retroalimentación sobre la clase de Programación Web.

miércoles, 21 de noviembre de 2012

AppInventor y REST.

Interfaz: una imagen(opcional). Un Botón y un Label donde se mostrarán los datos de la API desarrollada en PHP o en ASP.NET.



Bloques:

1.- Variables y programación del evento click del botón.


Click para hacer más grande.

2.- Función de parseo del JSON por elementos:


3.- Bloques de la programación de extracción y formateo de la información según el API desarrollado. Hay que modificar algunos campos para adecuar a su proyecto.


Resultado:


Importante:

* La dirección localhost de tu servidor debe ser reemplazada con la dirección IP 10.0.2.2.

Conclusión.

AppInventor nos puede servir como desarrolladores para crear aplicaciones no muy robustas y de bajo presupuesto.

Fuentes:



lunes, 12 de noviembre de 2012

RESP con PHP y MySQL.

En este ejemplo utilizo una tabla de la base de datos de un proyecto que se llama TamalesOL donde dicha tabla contiene los precios y los tamales que se ofertan.



Tabla Tamales

Código:

<?php
/*
 * Api de tamales_online que arrojará los precios de los tamales
 * tipo Json.
 */
function get_tamales_list(){
    
    //Iniciamos la consulta de la tabla de tamales.

    $conexion = mysql_connect('localhost', 'srtamal', 'cTt9HNfRYPZQdcCZ') or die("No se pudo conectar: ".  mysql_error());
        mysql_query('SET NAME utf8');

        mysql_select_db('tamalesol')or die("No se pudo conectar la BD".mysql_error());
        
        $sql = "SELECT * from tamales";
        $rs = mysql_query($sql,$conexion) or die ("No se realizó la consulta". mysql_error());
        
        $resp = array(); 
        
        while($fila = mysql_fetch_object($rs)){
            
            $resp[] = $fila;
            
        }
         mysql_free_result($rs);
         mysql_close($conexion);
         
         return json_encode($resp);
}

$possible_url = array("get_tamales_list");

$value = "An error has occurred";

if (isset($_GET["action"]) && in_array($_GET["action"], $possible_url))
{
  switch ($_GET["action"])
    {
      case "get_tamales_list":
        $value = get_tamales_list();
        break;
      //case "get_user":
        //if (isset($_GET["id"]))
          //$value = get_user_by_id($_GET["id"]);
        //else
          //$value = "Missing argument";
        //break;
    }
}

exit($value);


?>




Respuesta del Navegador.

@rezzaca

jueves, 8 de noviembre de 2012

Cámara Dinámica.

#include "stdafx.h"
#include <glut.h>
#include <math.h>
#define PI 3.1415926

void Dibuja();
void Inicializa();
void Listas();
void InitCamara();
void Especial(int,int,int);
void Raton(int,int,int,int);
void Mueve(int,int);

float ambiental[4]={.19225,.19225,.19225,1},
 difusa[4]={.50754,.50754,.50754,1},
 especular[4]={.508273,.508273,.508273,1},
 posicion[4]={-45,25,-48,1};
unsigned int pino=1, muñecos=2, montaña=3;
float pcx,pcy,pcz,ocx,ocy,ocz,upx,upy;
float teta,phi,inc,eta;
int ok,xini,yini,okd;

void main()
{
glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);
glutInitWindowSize(800,600);
glutInitWindowPosition(100,100);
glutCreateWindow("Camara");
glutDisplayFunc(Dibuja);
glutSpecialFunc(Especial);
glutMotionFunc(Mueve);
glutMouseFunc(Raton);
Inicializa();
glutMainLoop();
}

void Inicializa()
{
glClearColor(0,0,0,1);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(80,1.333,.1,80); 
glMatrixMode(GL_MODELVIEW); 
glEnable(GL_DEPTH_TEST);
glLightfv(GL_LIGHT1,GL_AMBIENT,ambiental);
glLightfv(GL_LIGHT1,GL_DIFFUSE,difusa);
glLightfv(GL_LIGHT1,GL_POSITION,posicion);
glEnable(GL_LIGHTING);
glEnable(GL_LIGHT1);
glShadeModel(GL_SMOOTH);
ambiental[0]=ambiental[1]=ambiental[2]=0;
glFogfv(GL_FOG_COLOR,ambiental);
glFogf(GL_FOG_MODE,GL_EXP);
glFogf(GL_FOG_DENSITY,0.04);
glEnable(GL_FOG);
Listas();
InitCamara();
}

void Dibuja()
{
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); 
glLoadIdentity();
gluLookAt(pcx,pcy,pcz,ocx,ocy,ocz,upx,upy,0);
glPushMatrix();

//PISO------------------------------
glDisable(GL_LIGHTING);
glColor3f(.7,.7,.7);
glBegin(GL_QUADS);
glVertex3f(-30,-10,10);
glVertex3f(-30,-1,-25);
glVertex3f(30,-1,-25);
glVertex3f(30,-10,10);
glEnd();
glEnable(GL_LIGHTING);

//PINOS----------------------------
glTranslated(-5,-1,0);
glCallList(pino);

glPopMatrix();
glPushMatrix();
glTranslated(7,-.2,-2);
glCallList(pino);

glPopMatrix();
glPushMatrix();
glTranslated(8,-.2,-10);
glCallList(pino);

glPopMatrix();
glPushMatrix();
glTranslated(5,-.2,-6);
glCallList(pino);

//MUÑECOS-------------------
glPopMatrix();
glPushMatrix();
glTranslated(4,-1,0);
glCallList(muñecos);

glPopMatrix();
glPushMatrix();
glTranslated(-4,-1,-5);
glCallList(muñecos);

glPopMatrix();
glPushMatrix();
glTranslated(0,-1,3);
glCallList(muñecos);

glPopMatrix();
glPushMatrix();
glTranslated(8,1.4,-15);
glRotated(45,0,1,0);
glCallList(muñecos);

glPopMatrix();
glPushMatrix();
glTranslated(-10,1.2,-15);
glRotated(45,0,1,0);
glCallList(muñecos);

//MONTAÑAS---------------------
glPopMatrix();
glPushMatrix();
glCallList(montaña);

glPopMatrix();
glPushMatrix();
glTranslated(9,0,0);
glCallList(montaña);

glPopMatrix();
glPushMatrix();
glTranslated(20,0,0);
glCallList(montaña);

glPopMatrix();
glPushMatrix();
glTranslated(30,0,0);
glCallList(montaña);

glPopMatrix();
glPushMatrix();
glTranslated(-13,0,0);
glCallList(montaña);

glPopMatrix();
glPushMatrix();
glTranslated(-20,0,0);
glCallList(montaña);

glPopMatrix();
glPushMatrix();
glTranslated(-30,0,0);
glCallList(montaña);

//LUNA------------------------------------------------
glPopMatrix();
ambiental[0]=0, ambiental[1]=0, ambiental[2]=0;
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,ambiental);
glMaterialfv(GL_FRONT,GL_SPECULAR,especular);
glMaterialf(GL_FRONT,GL_SHININESS,5);
glTranslated(-45,25,-48);//x,z,y
glutSolidSphere(9,99,99);

glutSwapBuffers();
}

void Listas()
{
GLUquadricObj *p;
p=gluNewQuadric();

//MONTAÑAS--------------------------------------------------------
glNewList(montaña,GL_COMPILE);
ambiental[0]=.6, ambiental[1]=.2, ambiental[2]=0;
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,ambiental);
glMaterialfv(GL_FRONT,GL_SPECULAR,especular);
glMaterialf(GL_FRONT,GL_SHININESS,10);
glTranslated(0,8,-35);
glRotated(90,1,0,0);
gluCylinder(p,3,9,10,9,4);
ambiental[0]=1, ambiental[1]=1, ambiental[2]=1;
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,ambiental);
glMaterialfv(GL_FRONT,GL_SPECULAR,especular);
glMaterialf(GL_FRONT,GL_SHININESS,10);
glTranslated(0,0,-5);//xzy
gluCylinder(p,.1,3,5,9,9);
glEndList();

//PINOS-------------------------------------------------
glNewList(pino,GL_COMPILE);
gluQuadricDrawStyle(p,GLU_FILL);
gluQuadricOrientation(p,GLU_OUTSIDE);

//tronco
ambiental[0]=.6, ambiental[1]=.2, ambiental[2]=0;
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,ambiental);
glMaterialfv(GL_FRONT,GL_SPECULAR,especular);
glMaterialf(GL_FRONT,GL_SHININESS,20);
glTranslated(0,0,-5);
glRotated(90,1,0,0);
gluCylinder(p,.2,.2,1,99,99);

//copas
ambiental[0]=0, ambiental[1]=.9, ambiental[2]=0;
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,ambiental);
glMaterialfv(GL_FRONT,GL_SPECULAR,especular);
glMaterialf(GL_FRONT,GL_SHININESS,20);
glRotated(180,1,0,0);
gluCylinder(p,1,0,2,99,99);
glTranslated(0,0,.5);
gluCylinder(p,.9,0,2,99,99);
glTranslated(0,0,.5);
gluCylinder(p,.8,0,2,99,99);
glEndList();

//MUÑECOS-----------------------------------------------
glNewList(muñecos,GL_COMPILE);
//cuerpo
ambiental[0]=.9, ambiental[1]=.9, ambiental[2]=.9;
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,ambiental);
glMaterialfv(GL_FRONT,GL_SPECULAR,especular);
glMaterialf(GL_FRONT,GL_SHININESS,20);
glTranslated(0,-2,-6);
glutSolidSphere(.8,99,99);
glTranslated(0,-1,0);
glutSolidSphere(1,99,99);
glTranslated(0,2.1,0);
glutSolidSphere(.5,99,99);

//ojos
ambiental[0]=0, ambiental[1]=0, ambiental[2]=0;
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,ambiental);
glMaterialfv(GL_FRONT,GL_SPECULAR,especular);
glMaterialf(GL_FRONT,GL_SHININESS,20);
glTranslated(-.2,.2,.45);
glutSolidSphere(.1,99,99);
glTranslated(.4,0,0);
glutSolidSphere(.1,99,99);

//botones
glTranslated(-.2,-.8,.2);
glutSolidSphere(.1,99,99);
glTranslated(0,-.2,.2);
glutSolidSphere(.1,99,99);
glTranslated(0,-.2,.1);
glutSolidSphere(.1,99,99);

//sonrisa
glTranslated(-.09,.8,-.5);
glutSolidSphere(.05,99,99);
glTranslated(.1,0,0);
glutSolidSphere(.05,99,99);
glTranslated(.1,0,0);
glutSolidSphere(.05,99,99);
glTranslated(.1,.05,0);
glutSolidSphere(.05,99,99);

//nariz
ambiental[0]=.8, ambiental[1]=.3, ambiental[2]=0;
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,ambiental);
glMaterialfv(GL_FRONT,GL_SPECULAR,especular);
glMaterialf(GL_FRONT,GL_SHININESS,20);
glTranslated(-.2,.2,-.1);
glutSolidCone(.1,1,99,99);

//sombrero
ambiental[0]=0, ambiental[1]=0, ambiental[2]=0;
glMaterialfv(GL_FRONT,GL_AMBIENT_AND_DIFFUSE,ambiental);
glMaterialfv(GL_FRONT,GL_SPECULAR,especular);
glMaterialf(GL_FRONT,GL_SHININESS,20);
glTranslated(0,.3,-.4);
glRotated(90,1,0,0);
glutSolidTorus(.1,.5,99,99);
glTranslated(0,0,-.6);
gluCylinder(p,.5,.5,.6,90,90);
glEndList();
gluDeleteQuadric(p);
}

void InitCamara()
{
inc=0.8;
teta=180;
phi=0;
eta=90;
pcx=0;
pcy=0;
pcz=0;
ocx=cos(phi*PI/180)*sin(teta*PI/180)+pcx;
ocy=sin(phi*PI/180)+pcy;
ocz=cos(phi*PI/180)*cos(teta*PI/180)+pcz;
upx=cos(eta*PI/180);
upy=sin(eta*PI/180);
}

void Especial (int tecla,int x, int y)
{
if(tecla==GLUT_KEY_UP)
{
pcx+=inc*sin(teta*PI/180);
ocx+=inc*sin(teta*PI/180);
pcz+=inc*cos(teta*PI/180);
ocz+=inc*cos(teta*PI/180);
glutPostRedisplay();
}
if(tecla==GLUT_KEY_DOWN)
{
pcx-=inc*sin(teta*PI/180);
ocx-=inc*sin(teta*PI/180);
pcz-=inc*cos(teta*PI/180);
ocz-=inc*cos(teta*PI/180);
glutPostRedisplay();
}
if(tecla==GLUT_KEY_RIGHT)
{
pcx+=inc*sin((teta-90)*PI/180);
ocx+=inc*sin((teta-90)*PI/180);
pcz+=inc*cos((teta-90)*PI/180);
ocz+=inc*cos((teta-90)*PI/180);
glutPostRedisplay();
}
if(tecla==GLUT_KEY_LEFT)
{
pcx-=inc*sin((teta-90)*PI/180);
ocx-=inc*sin((teta-90)*PI/180);
pcz-=inc*cos((teta-90)*PI/180);
ocz-=inc*cos((teta-90)*PI/180);
glutPostRedisplay();
}
if(tecla==GLUT_KEY_PAGE_UP)
{
pcy+=inc;
ocy+=inc;
glutPostRedisplay();
}
if(tecla==GLUT_KEY_PAGE_DOWN)
{
pcy-=inc;
ocy-=inc;
glutPostRedisplay();
}
}

void Raton(int boton, int edo, int x, int y)
{
if(boton==GLUT_LEFT_BUTTON)
{
ok=1;
okd=0;
xini=x;
yini=y;
}
if(boton==GLUT_RIGHT_BUTTON)
{
ok=0;
okd=1;
xini=x;
}
if(boton==GLUT_MIDDLE_BUTTON)
{
ok=0;
okd=0;
}
}

void Mueve(int x, int y)
{
int dx,dy;

if(ok)
{
dx=x-xini;
dy=y-yini;
xini=x;
yini=y;
teta-=dx*0.3;
if(teta>360)
teta-=360;
if(teta<0)
teta+=360;
phi-=dy*0.3;
if(phi>89)
phi=89;
if(phi<-89)
phi=-89;
ocx=cos(phi*PI/180)*sin(teta*PI/180)+pcx;
ocy=sin(phi*PI/180)+pcy;
ocz=cos(phi*PI/180)*cos(teta*PI/180)+pcz;
glutPostRedisplay();
}
if(okd)
{
dx=x-xini;
xini=x;
eta+=dx*0.3;
if(eta>360)
eta-=360;
if(eta<0)
eta+=360;
upx=cos(eta*PI/180);
upy=sin(eta*PI/180);
glutPostRedisplay();
}
}

miércoles, 7 de noviembre de 2012

API REST con ASP.NET

Aquí la liga del turorial!

http://www.codeproject.com/Articles/426769/Creating-a-REST-service-using-ASP-NET-Web-API

Después de haber probado el tutorial anterior, llegué a la conclusión de que algunas funciones o métodos no estaban actualizados por lo que buscando en la página de descarga de librería encontré este tutorial que les va a servir. Además tiene más ejemplos.


http://www.asp.net/web-api/overview/getting-started-with-aspnet-web-api/tutorial-your-first-web-api

Desarrollaremos la aplicación cliente con:

http://appinventor.mit.edu/

API's e información:

http://www.programmableweb.com/