200 likes | 363 Views
GRAFIKA KOMPUTER. PRIMITIVE OUTPUT Hilman Fauzi TSP, ST. Pixel (Dot) Posisi ( x,y ), Warna Garis (Line) Posisi (x1,y1,x2,y2), Warna , Thickness, Pattern Lingkaran (Circle) Pusat ( x,y ), Radius, Warna , Thickness, Pattern
E N D
GRAFIKA KOMPUTER PRIMITIVE OUTPUTHilmanFauzi TSP, ST
Pixel (Dot) Posisi (x,y), Warna Garis (Line) Posisi (x1,y1,x2,y2), Warna, Thickness, Pattern Lingkaran (Circle) Pusat(x,y), Radius, Warna, Thickness, Pattern Ellipse Pusat(x,y), Radius Horisonal/Vertikal, Warna, Thickness, Pattern Kurva Teratur/Tidakteratur (Bezier) Character Type, Slanted, Thickness, Color, dll Primitive grafis
Titik (Pixel/Dot) • Pustaka Grafis (Library)BGI putpixel (x,y,color)OPENGL GL_Drawdot(x,y,color) • Low Level Programming- Interupt H/W, S/W- DMA (Direct Memory Access) Modus Text : B800:0000h Modus Grafis : A000:0000h
Titik (Pixel/Dot) void setpixel_DMA (x,y,color) { char *Segmen = 0xA0000000; (Segmen+(800*y+x)) = color; } procedure setpixel_DMA(x,y,color); begin mem[A000:(800*y+x)] := color; end;
Y2 Y1 X1 X2 GARIS (LINE)
Algoritma Pembuatan Garis • Algoritma pembuatan garis lurus vertikal dan horisontal relatif mudah, tetapi bila garis tersebut miring, maka algoritma menjadi sulit. • Misal : Line (1,3,8,5)
DDA (Digital Differential Analyser) Algorithm • Jika 0m1 yk+1 = yk+ m xk+1 = xk + 1 • Jika m>1 xk+1 = xk + 1/m yk+1 = yk + 1
Bresenham’s Algorithm Plot (Xo,Yo) Repeat If Pk<0 then Plot (Xk+1,Yk) Otherwise Plot (Xk+1,Yk+1) Until X=end
Bresenham’s Algorithm • Contoh : Line (20,10,30,18) X = 10, Y = 8 Po = 2Y - X = 6 2.Y = 16 2Y - 2X = -4
CIRCLE • Defined as the set of points that are all at given distance r from a center position (Xc,Yc), expressed : • Calculate the position of points stepping along x axis from (Xc-r) to (Xc+r) with :
CIRCLE - Problem • Considerable computation at each step • Spacing between plotted pixel is not uniform. • Example :
CIRCLE – cont. • Using polar coordinate approach : • Symmetric in octant calculating only sector from x=0 to x=y Equally Spaced points
Midpoint Circle Algorithm • (Xo,Yo)=(0,r); Plot (Xo,Yo) • P0 = 1 – r • Repeat If Pk<0 then X=X+1 Plot (X,Y) Pk+1 = Pk+2X+1 Otherwise X=X+1; Y=Y-1 Plot (X,Y) Pk+1 = Pk+2X– 2Y+1 • Until X Y
Midpoint Circle Algorithm – cont. • Example :
Ellipse • Set of points such as the sum of the distance from two pixed position (foci) is the same for all points. P(x,y) d1 d2 d1+d2 = constant F2 F1
Ellipse - cont • Polar : Reg.I ry rx Reg.II
Midpoint Ellipse Algorithm Region I : • (xo,yo)=(0,ry); Plot (xo,yo) • P0 = ry2 – rx2ry+1/4rx2 • Px = 0; Py=2rx2y • While Px<Py x=x+1 Px = Px + 2ry2 If P 0 y=y-1 Py = Py – 2rx2 Pk+1 = Pk+ry2+Px-Py Otherwise Pk+1 = Pk+ry2+Px Plot(x,y) Region II : • Plot (xo,yo) • P0 = ry2 (x+½ )2+rx2(y-1)– rx2ry2 • While y>0 y=y-1 Py = Py - 2rx2 If P 0 x=x+1 Px = Px + 2ry2 Pk+1 = Pk+rx2+Px-Py Otherwise Pk+1 = Pk+rx2-Py Plot(x,y)
Midpoint Ellipse Algorithm • Example : rx=8, ry=6 • Untuk Region I :
Midpoint Ellipse Algorithm • Untuk Region II :