Pendulum

On October 21, 2008, in Animation, Drawing, by , Views : 24286


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include<graphics.h> 
#include<conio.h> 
#include<dos.h> 
#include<process.h> 
 
int cx=300,cy=100,r=300; 
int x=0,y,p; 
 
int path(int dtn) 
{ 
    int x1,y1; 
    setcolor(15); 
    if(x>=y) 
    { 
        return 0; 
    } 
    cleardevice(); 
 
    if(dtn==1) 
    { 
        circle(cx+x,cy+y,20); 
        line(cx,cy,cx+x,cy+y); 
    } 
    else 
    { 
        circle(cx-x,cy+y,20); 
        line(cx,cy,cx-x,cy+y); 
    } 
    delay(10); 
    if(kbhit()) 
        exit(0); 
    x++; 
    if(p<0) 
        p+=2*x+1; 
    else 
    { 
        y--; 
        p+=2*(x-y)+1; 
    } 
    x1=x; 
    y1=y; 
    path(dtn); 
 
    cleardevice(); 
    if(dtn==1) 
    { 
        circle(cx+x1,cy+y1,20); 
        line(cx,cy,cx+x1,cy+y1); 
    } 
    else 
    { 
        circle(cx-x1,cy+y1,20); 
        line(cx,cy,cx-x1,cy+y1); 
    } 
    delay(10); 
    if(kbhit()) 
        exit(0);
    return(0);
} 
 
void main() 
{ 
    int gd=DETECT,gm=DETECT; 
    initgraph(&gd,&gm,""); 
    cleardevice(); 
    putpixel(300,100,4); 
    while(1) 
    { 
        x=0; 
        y=r; 
        p=1-r; 
        path(1); 
        x=0; 
        y=r; 
        p=1-r; 
        path(0); 
    } 
}

Download the code using the below link:

Please 'Like' or '+1' us to get the download link! (If you have already liked us on facebook, then like us either on G+ or twitter)



Hope, it helps! 🙂



3 Responses to Pendulum

  1. plzz tel me the coding to show the ticking the clock or minutes hand moving in a clock..

  2. zaheer says:

    plz help me, i need a program of two balls are moving and when they collide,they become fours balls

Leave a Reply

Your email address will not be published. Required fields are marked *


*

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

  • Dipin Krishna

Archives

All entries, chronologically...

Read more:
Scaling_Scaled_Figure
2D Transformations: Scaling

kite
Flying Kite

Animated Road
A Simple Animation of a Road

MinMaxClose