REM ÇÀÄÀÍÈÅ ÊÎËÈ×ÅÑÒÂÀ ÃÐÀÍÅÉ È ÏÎÄÃÎÒÎÂÊÀ ÌÀÑÑÈÂÎÂ
12 ng%=7:DIM R_GRAN_COLOR(ng%):DIM G_GRAN_COLOR(ng%):DIM B_GRAN_COLOR(ng%):DIM zd_gr(ng%):DIM numgr(ng%)
14 n_plot%=4*ng%:DIM x_3d(n_plot%):DIM y_3d(n_plot%):DIM z_3d(n_plot%):DIM x_2d(n_plot%):DIM y_2d(n_plot%)
REM ÇÀÄÀÍÈÅ ÌÈÍÈÌÀËÜÍÎÉ È ÌÀÊÑÈÌÀËÜÍÎÉ ÃÐÀÍÈÖÛ ÃÐÀÍÈ 'y_3d_max' È ÄÀÍÍÛÕ ÃÐÀÍÈ
20 y_3d_max=100
21 y_3d_min=-y_3d_max
30 R_GRAN_COLOR(0)=255:G_GRAN_COLOR(0)=0:B_GRAN_COLOR(0)=0
31 x_3d(0)=-300:z_3d(0)=200
32 x_3d(1)=-180:z_3d(1)=200
33 R_GRAN_COLOR(1)=0:G_GRAN_COLOR(1)=255:B_GRAN_COLOR(1)=0
34 x_3d(4)=300:z_3d(4)=200
35 x_3d(5)=180:z_3d(5)=200
36 R_GRAN_COLOR(2)=255:G_GRAN_COLOR(2)=0:B_GRAN_COLOR(2)=0
37 x_3d(8)=-180:z_3d(8)=200
38 x_3d(9)=-100:z_3d(9)=250
39 R_GRAN_COLOR(3)=0:G_GRAN_COLOR(3)=255:B_GRAN_COLOR(3)=0
40 x_3d(12)=180:z_3d(12)=200
41 x_3d(13)=100:z_3d(13)=250
42 R_GRAN_COLOR(4)=255:G_GRAN_COLOR(4)=0:B_GRAN_COLOR(4)=0
43 x_3d(16)=-100:z_3d(16)=250
44 x_3d(17)=-100:z_3d(17)=500
45 R_GRAN_COLOR(5)=0:G_GRAN_COLOR(5)=255:B_GRAN_COLOR(5)=0
46 x_3d(20)=100:z_3d(20)=250
47 x_3d(21)=100:z_3d(21)=500
48 R_GRAN_COLOR(6)=0:G_GRAN_COLOR(6)=255:B_GRAN_COLOR(6)=0
49 x_3d(24)=-100:z_3d(24)=500
50 x_3d(25)=100:z_3d(25)=500
REM ÀÂÒÎÌÀÒÈ×ÅÑÊÎÅ ÄÏÎËÍÅÍÈÅ ÄÀÍÍÛÕ Î ÃÐÀÍÈ ÄËß 3D ENGINE
REM ÄÎÏÎËÍßÞÒÑß ÊÎÎÐÄÈÍÀÒÛ ÍÈÆÍÅÉ ÃÐÀÍÈÖÛ ÃÐÀÍÈ È ÑÎÇÄÀ¨ÒÑß ÌÀÑÑÈÂ 'y_3d'
990 sum_g=1
991 for t%=0 to ng%-1
992 x_3d(2*(t%+sum_g))=x_3d(4*t%):z_3d(2*(t%+sum_g))=z_3d(4*t%)
993 x_3d(2*(t%+sum_g)+1)=x_3d(4*t%+1):z_3d(2*(t%+sum_g)+1)=z_3d(4*t%+1)
994 y_3d(2*(t%+sum_g))=y_3d_min
995 y_3d(2*(t%+sum_g)+1)=y_3d_min
996 y_3d(2*(t%+sum_g)-2)=y_3d_max
997 y_3d(2*(t%+sum_g)-1)=y_3d_max
998 sum_g=sum_g+1
999 next t%


REM START 3D ENGINE
REM ÍÀÑÒÐÎÉÊÀ ÏÀÐÀÌÅÒÐÎÂ 3D ENGINE
1000 qualitet_map=36
1001 H_RECT_MAX=96
1002 Z_LIGHT=500
1003 Z3D_DREAM=-100
1004 X2D_LEFT_DREAM=50
1005 X2D_RIGHT_DREAM=190
1006 X_PERS_OS=0
1007 Z_PERS_OS=-100
1008 w_os=screenwidth(0)/2
1009 h_os=screenheight(0)/2
1010 ZOOM_X2D=0.3
1011 ZOOM_Y2D=0.3
1012 UGOL_A=0.174533
1013 Z3D_HOD=20
1014 RANG_GRAN=1


REM ÐÀÑ×ÅÒ ÊÎÎÐÄÈÍÀÒ ÏÐÈ ÏÎÂÎÐÎÒÀÕ È ÏÅÐÅÑ×ÅÒ Â 2Ä ÊÎÎÐÄÈÍÀÒÛ
1152 for t%=0 to n_plot%-1
1153 IF D_ALFA=0 THEN GOTO 1160
REM ÍÀÕÎÆÄÅÍÈÅ ÒÅÊÓÙÅÃÎ ÓÃËÀ ÒÎ×ÊÈ
1154 RL=SQR(((X_PERS_OS-x_3d(t%))^2)+((Z_PERS_OS-z_3d(t%))^2))
1155 ALFA=ACOS(((x_3d(t%)-X_PERS_OS)/RL)):IF z_3d(t%)<Z_PERS_OS then ALFA=-ALFA
REM ÏÎÂÎÐÎÒ ÒÎ×ÊÈ È ÏÅÐÅÑ×ÅÒ ÊÎÎÐÄÈÍÀÒÛ ÒÎ×ÊÈ ÏÎÄ ÍÎÂÛÌ ÓÃËÎÌ
1157 ALFA=ALFA+D_ALFA
1158 x_3d(t%)=X_PERS_OS+RL*COS(ALFA)
1159 z_3d(t%)=Z_PERS_OS+RL*SIN(ALFA)
REM ÏÅÐÅÂÎÄ 3Ä ÊÎÎÐÄÈÍÀÒ ÒÎ×ÊÈ Â 2Ä ÊÎÎÐÄÍÀÒÛ
1160 x_2d(t%)=w_os+x_3d(t%)*(16/(16+0.05*z_3d(t%)))*ZOOM_X2D
1161 y_2d(t%)=h_os-y_3d(t%)*(16/(16+0.05*z_3d(t%)))*ZOOM_Y2D
1162 next t%


REM ÐÀÑ×¨Ò ÏÎÐßÄÊÀ ÐÈÑÎÂÀÍÈß ÃÐÀÍÅÉ
REM ÐÀÑ×ÅÒ ÏÀÐÀÌÅÒÐÀ 'zd_gr' ÏÎ ÊÎÒÎÐÎÌÓ ÁÓÄÅÒ ÐÀÍÆÈÐÎÂÀÒÜÑß ÐßÄ
1166 for t%=0 to ng%-1
1167 zd_gr(t%)=(z_3d(4*t%)+z_3d(4*t%+1))/2:numgr(t%)=t%
1170 next t%
1171 IF RANG_GRAN=0 THEN GOTO 1184
REM ÈÑÏÎËÜÇÓÅÌ ÌÅÒÎÄ ÏÓÇÛÐÜÊÀ ÄËß ÐÀÍÆÈÐÎÂÀÍÈß ÐßÄÀ ÏÎ ÏÀÐÀÌÅÒÐÓ 'zd_gr'
1176 FOR t% = 2 TO ng%
1177 FOR t1% = 0 TO ng% - t%
1178 IF zd_gr(t1%)<zd_gr(t1%+1) THEN GOTO 1180
1179 GOTO 1182
REM ÐÅÀËÈÇÓÅÌ ÊÎÌÀÍÄÓ 'SWAP' ÈÇ ÎÁÛ×ÍÎÃÎ ÁÝÉÑÈÊÀ
1180 p=zd_gr(t1%):q=zd_gr(t1%+1):zd_gr(t1%)=q:zd_gr(t1%+1)=p
1181 p=numgr(t1%):q=numgr(t1%+1):numgr(t1%)=q:numgr(t1%+1)=p
1182 NEXT t1%
1183 NEXT t%


REM ÍÀÐÈÑÓÅÌ ÔÎÍ (ÄËß ÊÐÀÑÎÒÛ)
1184 CLS
1185 SETCOLOR 48,48,48
1186 FILLRECT X2D_LEFT_DREAM,h_os-(H_RECT_MAX/2),X2D_RIGHT_DREAM-X2D_LEFT_DREAM+1,H_RECT_MAX/2+1
1187 SETCOLOR 128,128,128
1188 FILLRECT X2D_LEFT_DREAM,h_os,X2D_RIGHT_DREAM-X2D_LEFT_DREAM+1,H_RECT_MAX/2+1

