Thứ Ba, 26 tháng 1, 2016

đồ họa c

#include&lt;stdio.h&gt;<br />
#include&lt;graphics.h&gt;<br />
#include&lt;dos.h&gt;<br />
void matrix(int numc, int numl, int high, int width, int sizec, int sizel, int timedelay, int sizeline)<br />
{<br />
&nbsp; &nbsp; setlinestyle(0,0,sizeline);<br />
&nbsp; &nbsp; for(int i=0;i&lt;=numc;i++)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; setcolor((i&lt;=7)?i:((i%7==0)?5:i%7));<br />
&nbsp; &nbsp; &nbsp; &nbsp; line(i*sizec,0,i*sizec,high);<br />
&nbsp; &nbsp; &nbsp; &nbsp; delay(timedelay);<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
&nbsp; &nbsp; for(int i=0;i&lt;=numl;i++)<br />
&nbsp; &nbsp; &nbsp; &nbsp; {<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;setcolor((i&lt;=7)?i:((i%7==0)?5:i%7));<br />
&nbsp; &nbsp; &nbsp; &nbsp; line(0,i*sizel,width,i*sizel);<br />
&nbsp; &nbsp; &nbsp; &nbsp; delay(timedelay);<br />
&nbsp; &nbsp; &nbsp; &nbsp; }<br />
}<br />
void diagonal(int numc, int numl, int high, int width, int sizec, int sizel, int timedelay, int sizeline)<br />
{<br />
&nbsp; &nbsp; &nbsp; &nbsp; setlinestyle(0,0,sizeline);<br />
&nbsp; &nbsp; &nbsp; &nbsp; int xs=0,ys=0,xe=0,ye=0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;for (int i=1;i&lt;=(numl+numc-1);i++)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;setcolor((i&lt;=7)?i:((i%7==0)?5:i%7));<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(xs&lt;numc)?xs++:ys++;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(ye&lt;numl)?ye++:xe++;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;line(xs*sizec,ys*sizel,xe*sizec,ye*sizel);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;delay(timedelay);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; xs=numc; ys=0; xe=numc; ye=0;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (int i=1;i&lt;=(numl+numc-1);i++)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;{<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; setcolor((i&lt;=7)?i:((i%7==0)?5:i%7));<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (xs&gt;0)?xs--:ys++;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (ye&lt;numl)?ye++:xe--;<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; line(xs*sizec,ys*sizel,xe*sizec,ye*sizel);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;delay(timedelay);<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br />
}<br />
main()<br />
{<br />
&nbsp; &nbsp; int numc,numl,width,high;<br />
&nbsp; &nbsp; printf("\t- Kich thuoc cua so (WIDTH x HIGH): "); scanf("%d x %d",&amp;width,&amp;high);<br />
&nbsp; &nbsp; printf("\t- Nhap kich thuoc luoi (ROW x COLUMN): "); scanf("%d x %d",&amp;numl,&amp;numc);<br />
&nbsp; &nbsp; initwindow(width,high);<br />
&nbsp; &nbsp; int sizec=width/numc, sizel=high/numl, time=300, sizeline=3;<br />
&nbsp; &nbsp; matrix(numc, numl, high, width, sizec, sizel, time, sizeline);<br />
&nbsp; &nbsp; diagonal(numc, numl, high, width, sizec, sizel, time, sizeline);<br />
&nbsp; &nbsp; getch();<br />
}

0 nhận xét: