Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
G
graphics_in_c
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Sankkara Narayanan
graphics_in_c
Commits
fb20ee8b
Commit
fb20ee8b
authored
7 years ago
by
opgrsankkar
Browse files
Options
Downloads
Patches
Plain Diff
Basic Fan
parent
d176b4e1
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
fan.c
+97
-0
97 additions, 0 deletions
fan.c
with
97 additions
and
0 deletions
fan.c
0 → 100644
+
97
−
0
View file @
fb20ee8b
/**
* rotating fan
*/
#include
<graphics.h>
#include
<stdlib.h>
#include
<stdio.h>
#include
<math.h>
double
rotatex
(
double
x
,
double
y
,
double
angle
,
double
pivotx
,
double
pivoty
){
return
(
x
)
*
cos
(
angle
)
-
(
y
)
*
sin
(
angle
)
+
pivotx
*
(
1
-
cos
(
angle
))
+
pivoty
*
(
sin
(
angle
));
// return (x - pivotx)*cos(angle) - (y - pivoty)*sin(angle) + pivotx;
}
double
rotatey
(
double
x
,
double
y
,
double
angle
,
double
pivotx
,
double
pivoty
){
return
(
x
)
*
sin
(
angle
)
+
(
y
)
*
cos
(
angle
)
+
pivoty
*
(
1
-
cos
(
angle
))
-
pivotx
*
(
sin
(
angle
));
// return (x - pivotx)*sin(angle) - (y - pivoty)*cos(angle) + pivoty;
}
int
kbhit
()
{
struct
timeval
tv
;
fd_set
fds
;
tv
.
tv_sec
=
0
;
tv
.
tv_usec
=
0
;
FD_ZERO
(
&
fds
);
FD_SET
(
STDIN_FILENO
,
&
fds
);
//STDIN_FILENO is 0
select
(
STDIN_FILENO
+
1
,
&
fds
,
NULL
,
NULL
,
&
tv
);
return
FD_ISSET
(
STDIN_FILENO
,
&
fds
);
}
int
main
()
{
/* request autodetection */
int
gdriver
=
DETECT
,
gmode
,
errorcode
;
/* Local Variables */
double
cx
,
cy
;
double
l1x1
,
l1y1
,
l1x2
,
l1y2
;
double
l1angle
=
120
/
180
.
0
*
3
.
14
;
double
l2angle
=
240
/
180
.
0
*
3
.
14
;
double
rotate_angle
=
2
/
180
.
0
*
3
.
14
;
int
speed
=
1
;
int
i
=
0
;
/* initialize graphics and local variables */
initgraph
(
&
gdriver
,
&
gmode
,
""
);
cx
=
getmaxx
()
/
2
;
cy
=
getmaxy
()
/
2
;
l1x1
=
cx
;
l1y1
=
cy
-
20
;
l1x2
=
cx
;
l1y2
=
cy
-
90
;
while
(
!
kbhit
())
{
i
++
;
if
(
i
>=
60
){
l1x1
=
cx
;
l1y1
=
cy
-
20
;
l1x2
=
cx
;
l1y2
=
cy
-
90
;
i
=
0
;
}
circle
((
int
)
cx
,
(
int
)
cy
,
20
);
line
((
int
)
l1x1
,
(
int
)
l1y1
,
(
int
)
l1x2
,(
int
)
l1y2
);
line
(
(
int
)
rotatex
(
l1x1
,
l1y1
,
l1angle
,
cx
,
cy
),
(
int
)
rotatey
(
l1x1
,
l1y1
,
l1angle
,
cx
,
cy
),
(
int
)
rotatex
(
l1x2
,
l1y2
,
l1angle
,
cx
,
cy
),
(
int
)
rotatey
(
l1x2
,
l1y2
,
l1angle
,
cx
,
cy
)
);
line
(
(
int
)
rotatex
(
l1x1
,
l1y1
,
l2angle
,
cx
,
cy
),
(
int
)
rotatey
(
l1x1
,
l1y1
,
l2angle
,
cx
,
cy
),
(
int
)
rotatex
(
l1x2
,
l1y2
,
l2angle
,
cx
,
cy
),
(
int
)
rotatey
(
l1x2
,
l1y2
,
l2angle
,
cx
,
cy
)
);
/* prepare for next frame */
delay
(
15
);
cleardevice
();
l1x1
=
rotatex
(
l1x1
,
l1y1
,
rotate_angle
,
cx
,
cy
);
l1y1
=
rotatey
(
l1x1
,
l1y1
,
rotate_angle
,
cx
,
cy
);
l1x2
=
rotatex
(
l1x2
,
l1y2
,
rotate_angle
,
cx
,
cy
);
l1y2
=
rotatey
(
l1x2
,
l1y2
,
rotate_angle
,
cx
,
cy
);
}
/* clean up */
closegraph
();
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment