Lucrare de Curs La SDA
Lucrare de Curs La SDA
Lucrare de Curs La SDA
Colun Mihail
gr. FAF-081
Introduction
Basics element of an digital image is the pixel with
specific coordinate and color,in C++ we have build in
graphic driver of resolution 640x480 pixels(total
307300 ) of different 16 colors build in C
Each quantity of
color can takes
values from 0 to
255.Totally we have
2563 colors
(16.777.216)
Coordinates in C graph
The coordinates in graph are
quite different from
standard, the origin of
coordinates system is placed
in the top left corner and
the positive direction of Y is
down. The visible values of
X is from 0 to 639,and for Y
from 0 to 479,it can take also
values out of this set but
they will not be visible in our
interface.
Basic functions
Putpixel(x,y,color) function that draw a pixel on the screen
with x, y coordinates and specified c color.
setcolor(c) - set the current drawing color in graph.
12
13
14
15
10
11
setrgbpalette(pal.colors[c], r,g ,b )
C is the number of color. Do not forget that our driver supports
only 16 colors.
Line(x1, y1, x2, y2) - where (x1,y1) are the coordinates of first
point and (x2,y2) are the coordinates of second point, by this way
we construct a segment that contains the endpoints in specified
points.
Note: Polygons can be represented as combinations of 3 or more lines
with the same endpoints.
Rectangle(x1, y1, x2, y2) - where the (x1, y1) are the coordinates
of first corner and the (x2, y2)the coordinates of second corner, by
this way we draw an rectangle that contains 2 specified points as
corners, the other to corners are drawn automatically.
bar(x1, y1, x2, y2) - draws a rectangle and automatically floodfill it.
bar3d(x1, y1, x2, y2, d, t) - draws a 3d bar in 2d where d is the
depth of bar and t is the govern whether a three-dimensional top
is put on the bar.
arc(x, y, a1, a2, r) - draws a curve line which has the center point in (x, y) and
the startangle a1 and the endangle a2 with radius r.
outtext () - draw the specified text on the screen on the current position
like on the output screen.
outtextxy(x, y, s) - draw a text in the specified coordinates where (x, y) are the
top left corner of the text, and s is the string that is going to be output on the
screen.
getpixel(x,y) - this function return the number of color in a specific point(x, y).
Useful functions
kbhit() - function that returns 1 if the a key is pressed
on the keyboard and 0 if not.
Circles on diagonal
In the next example we will draw some circle along the
diagonal of the screen and flood them with all colors from
our driver, also write near the circle the respectively color .
while((y<=480)&&(x<=640))
{
circle(x,y,14);
setfillstyle(1,a);
floodfill(x,y,2);
itoa(a,s,10);
outtextxy(x+17,y-5,s);
a++;
x=x+40;
y=y+30;
}
Moving Triangle 1
We will draw a triangle which will be moving on an ellipse orbit until a key
is pressed.
Also we will draw the ellipse orbit to feel that.
What we should mention hear that the main variable will be the angle a of
float type,
The xRadius will be 200 pixels and yRadius will be of 100 pixels, the initial
value for a is 0, also on variation of a depends the speed and direction of
rotation for triangle; if its negative it will rotate contra clock wise direction
and positive otherwise. The increment for a will be -0.1 rad.
First of all we must draw a triangle with the middle in the center of the
screen (320, 240) of length 50 pixels.
size=imagesize (295,212,345,254);
img=malloc(size);
getimage (295,212, 345,254 ,img);
putimage (295,212, img ,1);
Pseudo-3D function
In this program I will try to represent a graph
in 3 dimensions. Actually it will be 2
dimensional, but the difference of colors will
create to us an illusion of 3 dimensional space.
Basic theory here is the formula of converting
a 3D point to 2D and made this point of
different color.
Conclusion
Graph library contains useful things; by composing
logical algorithms of these functions we can create
many interesting images, animations, functions
graphic and more complicated games.