Seven Segment Display

#include 
#include 
#include 
#include 

#define ON  1
#define OFF 0

int maxX, maxY;

int lcdPoly[7][14] = {
                     { 260,100 , 270,93  , 345,93  , 355,100 , 345,107 , 270,107 , 260,100},   // segment a
                     { 358,101 , 366,111 , 357,177 , 348,185 , 342,179 , 351,112 , 358,101},   // segment b
                     { 347,191 , 355,201 , 345,270 , 336,276 , 330,270 , 339,201 , 348,191},   // segment c
                     { 240,280 , 250,273 , 325,273 , 335,280 , 325,287 , 250,287 , 240,280},   // segment d
                     { 247,191 , 255,201 , 245,270 , 236,276 , 230,270 , 239,201 , 248,191},   // segment e 
                     { 258,101 , 266,111 , 257,177 , 249,185 , 242,175 , 251,112 , 258,101},   // segment f
                     { 250,190 , 260,183 , 335,183 , 345,190 , 335,197 , 260,197 , 250,190}    // segment g
                  };

int alphanums[16][7] = { 
                   {1,1,1,1,1,1,0},  //0
                   {0,1,1,0,0,0,0},  //1
                   {1,1,0,1,1,0,1},  //2
                   {1,1,1,1,0,0,1},  //3
                   {0,1,1,0,0,1,1},  //4 
                   {1,0,1,1,0,1,1},  //5
                   {1,0,1,1,1,1,1},  //6
                   {1,1,1,0,0,0,0},  //7
                   {1,1,1,1,1,1,1},  //8
                   {1,1,1,1,0,1,1},  //9
                   {1,1,1,1,1,0,1},  //a
                   {0,0,1,1,1,1,1},  //b
                   {1,0,0,1,1,1,0},  //c
                   {0,1,1,1,1,0,1},  //d
                   {1,1,0,1,1,1,1},  //e
                   {1,0,0,0,1,1,1}   //f  
                 };


void powerSegment( int lcd, int status)
{
     if( status == ON)
     {
          setcolor( RED);
          setfillstyle( SOLID_FILL, YELLOW);           
     }
     else
     {
         setcolor( LIGHTBLUE);
         setfillstyle( SOLID_FILL, LIGHTBLUE);   
     }
     fillpoly( 7, lcdPoly[lcd]);
}


int main(void)
{
    initwindow(640, 400, "My Window");
    maxX = getmaxx();
    maxY = getmaxy();
    
    
    setfillstyle( SOLID_FILL, LIGHTBLUE);
    bar( 220, 78, 382, 300);
    
    int i=0;
    
    while( !kbhit())
    {
           i = (i==16)?0:i;
           
           for( int j=0; j<7; j++)
                powerSegment( j, alphanums[i][j]);
                     
           delay(1000);           
           i++;
    }
     
   
    getch();
    closegraph();
    return 0;
}

MID-POINT and BRESENHAM Circle Drawing Algorithm

// CIRCLE ALGORITHM

#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<process.h>

void midc(float r,float xc,float yc);
void bresc(float r,float xc,float yc);

int main()
{
	float xc,yc,x,y,p,r,m,n;
	int c;
	int gdriver = DETECT, gmode;
	initgraph(&gdriver, &gmode,"C:\\tc\\bgi");
	printf("\nEnter the radius of the circle\n");
	scanf("%f",&r);
	printf("\nEnter the centre of the circle\n");
	scanf("%f%f",&xc,&yc);

first:
	printf("\nOPTIONS \n1.MIDPOINT CIRCLE ALGORITHM \n2.BRESENHAM CIRCLE ALGORITHM \n3.EXIT");
	printf("\n Enter your choice:");
	scanf("%d",&c);
	switch(c)
	{
	case 1:
		midc(r,xc,yc);
		goto first;
	case 2:
		bresc(r,xc,yc);
		goto first;
	case 3:
		exit(0);
	}
	getch();
	return 0;
}
void midc(float r,float xc,float yc)
{
	float p,x,y,m,n;
	x=0;
	y=r;
	putpixel(xc+x,yc+y,2);
	putpixel(xc-x,yc+y,2);
	putpixel(xc+x,yc-y,2);
	putpixel(xc-x,yc-y,2);
	putpixel(xc+y,yc+x,2);
	putpixel(xc-y,yc+x,2);
	putpixel(xc+y,yc-x,2);
	putpixel(xc-y,yc-x,2);
	p=(5/4)-r;
	while(x<y)
	{
		if(p<0)
		{
			x=x+1;
			p=p+(2*x)+1;
		}
		else
		{
			x=x+1;
			y=y-1;
			m=(2*x)+2;
			n=(2*y)+2;
			p=p+m+1-n;
		}
		putpixel(xc+x,yc+y,2);
		putpixel(xc-x,yc+y,2);
		putpixel(xc+x,yc-y,2);
		putpixel(xc-x,yc-y,2);
		putpixel(xc+y,yc+x,2);
		putpixel(xc-y,yc+x,2);
		putpixel(xc+y,yc-x,2);
		putpixel(xc-y,yc-x,2);
	}
	getch();
}


