Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- C code to display Bengali Script on the DOS prompt
- Sandipan Dey
- BCSE, JU, Kolkata
- 2002
- */
- #include <math.h>
- #include <graphics.h>
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- #include <dos.h>
- #define MAX 10
- struct Point{
- double x,y;
- };
- double pow(double x,int i) {
- if (i==0) return 1; //0**0=1,for Jn,0(0)=1,i=0
- else if(x<=0 || i<0)return 0;
- else {
- double p=1;
- for(int j=0;j<i;++j)p*=x;
- return p;
- }
- }
- double fact(int n) {
- double f=1;
- for(int i=1;i<=n;++i)
- f=f*i;
- return f;
- }
- double C(int n,int i) {
- if(i<0 || n<0 || i>n)return 0;
- else if(i==0 || i==n)return 1;
- else return fact(n)/(fact(i)*fact(n-i));
- }
- double J(int n,int i,double t) { //Bernstein Basis Function
- return C(n,i)*pow(t,i)*pow(1-t,n-i);
- }
- Point P(Point* B,int n,double t) {
- Point p={0,0};
- for(int i=0;i<=n;++i) {
- p.x+=B[i].x*J(n,i,t);
- p.y+=B[i].y*J(n,i,t);
- }
- return p;
- }
- void PatternP(int lt=100,int tp=100,int color=15) {
- int n=4;
- double t;
- Point B[MAX]={{lt,tp+30},{lt+50,tp+45},{lt+50,tp+80},{lt,tp+100}},p;
- for(t=0;t<=1;t+=0.005) {
- p=P(B,n-1,t);putpixel(p.x,p.y,color);
- } //Draw Be'zier Curve of Degree n-1
- B[0].x=lt;B[0].y=tp+30;
- B[1].x=lt+70;B[1].y=tp+10;
- B[2].x=lt+50;B[2].y=tp+50;
- B[3].x=lt+100;B[3].y=tp+100;
- for(t=0;t<=1;t+=0.005){
- p=P(B,n-1,t);putpixel(p.x,p.y,color);
- } //Draw Be'zier Curve of Degree n-1
- B[0].x=lt;B[0].y=tp+100;
- B[1].x=lt+70;B[1].y=tp+100;
- B[2].x=lt+50;B[2].y=tp+50;
- B[3].x=lt+100;B[3].y=tp+100;
- for(t=0;t<=1;t+=0.005){
- p=P(B,n-1,t);putpixel(p.x,p.y,color);
- } //Draw Be'zier Curve of Degree n-1
- line(lt+100,tp+10,lt+100,tp+180);
- line(lt+95,tp+20,lt+130,tp+20);
- }
- void PatternB(int lt=100,int tp=100,int color=15) {
- int n=3;
- double t;
- Point B[MAX]={{lt,tp+100},{lt+50,tp+70},{lt+100,tp+180}},p;
- for(t=0;t<=1;t+=0.005) {
- p=P(B,n-1,t);putpixel(p.x,p.y,color);
- } //Draw Be'zier Curve of Degree n-1
- line(lt+100,tp+20,lt+100,tp+180);
- line(lt+100,tp+20,lt,tp+100);
- line(lt,tp+20,lt+120,tp+20);
- }
- void PatternJ(int lt=100,int tp=100,int color=15) {
- int n=3;
- double t;
- Point B[MAX]={{lt,tp+120},{lt+50,tp+90},{lt+100,tp+180}},p;
- for(t=0;t<=1;t+=0.005) {
- p=P(B,n-1,t);putpixel(p.x,p.y,color);
- } //Draw Be'zier Curve of Degree n-1
- line(lt+100,tp+20,lt+100,tp+180);
- line(lt+5,tp+20,lt+60,tp+75);
- line(lt+60,tp+75,lt,tp+120);
- line(lt,tp+20,lt+110,tp+20);
- }
- void PatternR(int lt=100,int tp=100,int color=15) {
- PatternB(lt,tp,color);
- circle(lt+50,tp+140,15);
- }
- void PatternD(int lt=100,int tp=100,int color=15) {
- int n=4;
- double t;
- Point B[MAX]={{lt+20,tp+100},{lt+60,tp+60},{lt+80,tp+60},{lt+100,tp+100}},p;
- for(t=0;t<=1;t+=0.005) {
- p=P(B,n-1,t);putpixel(p.x,p.y,color);
- } //Draw Be'zier Curve of Degree n-1
- B[0].x=lt+100;B[0].y=tp+100;
- B[1].x=lt+50;B[1].y=tp+110;
- B[2].x=lt+50;B[2].y=tp+140;
- B[3].x=lt+90;B[3].y=tp+170;
- for(t=0;t<=1;t+=0.005) {
- p=P(B,n-1,t);putpixel(p.x,p.y,color);
- } //Draw Be'zier Curve of Degree n-1
- line(lt,tp+20,lt+110,tp+20);
- line(lt+20,tp+20,lt+20,tp+100);
- }
- void PatternU(int lt=100,int tp=100,int color=15) {
- int n=4;
- double t;
- Point B[MAX]={{lt+10,tp},{lt,tp+50},{lt+40,tp+50},{lt+70,tp}},p;
- for(t=0;t<=1;t+=0.005) {
- p=P(B,n-1,t);putpixel(p.x,p.y,color);
- } //Draw Be'zier Curve of Degree n-1
- B[0].x=lt+10;B[0].y=tp;
- B[1].x=lt+70;B[1].y=tp-50;
- B[2].x=lt+70;B[2].y=tp+70;
- B[3].x=lt+200;B[3].y=tp+50;
- for(t=0;t<=1;t+=0.005) {
- p=P(B,n-1,t);putpixel(p.x,p.y,color);
- } //Draw Be'zier Curve of Degree n-1
- }
- void Line(int lt=100,int tp=100,int color=15) {
- setcolor(color);
- line(lt,tp+10,lt,tp+180);
- line(lt-20,tp+20,lt+20,tp+20);
- }
- void Name() {
- rectangle(515,375,630,415);
- outtextxy(520,380,"SANDIPAN DEY");
- outtextxy(520,390,"BCSE-IV");
- outtextxy(520,400,"Roll-99710");
- }
- void main() {
- int xm,ym;
- clrscr();
- int gd=DETECT,gm;
- initgraph(&gd,&gm,"");
- xm=getmaxx();ym=getmaxy();
- int i=1;
- Name();
- while(!kbhit()) {
- //setcolor(i);
- PatternJ(0,100,i);
- Line(125);
- //setcolor(i);
- PatternD(140,100,i);
- PatternB(250,100,i);
- PatternP(375,100,i);
- PatternU(410,280,i);
- PatternR(500,100,i);
- i=(i+1)%15+1;
- delay(1000);
- }
- getch();
- closegraph();
- }
Add Comment
Please, Sign In to add comment