Posts

POLYGON CLIPPING PROGRAM IN C | SUTHERLAND HODGEMAN ALGORITHM FOR POLYGON CLIPPING

Image
POLYGON CLIPPING PROGRAM IN C | SUTHERLAND - HODGEMAN ALGORITHM FOR POLYGON CLIPPING In computer graphics, we have to study the Sutherland - Hodgeman polygon clipping algorithm. The algorithm according to the book by A. P. Godse is as follows:  Algorithm:-        Step 1- Read coordinates of all the vertices of polygon        Step 2- Read coordinates of the clipping window        Step 3- Consider the left edge of window        Step 4- Compare the vertices of each edge of the                                polygon , individually with clipping plane.        Step 5-Save the resulting intersections and vertices in                         the new list of vertices according to four possible                     relationships between the edge and the clipping                     boundary discussed earlier.        Step 6- Repeat the steps 4 and 5 for remaining edges of                     the clipping window. Each time the resultant list                       of the vertic

Prime String concept and program in Java - Explained

Image
Prime Strings: You must have heard about prime numbers. But have you ever thought about prime string?   It's very simple and interesting. Here's the explanation:-  In computer science, string is sequence of characters.Characters may be alphabets, numbers, punctuation, or special symbols. So any word is a string. for example: "Hello" is a string. Now, what is prime string? A string which cannot be constructed by concatenating two or more than two(multiple) equal strings. Let's have a string "Road" , when we divide "road" into two equal parts we get "ro" and "ad" which are not equal strings. Thus "road" is a prime string . Now let's take a string "baba". By dividing this string into two equal parts we get "ba" and "ba" . Both these strings are equal. So it is not a prime string. Here's a prime string program written in java. It also tells the first h

Floyd's triangle and reverse Floyd's triangle in java

Image
Hello friends, Let's see what is Floyd's triangle! The concept of Floyd's Triangle  was invented by the computer scientist Robert Floyd. Floyd's Triangle is a right angled triangle filled by natural numbers, which is having n rows. In this triangle nth row will have n natural numbers. So in the first row there will  be only 1 element, that is, 1, in the second row there will be 2 elements next to one, 2 and 3, in third row there will be 3 elements 4,5 and 6. In this way the triangle so formed is called Floyd's Triangle. 1 2 3 4 5 6 7 8 9 10 This is the Floyd's Triangle having 4 rows. Reverse Floyd's Triangle:- Now let us see what is Reverse Floyd's Triangle. It is simply reverse of Floyd's Triangle. The natural numbers are written from end to start. For example, the Reverse Floyd's Triangle for 4 rows will be: 10 9 8 7 6 5 4 3 2 1 This is the Reverse Floyd's Triangle having 4 rows. Here's a program to print Floyd&#

Happy Number

Image
Guys , I'm back with a new program and it is also in C language.  So get ready to find your lucky number now..😃 Happy Number..           Doesn't it seem interesting.. 😉           Yeah off course it is..!            What is a happy number. If the repeated sum of digits of  any number is ' 1 ', then it is considered to be a happy.. And if it is not then it is sad number.           Also when the sum of  digits of a number becomes 4..we cannot get '1' as a result because it requires so many iterations and we remain messed up into an infinite loop.., so if sum of digits is 4 then it is also a sad number.            Let's take an example.Suppose we have a number 19.  19 -> 1 and 9  1^2 + 9^2 = 82 again, 82 -> 8 and 2 8^2 + 2^2 = 68 again, 68-> 6 and 8 6^2 + 8 ^2 = 100 again, 100 -> 1 0 and 0 1^2 + 0^2 + 0 ^2 = 1 Yeeh..we got 1. Thus the number 19 is a happy number .😄 So which one is the sad numb

Traffic Signal Simulator in C graphics

Image
Hey Guys..              I'm back with a new program and guess what? It's also in C .            I have built a program of Traffic Signal Simulator using Graphics. It simply shows a simulation of traffic signal like red,yellow and green lights lighting after regular intervals. Here you go ---> #include<conio.h> #include<graphics.h> #include<stdlib.h> #include<dos.h> int main() { int gd,gm,midx,midy; detectgraph(&gd,&gm); initgraph(&gd,&gm,"c:\\turboc3\\bgi");//initialize graphics midx=getmaxx()/2;//midpoint of x axis // midy=getmaxy()/2;midpoint of y axis settextstyle(0,HORIZ_DIR,2); outtextxy(150,50,"TRAFFIC SIGNAL SIMULATOR"); setcolor(WHITE); rectangle(midx-40,100,midx+40,320); rectangle(midx-15,320,midx+15,480); floodfill(midx-14,321,WHITE); circle(midx,140,30); circle(midx,210,30); circle(midx,280,30); while(!kbhit()) { //RED color

Let's begin with beginning..Shortest path program in c Graphics

Image
Helloow friends..     We all think, graphics in c is quite complicated.. but only in the beginning .Once you have kept your hands on it..practice more and more and graphics will be your cup of tea..  Here's a program for finding shortest route among cities using graphics:          I keep posting such interesting new programs.. Follow our blog for more. #include<graphics.h> #include<conio.h> #include<stdio.h> #include<string.h>  void        dennix(); void denmia(); void denaus(); void        miaatl(); void ausmia(); void ausatl(); void auston(); void auschi(); void phoaus(); void bosatl(); void bostle(); void boschi(); void phochi(); void chitle(); void          atlsea(); void citynode(int x,int y) { setcolor(WHITE); circle(x,y,5); setfillstyle(SOLID_FILL,GREEN); floodfill(x,y,WHITE); } void map() { settextstyle(0,HORIZ_DIR,1); citynode(160,120); setcolor(14);