Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

TUGAS GRAFIKA KOMPUTER

KURVA C, DRAGON, DAN SIEPERNZKI

Oleh :

Dinar Rani P. (0710960023)


Khori Widayanti (0710963019)
Ade Yuanita Anggraini (0710963049)

PROGRAM STUDI ILMU KOMPUTER


JURUSAN MATEMATIKA
FAKULTAS MATEMATIKA DAN ILMI PENGETAHUAN
ALAM
UNIVERSITAS BRAWIJAYA
2009
Source Code
No. Unit1
1 unit Unit1;
2
3 interface
4
5 uses
6 Windows, Messages, SysUtils, Classes, Graphics, Controls,
7 Forms, Dialogs,
8 OpenGL, StdCtrls, ExtCtrls, Buttons,UKurva, Menus;
9
10 type
11 TForm1 = class(TForm)
12 PanelDraw: TPanel;
13 Button1: TButton;
14 Button2: TButton;
15 BitBtn1: TBitBtn;
16 procedure FormDestroy(Sender: TObject);
17 procedure FormCreate(Sender: TObject);
18 procedure Button1Click(Sender: TObject);
19 procedure Button2Click(Sender: TObject);
20
21 private
22 GLContext: HGLRC;
23 glDC: HDC;
24 errorCode: GLenum;
25 procedure ExceptionGL (Sender: TObject; E:Exception);
26 end;
27
28 var
29 Form1: TForm1;
30 h_Wnd : HWND;
31 h_DC : HDC;
32 h_RC : HGLRC;
33
34 implementation
35 uses
36 Palets, FComplex, Complex;
37
38 var
39 Parameter : TParCmpFrt;
40 Palet : TPalet;
41
42 {$R *.dfm}
43
44 function PrepareOpenGL (aHandle: THandle;
45 var GLContext: HGLRC;
46 var glDC: HDC) : boolean;
47
48 var
49 pfd: TPixelFormatDescriptor;
50 FormatIndex: integer;
51 begin
52 Result := false;
53 FillChar (pfd, SizeOf(pfd), 0);
54 with pfd do
55 begin
56 nSize := SizeOf(TPIXELFORMATDESCRIPTOR);
57 nVersion := 1;
58 dwFlags := PFD_DRAW_TO_WINDOW
59 or PFD_SUPPORT_OPENGL;
60 iPixelType := PFD_TYPE_RGBA;
61 cRedBits := 0;
62 cRedShift := 0;
63 cGreenBits := 0;
64 cGreenShift := 0;
65 cBlueBits := 0;
66 cBlueShift := 0;
67 cAlphaBits := 0;
68 cAlphaShift := 0;
69 cAccumBits := 0;
70 cAccumRedBits := 0;
71 cAccumGreenBits := 0;
72 cAccumBlueBits := 0;
73 cAccumAlphaBits := 0;
74 cDepthBits := 16;
75 cStencilBits := 0;
76 cAuxBuffers := 0;
77 iLayerType := PFD_MAIN_PLANE;
78 bReserved := 0;
79 dwLayerMask := 0;
80 dwVisibleMask := 0;
81 dwDamageMask := 0;
82 end;
83
84 glDC := getDC (aHandle);
85 FormatIndex := ChoosePixelFormat (glDC, @pfd);
86 if FormatIndex=0 then
87 raise Exception.Create ('ChoosePixelFormat failed
88 '+IntToStr (GetLastError));
89
90 if not SetPixelFormat (glDC, FormatIndex, @pfd) then
91 raise Exception.Create ('SetPixelFormat failed '+IntToStr
92 (GetLastError));
93
94 GLContext := wglCreateContext (glDC);
95 if GLContext=0 then
96 raise Exception.Create ('wglCreateContext failed
97 '+IntToStr (GetLastError));
98
99 if not wglMakeCurrent (glDC, GLContext) then
100 raise Exception.Create ('wglMakeCurrent failed '+IntToStr
101 (GetLastError));
102 Result := true;
103 end;
104
105 procedure TForm1.FormDestroy(Sender: TObject);
106 begin
107 wglMakeCurrent (Canvas.Handle, 0);
108 wglDeleteContext (GLContext);
109 end;
110
111
112 procedure TForm1.ExceptionGL (Sender: TObject; E:Exception);
113 begin
114 ShowException (Sender, E);
115 repeat
116 errorCode := glGetError;
117 if errorCode<>GL_NO_ERROR then
118 ShowMessage (gluErrorString(errorCode));
119 until errorCode=GL_NO_ERROR;
120 end;
121
122 procedure TForm1.FormCreate(Sender: TObject);
123 begin
124 randomize;
125 Application.OnException := ExceptionGL;
126 PrepareOpenGL (PanelDraw.handle, GLContext, glDC);
127
128 if (Height = 0) then
129 Height := 1;
130 glMatrixMode(GL_PROJECTION);
131 glLoadIdentity();
132 gluPerspective(45.0, PanelDraw.Width/PanelDraw.Height, 1.0,
133 100.0);
134 glMatrixMode(GL_MODELVIEW);
135 glLoadIdentity();
136 glClearColor(0.0, 0.0, 0.0, 1.0);
137 glColor3f(1.0, 1.0, 1.0);
138 glClear(GL_COLOR_BUFFER_BIT);
139 glColor3f(1.0, 1.0, 1.0);
140 glViewport(0, 0, PanelDraw.Width, PanelDraw.Height);
141 glMatrixMode(GL_PROJECTION);
142 glLoadIdentity();
143 if (PanelDraw.Width <= PanelDraw.Height) then
144 glOrtho (-1.0, 1.0,
145 -1.0*PanelDraw.Height/PanelDraw.Width,
146 1.0*PanelDraw.Height/PanelDraw.Width, -1.0, 1.0)
147 else
148 glOrtho (-1.0*PanelDraw.Width/PanelDraw.Height,
149 1.0*PanelDraw.Width/PanelDraw.Height, -1.0, 1.0,
150 -1.0, 1.0);
151 glShadeModel(GL_SMOOTH);
152 Palet := TPalet.Create (64);
153 Parameter.C := TComplex.Create (0,0);
154 end;
155
156 procedure Sierp(k:integer;h:integer;SN:SierpN;SA:SierpM);
157
158 begin
159 if k > 0 then
160 begin
161 Sierp(k - 1,SN.a1[h],SN,SA);
162 T.A:=SA[H,1];
163 // avanti;
164 Sierp(k - 1,SN.a2[h],SN,SA);
165 T.A:=SA[h,2];
166 T.P:=T.P/2;
167 //avanti;
168 T.P:=T.P*2;
169 Sierp(k - 1,SN.a3[h],SN,SA);
170 T.A :=SA[h,3];
171 //avanti;
172 Sierp(k - 1,SN.a4[h],SN,SA);
173 end;
174 end;
175
176 {procedura di assegnazione}
177 procedure SierpinskiBis(h:integer);
178 var
179 SN:SierpN;
180 SA:SierpM;
181
182 begin
183
184 {ordine di di orientamento}
185
186 SA[1,1]:=135;
187 SA[1,2]:=90;
188 SA[1,3]:=45;
189
190 SA[2,1]:=225;
191 SA[2,2]:=180;
192 SA[2,3]:=135;
193
194 SA[3,1]:=315;
195 SA[3,2]:=270;
196 SA[3,3]:=225;
197
198 SA[4,1]:=45;
199 SA[4,2]:=0;
200 SA[4,3]:=315;
201
202 {ordine di ripetizione}
203
204 SN.a1[1]:=1;
205 SN.a2[1]:=2;
206 SN.a3[1]:=4;
207 SN.a4[1]:=1;
208
209 SN.a1[2]:=2;
210 SN.a2[2]:=3;
211 SN.a3[2]:=1;
212 SN.a4[2]:=2;
213
214 SN.a1[3]:=3;
215 SN.a2[3]:=4;
216 SN.a3[3]:=2;
217 SN.a4[3]:=3;
218
219 SN.a1[4]:=4;
220 SN.a2[4]:=1;
221 SN.a3[4]:=3;
222 SN.a4[4]:=4;
223
224 {chiamata della ricorsione}
225 Sierp(h,4,SN,SA);
226 T.A:=(45);
227 // avanti;
228 Sierp(h,1,SN,SA);
229 T.A:=135;
230 // avanti;
231 Sierp(h,2,SN,SA);
232 T.A:= 225;
233 //avanti;
234 Sierp(h,3,SN,SA);
235 T.A:= 315;
236 //avanti;
237
238 end;
239
240 procedure TForm1.Button1Click(Sender: TObject);
241 begin
242 ClearScreen;
243 cp.x:= 0.2;
244 cp.y:= 0.0;
245 DrawC(90,0.8,20);
246 end;
247
248 procedure TForm1.Button2Click(Sender: TObject);
249 begin
250 ClearScreen;
251 glColor3f(0,0,0);
252 InitCp.x:=-0.5;
253 Initcp.y:= 0.0;
254 cp:=InitCP;
255 jum :=1;
256 t1[1]:=cp;
257 t2 :=t1;
258 Dragon(0,0.8,12);
259 end;
260
261 procedure TForm1.Button3Click(Sender: TObject);
262
263 begin
264 T.X:=150; T.Y:=50; T.P:=25;
265 end;
266
267 end.
OUTPUT

* Kurva C :

* Kurva Dragon :

You might also like