Posts

Showing posts from 2012

Base Conversion in Javascript

You might think how base conversion worked out in JavaScript. Here the solution, 

Number to Base ValueNumber.toString([radix]);Number - Integer number that is to be converted radix - base value either 2, 8, 16 (optional parameter)

Example:
<script>  //INTEGER TO BASE VALUE var n = 42; document.write(n.toString(2)); document.write(n.toString(8)); document.write(n.toString(16)); //HEX TO base var h = 0xa; document.write(n.toString(2)); document.write(n.toString(8)); </script> Output:
101010 52 2a 1010 12
Any Base value to Integer value
parseInt(string, [radix]); 
string - string that is to be converted. The string can be binary value, octal value or hexadecimal value
radix - base value either 2, 8, 16 (optional parameter)

Example:
<script>  //Binary to integer document.write(parseInt('111',2)); //Octal to integer document.write(parseInt('12',8)); //Hex to integer document.write(parseInt('0xc',16)); </script> Output:
7 10 12

Exception Handling in PHP

Notices: These are trivial, non-critical errors that PHP encounters while executing a script Example:  Accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all - although you can change this default behavior.
Warnings: These are more serious errors Example: attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination.
Fatal errors: These are critical errors Example: Instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP’s default behavior is to display them to the user when they take place.
Parse Error: When we make mistake in PHP code like, missing semicolon or any unexpected symbol in code
What are Exceptions? Exceptions are the PHP 5 way of flagging up an unexpected event. They contain an information message, and can be extended just like any other object…

Random Bouncing Ball Animation

Image
Simple animation of random balls that bounces within the screen


Source:

#include<stdio.h> #include<graphics.h> #include<conio.h> #include<dos.h> #include<math.h> void drawBall(struct ball *b, int color); struct ball{ int x, y; int dx, dy; int radius; }; void main() { int gd=0, gm=VGAHI; int i; struct ball b[10]; initgraph(&gd, &gm, ""); for(i=1;i<=15;i++){ b[i].radius = rand()%20; b[i].x=rand()%getmaxx(); b[i].y=rand()%getmaxy(); b[i].dx=2; b[i].dy=4; } while(!kbhit()) { delay(5); cleardevice(); for(i=1;i<=15;i++) drawBall(&b[i],i); } closegraph(); } void drawBall(struct ball *b, int color){ setfillstyle(1,color); setcolor(color); fillellipse(b->x, b->y, b->radius, b->radius); if(b->x+b->radius > getmaxx() || b->x-b->radius<0) b->dx = -b->dx; if(b->y+b->radius > getmaxy() || b->y-b->radius<0) b->dy = -b->dy; b->x+=b->dx; …

RGB in C

Image
Default palette size for normal graphics driver is 16 i.e) the color number rages from 0 to 15
To use rgb color modes we have to choose VGA or IBM 8514 as a graphics driver
For VGA, Palette size is 16 i.e) color number ranges from 0-16 For IBM 8514, Palette size is 256 i.e) color number ranges from 0-255, we can also say it as VGA with 256 palette size
By using setrgbpalette function we can generate RGB colors, we can generate colors with respect to Palette size. This function replaces the default palette colors with the generated Palette colors.
Syntax: void setrgbpalette(int colornum, int red, int green, int blue); /* colornum - color number in palette (0-15 or 0-255 depens on graphics driver) red - color value for red (0-255) green - color value for green (0-255) blue - color value for blue (0-255) */

Example:
#include<graphics.h> #include<stdio.h> #include<conio.h> #include<stdlib.h> #include<time.h> void main(){ int gd=VGA, gm=VGAHI, i, r, g, b , x, y,…

CSS Selectors

PatternMeaningDescribed in sectionFirst defined in CSS level*any elementUniversal selector2Ean element of type EType selector1E[foo]an E element with a "foo" attributeAttribute selectors2E[foo="bar"]an E element whose "foo" attribute value is exactly equal to "bar"Attribute selectors2E[foo~="bar"]an E element whose "foo" attribute value is a list of whitespace-separated values, one of which is exactly equal to "bar"Attribute selectors2E[foo^="bar"]an E element whose "foo" attribute value begins exactly with the string "bar"Attribute selectors3E[foo$="bar"]an E element whose "foo" attribute value ends exactly with the string "bar"Attribute selectors3E[foo*="bar"]an E element whose "foo" attribute value contains the substring "bar"Attribute selectors3E[foo|="en"]an E element whose "foo" attribute has a hyphen-…

Creating arrow edges using CSS

Image
Before we start, we have to understand the concept behind  "border"

Basically, borders render like this:
#sampleStyle{ border-top : 25px solid #a71d95; border-right : 25px solid #1da2a7; border-bottom: 25px solid #70a71d; border-left : 25px solid #c10902; width :60px; heigth:60px; }
If we compress the content area, i.e) makewidthand heightvalues to"0px"

#sampleStyle{ border-top : 25px solid #a71d95; border-right : 25px solid #1da2a7; border-bottom: 25px solid #70a71d; border-left : 25px solid #c10902; width :0px; heigth:0px; }
If we want right arrow , make all border-color except border-left-color to transparent


#sampleStyle{ border-top : 25px solid #a71d95; border-right : 25px solid #1da2a7; border-bottom: 25px solid #70a71d; border-left : 25px solid #c10902; width :0px; heigth:0px; }

Example:
.arrow_box { position: relative; background: #182126; border: 1px solid #000000; p…

Personal Diary - A Mini Project Written in Turbo C With Graphical Interface

Image
A Simple Personal Diary written in Turbo C with Graphical User Interface

Features,
Birthday ReminderNotesAddress Book The main part of the project is UI

'GUI.h' header file includes texbox, message-box and more custom graphical functions 
' Dairy.h' header file includes functionality of Personal Dairy
' Dairyload.c' includes loadingscreen, login screen, installation check etc
'Dairy.c' - execution stats here




3D Projection

Image
I hope you will remember engineering graphics in your first year of engineering, This basic idea will be useful in understanding the concept.  Usually projection is nothing but the representation of a 3D object in a 2D form with the angle we view. Basically we represent a 3D object in a 2D form with three basic views
Front ViewTop ViewSide ViewIn the following code, the user is asked to enter the co-ordinates for a 2D object and with the depth we enter it will generate a 3D object. For example , consider a cube - the view you see without a depth will be a square.

Note: In computer graphics the co-ordinates start from top-left (0,0) of your screen


CODE :
#include <stdio.h> #include <stdlib.h> #include <graphics.h> #include <conio.h> int ARRAY_SIZE; int array_max(int *arr, int returnIndex); int array_min(int *arr, int returnIndex); void draw3d(int sides, int *x, int *y, int depth); void drawFrontView(int sides, int *x, int *y); void drawSideView(int sides, int *x,…

3D Rotation

#include <stdio.h> #include <stdlib.h> #include<graphics.h> #include<conio.h> #include<math.h> void draw3d(int fs,int x[20],int y[20],int tx,int ty,int d); void draw3d(int fs,int x[20],int y[20],int tx,int ty,int d) { int i,j,k=0; for(j=0;j<2;j++) { for(i=0;i<fs;i++) { if(i!=fs-1) { line(x[i]+tx+k,y[i]+ty-k,x[i+1]+tx+k,y[i+1]+ty-k); } else line(x[i]+tx+k,y[i]+ty-k,x[0]+tx+k,y[0]+ty-k); } k=d; } for(i=0;i<fs;i++) { line(x[i]+tx,y[i]+ty,x[i]+tx+d,y[i]+ty-d); } } void main() { int gd=DETECT,gm; int x[20],y[20],x1[20],y1[20],tx=0,ty=0,i,j,k,fs,temp,d,a; float theta; initgraph(&gd,&gm,""); printf("No of sides (front view only) : "); scanf("%d",&fs); printf("Co-ordinates : "); for(i=0;i<fs;i++) { printf("(x%d,y%d)",i,i); scanf("%d%d",&x[i],&y[i]); } printf("Depth :"); scanf("%d",&d); draw3d(fs,x,y,tx,ty,d); printf("translation (x,y),rotate(a…

3D Scaling

#include <stdio.h> #include <stdlib.h> #include<graphics.h> #include<conio.h> #include<math.h> void draw3d(int fs,int x[20],int y[20],int tx,int ty,int d); void draw3d(int fs,int x[20],int y[20],int tx,int ty,int d) { int i,j,k=0; for(j=0;j<2;j++) { for(i=0;i<fs;i++) { if(i!=fs-1) line(x[i]+tx+k,y[i]+ty-k,x[i+1]+tx+k,y[i+1]+ty-k); else line(x[i]+tx+k,y[i]+ty-k,x[0]+tx+k,y[0]+ty-k); } k=d; } setfillstyle(1,15); for(i=0;i<fs;i++) { line(x[i]+tx,y[i]+ty,x[i]+tx+d,y[i]+ty-d); } } void main() { int gd=DETECT,gm; int x[20],y[20],x1[20],y1[20],tx=0,ty=0,i,j,k,fs,temp,d,xm,ym; float theta; initgraph(&gd,&gm,""); printf("no of sides (front view only) : "); scanf("%d",&fs); printf("co-ordinates : "); for(i=0;i<fs;i++) { printf("(x%d,y%d)",i,i); scanf("%d%d",&x[i],&y[i]); } printf("Depth :"); scanf("%d",&d); draw3d(fs,x,y,tx,ty,d); printf("magni…

3D Translation

#include <stdio.h> #include <stdlib.h> #include<graphics.h> #include<conio.h> void draw3d(int fs,int x[20],int y[20],int tx,int ty,int d); void draw3d(int fs,int x[20],int y[20],int tx,int ty,int d) { int i,j,k=0; for(j=0;j<2;j++) { for(i=0;i<fs;i++) { if(i!=fs-1) line(x[i]+tx+k,y[i]+ty-k,x[i+1]+tx+k,y[i+1]+ty-k); else line(x[i]+tx+k,y[i]+ty-k,x[0]+tx+k,y[0]+ty-k); } k=d; } for(i=0;i<fs;i++) { line(x[i]+tx,y[i]+ty,x[i]+tx+d,y[i]+ty-d); } } void main() { int gd=DETECT,gm; int x[20],y[20],tx=0,ty=0,i,fs,d; initgraph(&gd,&gm,""); printf("no of sides (front view only) : "); scanf("%d",&fs); printf("co-ordinates : "); for(i=0;i<fs;i++) { printf("(x%d,y%d)",i,i); scanf("%d%d",&x[i],&y[i]); } printf("Depth :"); scanf("%d",&d); draw3d(fs,x,y,tx,ty,d); printf("translation (x,y)"); scanf("%d%d",&tx,&ty); draw3d(fs,x,y,tx,ty,d);…

2D Shearing

#include <stdio.h> #include <stdlib.h> #include<graphics.h> #include<conio.h> #include<math.h> void draw2d(int,int [],int [],int,int); void main() { int gd=DETECT,gm; int x[20],y[20],x1[20],y1[20],tx=0,ty=0,i,fs,a; initgraph(&gd,&gm,""); printf("No of sides : "); scanf("%d",&fs); printf("Co-ordinates : "); for(i=0;i<fs;i++) { printf("(x%d,y%d)",i,i); scanf("%d%d",&x[i],&y[i]); } draw2d(fs,x,y,tx,ty); printf("translation (x,y) : "); scanf("%d%d",&tx,&ty); while(1) { clrscr(); cleardevice(); printf("1. X Shear\n\n2. Y Shear\n\n3. Exit\n\n"); draw2d(fs,x,y,0,0); switch(getche()) { case '1': printf("X Shear Value : "); scanf("%d",&a); for(i=0;i<fs;i++) { x1[i]=x[i]+(a*(y[i]-ty)); y1[i]=y[i]; } break; case '2': printf("Y Shear Value : "); scanf("%d",&a); for(i=0;i<fs;i++)…

2D Scaling

#include<stdio.h> #include <stdlib.h> #include<graphics.h> #include<conio.h> #include<math.h> void draw2d(int,int [],int [],int,int); void main() { int gd=DETECT,gm; int x[20],y[20],tx=0,ty=0,i,fs; int mx,my; initgraph(&gd,&gm,""); printf("No of sides : "); scanf("%d",&fs); printf("Co-ordinates : "); for(i=0;i<fs;i++) { printf("(x%d,y%d)",i,i); scanf("%d%d",&x[i],&y[i]); } draw2d(fs,x,y,tx,ty); printf("magnification (x,y) : "); scanf("%d%d",&mx,&my); for(i=0;i<fs;i++) { x[i]=x[i]*mx; y[i]=y[i]*my; } draw2d(fs,x,y,tx,ty); getch(); } void draw2d(int fs,int x[20],int y[20],int tx,int ty) { int i; for(i=0;i<fs;i++) { if(i!=(fs-1)) line(x[i]+tx,y[i]+ty,x[i+1]+tx,y[i+1]+ty); else line(x[i]+tx,y[i]+ty,x[0]+tx,y[0]+ty); } }

2D Rotation

#include <stdio.h> #include <stdlib.h> #include<graphics.h> #include<conio.h> #include<math.h> void draw2d(int,int [],int [],int,int); void main() { int gd=DETECT,gm; int x[20],y[20],x1[20],y1[20],tx=0,ty=0,i,fs,a; float theta; initgraph(&gd,&gm,""); printf("No of sides : "); scanf("%d",&fs); printf("Co-ordinates : "); for(i=0;i<fs;i++) { printf("(x%d,y%d)",i,i); scanf("%d%d",&x[i],&y[i]); } draw2d(fs,x,y,tx,ty); printf("translation (x,y), Angle : "); scanf("%d%d%d",&tx,&ty,&a); theta=(float)(a*(3.14/180)); for(i=0;i<fs;i++) { x1[i]=tx+((x[i]-tx)*cos(theta))-((y[i]-ty)*sin(theta)); y1[i]=ty+((y[i]-ty)*cos(theta))+((x[i]-tx)*sin(theta)); } draw2d(fs,x1,y1,tx,ty); getch(); } void draw2d(int fs,int x[20],int y[20],int tx,int ty) { int i; for(i=0;i<fs;i++) { if(i!=(fs-1)) line(x[i]+tx,y[i]+ty,x[i+1]+tx,y[i+1]+ty); else line(x[i]+tx,y[i]+ty,…