void bresc(float r,float xc,float yc)
{
	float p,x,y;

	x=0;
	y=r;
	putpixel(xc+x,yc+y,2);
	putpixel(xc-x,yc+y,2);
	putpixel(xc+x,yc-y,2);
	putpixel(xc-x,yc-y,2);
	putpixel(xc+y,yc+x,2);
	putpixel(xc-y,yc+x,2);
	putpixel(xc+y,yc-x,2);
	putpixel(xc-y,yc-x,2);
	p=3-(2*r);
	while(x<y)
	{
		if(p<0)
		{
			x=x+1;
			p=p+(4*x)+6;
		}
		else
		{
			x=x+1;
			y=y-1;
			p=p+(4*x)-(4*y)+10;
		}
		putpixel(xc+x,yc+y,2);
		putpixel(xc-x,yc+y,2);
		putpixel(xc+x,yc-y,2);
		putpixel(xc-x,yc-y,2);
		putpixel(xc+y,yc+x,2);
		putpixel(xc-y,yc+x,2);
		putpixel(xc+y,yc-x,2);
		putpixel(xc-y,yc-x,2);
	}
	getch();
}

E – Book List

Line Drawing using DDA Algorithm

//Line Drawing using DDA Algorithm

#include<stdio.h>
#include<graphics.h>
#include<conio.h>
#include<stdlib.h>

int main()
{
	int i, start_x, start_y, end_x, end_y, steps, dx, dy;
	float x, y, x_incr, y_incr;

    //// init graphics driver Turbo C++
    //int driver = DETECT, mode = DETECT;
	//initgraph(&driver, &mode, "C:\TC\BGI");
	
	// init graphics driver Dev C++
	initwindow(640, 400, "My Window");

	//getting cords from user
	printf("Enter the Start cords (x and y): ");
	scanf("%d%d", &start_x, &start_y);
	
	printf("Enter the End cords (x and y): ");
	scanf("%d%d", &end_x, &end_y);

	//setting up drawing parameters
	dx = end_x - start_x;
	dy = end_y - start_y;
	if(dx>dy)
		steps=dx;
	else
		steps=dy;

	x_incr = (float)dx/steps;
	y_incr = (float)dy/steps;

	printf("Parameters are\ns_x : %d\ns_y : %d\ne_x : %d\ne_y : %d\ndx : %d\ndy : %d\nsteps : %d\nx_i : %f\ny_i : %f\n", start_x, start_y, end_x, end_y, dx, dy, steps, x_incr, y_incr);
	printf("press any key to draw line\n");
	
	system( "cls");

	//drawing line
	x=start_x;
	y=start_y;
	for(i=0; i<=steps; i++)
	{
		putpixel((int)x, (int)y, 15);
		x += x_incr;
		y += y_incr;
	}
	
	getch();

	//closing driver
	closegraph();
	return 0;
}

Non Deterministic Finite Automata

The same program can be used for DFA.

Read the rest of this entry

Macro Intergrated Assembler

This is simply the combination of 2-Pass assembler and a Macro Processor .

Read the rest of this entry

Macro Processor

SIC Macro Processor. Output is included.

Read the rest of this entry

Relocating Loader

Free memory list is hard coded & first fit free block is selected

Read the rest of this entry

Assembler with relocating option

Two operand instruction are not considered. Sample output is included in the program.

Read the rest of this entry

Absolute loader

Sample output is included in the program. Program name and size validation are not done.

Read the rest of this entry