Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:

Лабы / 3 / BEZ_LINE

.CPP
Скачиваний:
24
Добавлен:
16.04.2013
Размер:
1.5 Кб
Скачать
//Џа®Ја ¬¬  аЁбгҐв ЄаЁўлҐ ЃҐ§мҐ  Ї® 4-Ґ¬ в®зЄ ¬ (в®зҐЄ в®«мЄ® 4)
//¬®п Їа®Ј . ЋзҐ­м Їа®бв п ў ЁбЇ®«­Ґ­ЁЁ
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
#include<iostream.h>
#include<graphics.h>

int N=4; 		           //Є®«ЁзҐбвў® в®зҐЄ
float J0,J1,J2,J3;        //ЇҐаҐ¬Ґ­­лҐ ¤«п а бзҐв  Є®нддЁжЁҐ­в®ў
int t=0;

struct point{
	  int x;
	  int y;
	  } mas[100];
//€­ЁжЁ «Ё§ жЁп в®зҐЄ Ї® Є®в®ал¬ бва®Ё¬ ЄаЁўлҐ Ё ᮥ¤Ё­Ґ­ЁҐ нвЁе в®зҐЄ Їап¬л¬Ё
//¤«п ­ Ј«п¤­®бвЁ
void init()
{
 randomize();
 for (int i=0;i<N;i++)
 {
 mas[i].x=random(640);
 mas[i].y=random(480);
 putpixel(mas[i].x,mas[i].y,WHITE);
 }
 for(i=0;i<N-1;i++)
 {
 line(mas[i].x,mas[i].y,mas[i+1].x,mas[i+1].y);
 }
}

void Draw_Bez()
{
  int x,y;
  for(float t=0;t<1;t=t+0.00001)
  {
//Ї®¤бзҐв Є®ндЁжЁҐ­в®ў ¤«п Ї®бв஥­Ёп ЄаЁўле Ї® 4-Ґ¬ в®зЄ ¬
J0=1-3*t+3*(t*t)-(t*t*t);
J1=3*t-6*(t*t)+3*(t*t*t);
J2=3*(t*t)-3*(t*t*t);
J3=t*t*t;
  x=J0*mas[0].x+J1*mas[1].x+J2*mas[2].x+J3*mas[3].x;
  y=J0*mas[0].y+J1*mas[1].y+J2*mas[2].y+J3*mas[3].y;
  putpixel(x,y,GREEN);
 }
}

void main()
{
clrscr();
//////////////////€­ЁжЁ «Ё§ жЁп Ја дЁзҐбЄ®Ј® ०Ё¬ ////////////////////
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "E:\\C3.1\\BGI");
errorcode = graphresult();
if (errorcode != grOk)
{
   printf("Graphics error: %s\n", grapherrormsg(errorcode));
   printf("Press any key to halt:");
   getch();
   exit(1);
}
init();
Draw_Bez();
getchar();
closegraph();
}
Соседние файлы в папке 3