Pages

Tuesday, May 3, 2011

HTML - Login Box

1. Login Box
==================

<div id="po">
<div id="page">
<table>
<tr>
<td>Username</td>
<td><input type="text" class="input"/></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" class="input"/></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="Log In"/></td>
</tr>
</table>
</div>
</div>
<style>
#page{
 background: #af0;
 width: 300px;
 text-align: center;
 padding: 10px;
 -moz-border-radius: 4px;

}
.input{
 border: 1px solid #8c0;
 width: 200px;
 padding: 2px;
}
table td{
 font: 14px arial;
 color: #22f;
 font-weight: bold;
 padding: 5px;
}
#po{
 padding: 2px;
 border: 1px solid #af0;
 max-width: -moz-fit-content;
 -moz-border-radius: 4px;
 background: #fff;
}
body{
 background: #eee;
}
</style>

Thursday, March 31, 2011

PyQt - Data App

import sys
from PyQt4 import QtGui, QtCore


class DataApp(QtGui.QWidget):

    def __init__(self, parent=None):

        QtGui.QWidget.__init__(self, parent)

        self.setGeometry(200, 100, 400, 300);
        self.setWindowTitle('Data App')
        self.setWindowIcon(QtGui.QIcon('e.png'))


        self.lName = QtGui.QLabel('Name', self)
        self.lCity = QtGui.QLabel('City', self)
        self.leName = QtGui.QLineEdit(self)
        self.leCity = QtGui.QLineEdit(self)
        self.pbAdd = QtGui.QPushButton('Add', self)

        self.lsName = QtGui.QLabel('Name', self)
        self.lsCity = QtGui.QLabel('City', self)
        self.lsNo = QtGui.QLabel('No', self)

        self.col1 = 10
        self.row1 = 10
        self.width = 150
        self.height = 20
        self.hozSpace = 10
        self.verSpace = 10

        self.col2 = self.col1 + self.width + self.hozSpace
        self.col3 = self.col1 + 2*(self.width + self.hozSpace)

        self.row2 = self.row1 + self.height + self.verSpace
        self.row3 = self.row1 + 2*(self.height + self.verSpace)

        self.lName.setGeometry(self.col1, self.row1, self.width, self.height)
        self.lCity.setGeometry(self.col2, self.row1, self.width, self.height)
        self.leName.setGeometry(self.col1, self.row2, self.width, self.height)
        self.leCity.setGeometry(self.col2, self.row2, self.width, self.height)
        self.pbAdd.setGeometry(self.col3, self.row2, self.width-81, self.height)

        self.colS1 = 10
        self.colS2 = self.colS1 + 30
        self.colS3 = self.colS1 + 30 + 150

        self.lsNo.setGeometry(self.colS1, self.row3, self.width, self.height)
        self.lsName.setGeometry(self.colS2, self.row3, self.width, self.height)
        self.lsCity.setGeometry(self.colS3, self.row3, self.width, self.height)

        self.connect(self.pbAdd, QtCore.SIGNAL('clicked()'), self.addData)

        self.n = 0;

        len = 5

        self.no = [QtGui.QLabel('', self) for i in range(len)]
        self.name = [QtGui.QLabel('', self) for i in range(len)]
        self.city = [QtGui.QLabel('', self) for i in range(len)]   



    def addData(self):

        try:
            self.no[self.n].setText(str(self.n + 1))
            self.name[self.n].setText(self.leName.text())
            self.city[self.n].setText(self.leCity.text())

            row = 90 + (20 * self.n)

            self.no[self.n].setGeometry(self.colS1, row, self.width, self.height)
            self.name[self.n].setGeometry(self.colS2, row, self.width, self.height)
            self.city[self.n].setGeometry(self.colS3, row, self.width, self.height)

            self.n = self.n + 1

        except IndexError:

            QtGui.QMessageBox.information(self, 'Maximum Capacity', "The List Is Maximum", QtGui.QMessageBox.Ok)

   

app = QtGui.QApplication(sys.argv)
one = DataApp()
one.show()
sys.exit(app.exec_())
       
               
       
       

Monday, March 28, 2011

Javascript - Like Google

index.php


<html>
<head>
<title>
Javascript Update
</title>

</head>
<body>
<select id="name">
    <option value="aura">Aura</option>
    <option value="luna">Luna</option>
    <option value="lady">Lady</option>
</select>
<input type="button" value="Get" onclick="getData()"/>
<br/>
<input type="button" value="Last Name" onclick="lastName()"/>
<input type="button" value="City" onclick="city()"/>
<input type="button" value="Age" onclick="age()"/>
<script>
function getData(){
    var script = document.createElement('script');
    var name = document.getElementById('name');
    var head = document.getElementsByTagName('head')[0];
    head.appendChild(script);
    script.setAttribute('src','hello.php?fname='+name.value);
    alert('');
}
function lastName(){
    alert(data.lname);
}
function city(){
    alert(data.city);
}
function age(){
    alert(data.age);
}


</script>


</body>
</html>


hello.php

<?php

    $data = array(
        'luna' => array('maya','denpasar',24),
        'lady' => array('gaga','new york',24),
         'aura' => array('kasih','jakarta',25),
    );
   
    $fname = $_GET['fname'];
   
    $output = 'var data = {};';
    $out = array();
   
    foreach($data as $key => $value){
        if(strcmp($fname, $key) == 0){
            foreach($value as $v){
                $out[] = $v;
               
            }
        }
    }
    $output .= 'data.lname = "'.$out[0].'";';
                $output .= 'data.city = "'.$out[1].'";';
                $output .= 'data.age = "'.$out[2].'";';
   
    header('Content-type: text/javascript');
    echo $output;
?>
   

OpenGL - Gridding

#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

using namespace std;

#define WIDTH 400
#define HEIGHT 300
#define N 10
float dens[N][N] = {};
void init(){
    glClearColor(1.0, 1.0, 1.0,1.0);
    //glMatrixMode(GL_PROJECTION);
    //glLoadIdentity();
    //glOrtho(0, WIDTH, HEIGHT, 0, 0, 1);
    //glMatrixMode(GL_MODELVIEW);
    //gluOrtho2D(0.0,1.0,0.0,1.0);
    //glDisable(GL_DEPTH_TEST);

}



void display(){
    glClear(GL_COLOR_BUFFER_BIT);
    glPointSize(3.0);
    glBegin(GL_QUADS);
    float h = 1.00/N;
    for(int i=0; i<N; i++){
        float x = 1.0*i/N;
        for(int j=0; j<N; j++){
            float y = 1.0*j/N;
            glColor3f(1.0,0.0,0.0);
            glVertex2f(x, y);
            glColor3f(0.0,1.0,0.0);
            glVertex2f(x+h, y);
            glColor3f(0.0,0.0,1.0);
            glVertex2f(x+h, y+h);
            glColor3f(0.0,1.0,1.0);
            glVertex2f(x, y+h);
        }
    }
    glEnd();
    glFlush();
}

int main(int argc, char* argv[]){

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
    glutInitWindowSize(WIDTH, HEIGHT);
    glutInitWindowPosition(200, 100);
    glutCreateWindow("Lucia OpenGL");

    glClearColor(1.0, 1.0, 1.0, 0.0);
    //glMatrixMode(GL_PROJECTION);
    //glLoadIdentity();
    gluOrtho2D(0.0,1.0,0.0,1.0);
    glutDisplayFunc(display);
    glutMainLoop();

    return 0;
}

Friday, March 25, 2011

HTML5 - Lucia


var ctx = document.getElementById('canvas').getContext('2d');

grad = ctx.createLinearGradient(0,30,280,30);
grad.addColorStop(0.1, '#af8');
grad.addColorStop(0.5, '#fc0');
grad.addColorStop(1.0, '#faf');
ctx.fillStyle = grad;

ctx.fillRect(0,0,280,60)

ctx.fillStyle = '#a5f';
ctx.font = '30px arial';
ctx.fillText('Lucia Corporation',20, 40);

The above code will finish in like below:


Tuesday, March 22, 2011

OpenGL - Dragging Single Object


#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

#include <ctime>
#include <cstdlib>

#include <iostream>

using namespace std;

#define WIDTH 400.00
#define HEIGHT 300.00

typedef struct point{
    float x;
    float y;
}point;

point titik[4];


void init(){
    glClearColor(1.0,1.0,1.0,1.0);
    gluOrtho2D(0,1,0,1);

    titik[0].x = 0.1;
    titik[0].y = 0.1;

    titik[1].x = 0.2;
    titik[1].y = 0.1;

    titik[2].x = 0.2;
    titik[2].y = 0.2;

    titik[3].x = 0.1;
    titik[3].y = 0.2;
}

