Skip to main content

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 Value   Number.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 In tege r 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&

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 m

Random Bouncing Ball Animation

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-&g

RGB in C

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,

CSS Selectors

Pattern Meaning Described in section First defined in CSS level * any element Universal selector 2 E an element of type E Type selector 1 E[foo] an E element with a "foo" attribute Attribute selectors 2 E[foo="bar"] an E element whose "foo" attribute value is exactly equal to "bar" Attribute selectors 2 E[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 selectors 2 E[foo^="bar"] an E element whose "foo" attribute value begins exactly with the string "bar" Attribute selectors 3 E[foo$="bar"] an E element whose "foo" att

Creating arrow edges using CSS

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) make width and height values 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; backgroun

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

A Simple Personal Diary written in Turbo C with Graphical User Interface Features, Birthday Reminder Notes Address 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

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 View Top View Side View In 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 dra

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

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