Lampiran Script Chaos Game
B. Lampiran Script Chaos Game
[x,y]=ginput; hold on plot(x,y, 'r.' , 'markersize' ,20); set(handles.axes1, 'XLim' ,[0 10], 'YLim' ,[0 10], 'xtick' ,[0:10], 'ytick' ,[0:10]); TS=[x y]; [m n]=size(TS); for i=1:m-1
rownames(i)={[ 'T' num2str(i-1)]}; data(i)=0;
end set(handles.uitable3, 'data' ,data, 'columneditable' ,true, 'visible' , 'on' , 'rowname' , '%' , 'columnname' , rownames); set(handles.figure1, 'Userdata' ,[x y]);
clc pers=get(handles.uitable3, 'data' ); pjg=length(pers); data=get(handles.figure1, 'Userdata' ); imax=str2double(get(handles.edit1, 'string' )); for i=1:pjg
mt(i)=(pers(i)/100)*imax; end randomt=randperm(imax); ind=0; ra=zeros(1,imax); for i=1:pjg
for j=1:mt(i) ind=ind+1; ra(randomt(ind))=i;
end end set(handles.axes1, 'NextPlot' , 'replace' );
set(handles.figure1, 'CurrentAxes' ,handles.axes1); [m n]=size(data); if m-1==3
t1=data(1,:); t2=data(2,:); t3=data(3,:); ack=data(4,:);
set(handles.axes1, 'NextPlot' , 'replace' ); set(handles.figure1, 'CurrentAxes' ,handles.axes1); plot([t1(1) t2(1)], [t1(2) t2(2)], 'y' , 'linewidth' ,2); set(handles.axes1, 'Color' ,[0.941 0.941 0.941], 'XColor' ,[0 0 0], 'YColor' ,[0 0 0], 'NextPlot' , 'add' ); plot(ack(1),ack(2), 'o' , 'markerfacecolor' , 'c' , 'markeredgecolor' , 'k' , 'markersize' ,8) a1=sprintf( ' %10.3f' ,ack(1)); a2=sprintf( ' %10.3f' ,ack(2)); matacak(1,:)={a1,a2}; a3(1)={ ' -' }; rownames(1)={ 'A0' };
set(handles.axes1, 'XLim' ,[0 10], ... 'YLim' ,[0 10], 'xgrid' , 'on' , 'ygrid' , 'on' );
tgh1=(t3(1)+t2(1))/2; tgh2=(t3(2)+t2(2))/2; tgh3=(t3(1)+t1(1))/2; tgh4=(t3(2)+t1(2))/2; tgh6=(t1(1)+t2(1))/2; tgh7=(t1(2)+t2(2))/2;
a= 'g.' ; b= 'b.' ; c= 'r.' ; d= 'k.' ; tanda=0; for i=1:imax
tp=ra(i); batas1=grs(ack(1),t1(1),t2(1),t1(2),t2(2)); batas2=grs(ack(1),t1(1),t3(1),t1(2),t3(2)); batas3=grs(ack(1),t2(1),t3(1),t2(2),t3(2));
if (ack(2)<=batas1)&& (ack(2)<=batas3) && (ack(2)>=batas2) && (tanda==0) waktu=tic; tanda=1; plot(ack(1),ack(2), 'o' , 'markerfacecolor' , 'm' , 'markeredgecolor' , 'k' , 'markersize' ,8)
end ok=grs(ack(1),tgh1,tgh3,tgh2,tgh4);
oi=grs(ack(1),t3(1),tgh1,t3(2),tgh2); oy=grs(ack(1),tgh3,t3(1),tgh4,t3(2)); ok2=grs(ack(1),tgh3,tgh6,tgh4,tgh7); oi2=grs(ack(1),t1(1),tgh6,t1(2),tgh7); oy2=grs(ack(1),t1(1),tgh3,t1(2),tgh4); ok3=grs(ack(1),tgh6,tgh1,tgh7,tgh2); oi3=grs(ack(1),t2(1),tgh6,t2(2),tgh7); oi4=grs(ack(1),t2(1),tgh1,t2(2),tgh2);
if tp==1 tplh=t1; if (ack(2)<=ok)&& (ack(2)<=oi) && (ack(2)>=oy) x=(tplh(1)+ack(1))/2; y=(tplh(2)+ack(2))/2; ack=[x y]; plot(ack(1),ack(2),a)
elseif (ack(2)<=ok2) && (ack(2)<=oi2) && (ack(2)>=oy2) x=(tplh(1)+ack(1))/2; y=(tplh(2)+ack(2))/2; ack=[x y]; plot(ack(1),ack(2),b)
elseif (ack(2)>=ok3) && (ack(2)<=oi3) && (ack(2)<=oi4) x=(tplh(1)+ack(1))/2; y=(tplh(2)+ack(2))/2; ack=[x y]; plot(ack(1),ack(2),c)
else x=(tplh(1)+ack(1))/2; y=(tplh(2)+ack(2))/2; ack=[x y]; plot(ack(1),ack(2),d)
end elseif tp==2 tplh=t2; if (ack(2)<=ok)&& (ack(2)<=oi) && (ack(2)>=oy) x=(tplh(1)+ack(1))/2; y=(tplh(2)+ack(2))/2; ack=[x y]; plot(ack(1),ack(2),a)
elseif (ack(2)<=ok2) && (ack(2)<=oi2) && (ack(2)>=oy2) x=(tplh(1)+ack(1))/2; y=(tplh(2)+ack(2))/2; ack=[x y]; plot(ack(1),ack(2),b)
elseif (ack(2)>=ok3) && (ack(2)<=oi3) && (ack(2)<=oi4) x=(tplh(1)+ack(1))/2; y=(tplh(2)+ack(2))/2;
ack=[x y]; plot(ack(1),ack(2),c)
else x=(tplh(1)+ack(1))/2; y=(tplh(2)+ack(2))/2; ack=[x y]; plot(ack(1),ack(2),d)
end elseif tp==3 tplh=t3; if (ack(2)<=ok) && (ack(2)<=oi) && (ack(2)>=oy) x=(tplh(1)+ack(1))/2; y=(tplh(2)+ack(2))/2; ack=[x y]; plot(ack(1),ack(2),a)
elseif (ack(2)<=ok2) && (ack(2)<=oi2) && (ack(2)>=oy2) x=(tplh(1)+ack(1))/2; y=(tplh(2)+ack(2))/2; ack=[x y]; plot(ack(1),ack(2),b)
elseif (ack(2)>=ok3) && (ack(2)<=oi3) && (ack(2)<=oi4) x=(tplh(1)+ack(1))/2; y=(tplh(2)+ack(2))/2; ack=[x y]; plot(ack(1),ack(2),c)
else x=(tplh(1)+ack(1))/2; y=(tplh(2)+ack(2))/2; ack=[x y]; plot(ack(1),ack(2),d)
end end a1=sprintf( ' %10.3f' ,ack(1)); a2=sprintf( ' %10.3f' ,ack(2)); a3(i+1)={[ ' T' num2str(tp-1)]}; sgtga(i)={[ ' ' num2str(tanda)]}; matacak(i+1,:)={a1,a2}; rownames(i+1)={[ 'A' num2str(i)]};
end waktu=toc(waktu); sgtga(i+1)={[ ' ' num2str(tanda)]}; set(handles.uitable2, 'data' ,[matacak a3' sgtga'], 'rowname' ,rownames, 'columnname' , ...
'x' { , 'y' , 'Titik Terpilih' , 'Segitiga' }, 'rowstriping' , 'on' ); set(handles.text5, 'string' ,waktu); wrna={ ' Biru' , ' Merah' , ' Hijau' , ' Ciyan' }; for i=1:m-1
a4=sprintf( ' %10.3f' ,data(i,1)); a5=sprintf( ' %10.3f' ,data(i,2)); a6(i)=wrna(i); matdata(i,:)={a4,a5}; rname(i)={[ 'T' num2str(i-1)]}; plot(data(i,1),data(i,2), 'o' , 'markeredgecolor' , 'r' , 'markerfacecolor' , 'y' , 'markersize' ,7);
end set(handles.uitable1, 'data' ,[matdata a6'], 'rowname' ,rname, 'columnname' ,{ 'x' , 'y' , 'Warna' }) plot([t1(1) t2(1)], [t1(2) t2(2)], 'k' , 'linewidth' ,3); plot([t2(1) t3(1)],[t2(2) t3(2)], 'k' , 'linewidth' ,3); plot([t1(1) t3(1)],[t1(2) t3(2)], 'k' , 'linewidth' ,3); plot(t1(1),t1(2), 'o' , 'markeredgecolor' , 'r' , 'markerfacecolor' , 'y' , 'markersize' ,8); plot(t2(1),t2(2), 'o' , 'markeredgecolor' , 'r' , 'markerfacecolor' , 'y' , 'markersize' ,8); plot(t3(1),t3(2), 'o' , 'markeredgecolor' , 'r' , 'markerfacecolor' , 'y' , 'markersize' ,8); xlabel( 'x' ) ylabel( 'y' ) text(t1(1)- 0.05,t1(2), '\color{black}T0' , 'fontsize' ,12, 'fontweight' , 'bold' , 'HorizontalAlignment' , 'right' ) text(t2(1),t2(2)+0.07, '\color{black}T1' , 'fontsize' ,12, 'fontweight' , 'bold' , 'HorizontalAlignment' , ' center' , 'VerticalAlignment' , 'baseline' ) text(t3(1)+0.05,t3(2), '\color{black}T2' , 'fontsize' ,12, 'fontweight' , 'bold' , 'HorizontalAlignment' , ' left' )
else waktu=tic; acak=data(m,:); for iter=1:imax
pilih=ra(iter); x=(data(pilih,1)+acak(1))/2; y=(data(pilih,2)+acak(2))/2; plot(x,y, 'b.' ) set(handles.axes1, 'Color' ,[1 1 1], 'XColor' ,[0 0 0], 'YColor' ,[0 0
0], 'Xgrid' , 'on' , 'ygrid' , 'on' , 'NextPlot' , 'add' ); acak=[x y]; a1=sprintf( ' %9.3f' ,acak(1)); a2=sprintf( ' %9.3f' ,acak(2)); a3(iter)={[ ' T' num2str(pilih-1)]}; matacak(iter,:)={a1,a2}; rownames(iter)={[ 'A' num2str(iter)]};
end waktu=toc(waktu); set(handles.text5, 'string' ,waktu); set(handles.uitable2, 'data' ,[matacak a3'], 'rowname' ,rownames, 'columnname' ,{ 'x' , 'y' , 'Titik Terpilih' }, 'rowstriping' , 'on' ) set(handles.axes1, 'XLim' ,[min(data(:,1))-1 max(data(:,1)+1)], ...
'YLim' ,[min(data(:,2))-1 max(data(:,2))+1], 'xgrid' , 'on' , 'ygrid' , 'on' );
50
for j=1:m-1 if j~=m-1 plot([data(j,1) data(j+1,1)], [data(j,2) data(j+1,2)], 'k' , 'linewidth' ,3); end end plot([data(m-1,1) data(1,1)], [data(m-1,2) data(1,2)], 'k' , 'linewidth' ,3); for i=1:m-1
rname(i)={[ 'T' num2str(i-1)]}; plot(data(i,1),data(i,2), 'o' , 'markeredgecolor' , 'r' , 'markerfacecolor' , 'y' , 'markersize' ,10); text(data(i,1)-0.05,data(i,2),[ '\color{black}T' num2str(i-
1)], 'fontsize' ,12, 'fontweight' , 'bold' , 'HorizontalAlignment' , 'right' ) end rname(m)={ 'A0' }; set(handles.uitable1, 'data' ,data, 'rowname' ,rname, 'columnname' ,{ 'x' , 'y' })
end