REM ÐÈÑÎÂÀÍÈÅ ÃÐÀÍÅÉ
1190 for tt%=0 to ng%-1
1191 IF zd_gr(tt%)<Z3D_DREAM THEN goto 2186
REM ÎÏÐÅÄÅËÅÍÈÅ ÂÕÎÄÍÛÕ ÏÀÐÀÌÅÒÐÎÂ ÄËß ÏÐÀÂÈËÜÍÎÃÎ ÂÛÐÈÑÎÂÛÂÀÍÈß ÃÐÀÍÅÉ
1192 nom%=4*numgr(tt%)
1510 dx=ABS(x_2d(nom%)-x_2d(nom%+1)):dy0=y_2d(nom%+2)-y_2d(nom%):dy1=y_2d(nom%+3)-y_2d(nom%+1):dy=ABS((dy0-dy1)/2)
1550 znak_y=1:if (dy0-dy1)<0 then znak_y=-1
1552 znak_x=1:k_x=0:if (x_2d(nom%+1)-x_2d(nom%))<0 then znak_x=-1:k_x=1
REM ÎÏÐÅÄÅËÅÍÈÅ ÊÎËÈ×ÅÑÒÂÀ È ØÈÐÈÍÛ ÏÐßÌÎÓÃÎËÜÍÈÊÎÂ Â ÃÐÀÍÈ
1600 w_gr%=(qualitet_map*dy/(dx+1)):if w_gr%>qualitet_map then w_gr%=qualitet_map
1602 if w_gr%<1 then w_gr%=1
2110 delta_y=dy/w_gr%:n_w=dx/w_gr%
REM ÎÏÐÅÄÅËÅÍÈÅ ÎÑÂÅÒËÅÍÍÎÑÒÈ ÃÐÀÍÈ
2111 K_LIGHT=1-(zd_gr(tt%)/Z_LIGHT):IF K_LIGHT<0 THEN K_LIGHT=0
2113 IF K_LIGHT>1 THEN K_LIGHT=1
2114 RR%=R_GRAN_COLOR(numgr(tt%))*K_LIGHT
2115 GG%=G_GRAN_COLOR(numgr(tt%))*K_LIGHT
2116 BB%=B_GRAN_COLOR(numgr(tt%))*K_LIGHT
2117 SETCOLOR RR%,GG%,BB%
REM ÖÈÊË ÂÛÐÈÑÎÂÛÂÀÍÈß ÃÐÀÍÈ
2130 h_scr=0
2131 for t%=0 to w_gr%-1
2132 xx=x_2d(nom%)+znak_x*n_w*(t%+1*k_x)
2133 if h_scr=1 then goto 2137
2134 yy=y_2d(nom%)+znak_y*delta_y*t%:hh=dy0-znak_y*delta_y*2*t%
2136 if hh>H_RECT_MAX and h_scr=0 and znak_y=-1 then h_scr=1
2137 IF xx+n_w<X2D_LEFT_DREAM OR xx>X2D_RIGHT_DREAM then goto 2160
2150 fillrect xx,yy,n_w+1,hh
2160 next t%
2186 next tt%


REM ÐÈÑÓÅÌ ÐÀÌÊÓ, ÊÎÒÎÐÀß ÎÁÎÇÍÀ×ÀÅÒ ÃÐÀÍÈÖÛ ÐÈÑÎÂÀÍÈß (ÄËß ÓÄÎÁÑÒÂÀ)
2187 SETCOLOR 0,0,0
2188 drawrect X2D_LEFT_DREAM-1,h_os-1-(H_RECT_MAX/2),X2D_RIGHT_DREAM-X2D_LEFT_DREAM+2,H_RECT_MAX+2
2189 repaint


REM ÓÏÐÀÂËÅÍÈÅ
2190 D_ALFA=0
2191 if left(0) then D_ALFA=-UGOL_A
2192 if RIGHT(0) then D_ALFA=UGOL_A
2193 IF UP(0) THEN GOTO 3000
2194 IF DOWN(0) THEN GOTO 3010
2196 GOTO 1152
REM ÏÎÄÏÓÍÊÒÛ ÓÏÐÀÂËÅÍÈß
3000 FOR T%=0 TO N_PLOT%-1
3001 z_3d(t%)=z_3d(t%)-Z3D_HOD
3002 next t%
3003 goto 1152
3010 FOR T%=0 TO N_PLOT%-1
3011 z_3d(t%)=z_3d(t%)+Z3D_HOD
3012 next t%
3013 goto 1152