void display(){
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(0.0,0.0,1.0);

    glBegin(GL_QUADS);
        glVertex2f(titik[0].x, titik[0].y);
        glVertex2f(titik[1].x, titik[1].y);
        glVertex2f(titik[2].x, titik[2].y);
        glVertex2f(titik[3].x, titik[3].y);
    glEnd();

    glFlush();
}

void keyboard(unsigned char key, int x, int ){
    switch(key){
        case 27:
            exit(1);
            break;
    }
}

void mouse(int mouse, int state, int x, int y){
    switch(mouse){
        case GLUT_LEFT_BUTTON:
            if(state == GLUT_DOWN){

            }
            break;
    }
}


void motion(int x, int y){

    float xx = x / WIDTH;
    titik[0].x = xx;
    titik[1].x = xx + 0.1;
    titik[2].x = xx + 0.1;
    titik[3].x = xx;

    float yy = y / HEIGHT;

    yy = 1 - yy;

    titik[0].y = yy;
    titik[1].y = yy;
    titik[2].y = yy + 0.1;
    titik[3].y = yy + 0.1;

    cout << xx << endl;
    glutPostRedisplay();
}

int main(int argc, char *argv[]){

    system("color 2f");

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
    glutInitWindowSize(WIDTH,HEIGHT);
    glutInitWindowPosition(200,100);
    glutCreateWindow("Simulation App");

    init();
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMotionFunc(motion);
    glutMouseFunc(mouse);

    glutMainLoop();

    return 0;
}

Sunday, March 20, 2011

OpenGL - Dragging Points

/**
 * This program will do the particle generation. Then directs the
 * particles move as the mouse moves.
 * The hope of the program is that the particle will move to the
 * right direction if the particle position
 * lies in left side than the mouse cursor. And reciprocally.
 *
 * @author   : irfanudin ridho
 * @email    : irfan.ub@gmail.com
 * @version  : 1.0
 * @date     : March 20, 2011
 */


#include <GL/gl.h>
#include <GL/glu.h>
#include <GL/glut.h>

#include <ctime>
#include <cstdlib>

#include <iostream>

using namespace std;
typedef struct{
    float x;
    float y;
}point;

#define nn 1000
point titik[nn];

// record the previous state
int prev_x = 0, prev_y=0;

void init(){
    glClearColor(1.0,1.0,1.0,1.0);
    gluOrtho2D(0,400,0,300);

    srand((unsigned)time(NULL));
    for(int i=0;i<nn;i++){
        titik[i].x = rand()/100;
        titik[i].y = rand()/100;
    }
}

void display(){
    glClear(GL_COLOR_BUFFER_BIT);
    glColor3f(0.0,0.0,1.0);

    glPointSize(2.0);
    glBegin(GL_POINTS);
        for(int i=0; i<nn; i++){
            glVertex2f(titik[i].x, titik[i].y);
        }
    glEnd();

    glFlush();
}

void keyboard(unsigned char key, int x, int ){
    switch(key){
        case 27:
            exit(1);
            break;
    }
}


void motion(int x, int y){

    // horizontal dragging
    if(x > prev_x){
        for(int i=0; i<nn; i++){
            titik[i].x++;
        }
    }else if(x < prev_x){
         for(int i=0; i<nn; i++){
            titik[i].x--;
         }
    }

    // vertical dragging: reverse
    if(y < prev_y){
        for(int i=0; i<nn; i++){
            titik[i].y++;
        }
    }else if(y > prev_y){
        for(int i=0; i<nn; i++){
            titik[i].y--;
        }
    }

    prev_x = x;
    prev_y = y;

    glutPostRedisplay();
}

int main(int argc, char *argv[]){

    system("color 2f");

    glutInit(&argc, argv);
    glutInitDisplayMode(GLUT_RGB | GLUT_SINGLE);
    glutInitWindowSize(400,300);
    glutInitWindowPosition(200,100);
    glutCreateWindow("Simulation App");

    init();
    glutDisplayFunc(display);
    glutKeyboardFunc(keyboard);
    glutMotionFunc(motion);

    glutMainLoop();

    return 0;
}