Загрузка...

Функция, рисующая конденсатор


void condensator(int x1,int y1,int x2,int y2){

int x3,y3;

switch(pozition(x1,y1,x2,y2)){

case 1:

if(x2>x1){

y2=y1;

x3=x1+(x2-x1)/2;

line(x1,y1,x3-3,y1);

line(x3+3,y2,x2,y2);

line(x3-3,y1-7,x3-3,y1+7);

line(x3+3,y2-7,x3+3,y2+7);

}

if(x2<x1){

x3=x2+(x1-x2)/2;

y2=y1;

line(x2,y2,x3-3,y1);

line(x3+3,y2,x1,y1);

line(x3-3,y1-7,x3-3,y1+7);

line(x3+3,y2-7,x3+3,y2+7);

}

break;

case 2:

if(y1<y2){

y3=y1+(y2-y1)/2;

x2=x1;

line(x1,y1,x1,y3-3);

line(x2,y3+3,x2,y2);

line(x1-7,y3-3,x1+7,y3-3);

line(x1-7,y3+3,x1+7,y3+3);

}

if(y1>y2){

y3=y2+(y1-y2)/2;

x2=x1;

line(x1,y1,x1,y3+3);

line(x2,y3-3,x2,y2);

line(x1-7,y3-3,x1+7,y3-3);

line(x1-7,y3+3,x1+7,y3+3);

}

break;

case 3:

if(x2>x1){

y2=y1-(x2-x1);

x3=x1+(x2-x1)/2;

y3=y1+(y2-y1)/2;

line(x1,y1,x3-2,y3+2);

line(x3+2,y3-2,x2,y2);

line(x3+3,y3+7,x3-7,y3-3);

line(x3+7,y3+3,x3-3,y3-7);

}

if(x2<x1){

y2=y1+(x1-x2);

x3=x2+(x1-x2)/2;

y3=y1+(y2-y1)/2;

line(x1,y1,x3+2,y3-2);

line(x3-2,y3+2,x2,y2);

line(x3-7,y3-3,x3+3,y3+7);

line(x3-3,y3-7,x3+7,y3+3);

}

break;

case 4:

if(x2>x1){

y2=y1+(x2-x1);

x3=x1+(x2-x1)/2;

y3=y1+(y2-y1)/2;

line(x1,y1,x3-2,y3-2);

line(x3+2,y3+2,x2,y2);

line(x3-7,y3+3,x3+3,y3-7);

line(x3-3,y3+7,x3+7,y3-3);

}

if(x2<x1){

y2=y1-(x1-x2);

x3=x2+(x1-x2)/2;

y3=y2+(y1-y2)/2;

line(x1,y1,x3+2,y3+2);

line(x3-2,y3-2,x2,y2);

line(x3-3,y3+7,x3+7,y3-3);

line(x3-7,y3+3,x3+3,y3-7);

}

break;

}

}

// Функция, рисующая катушку

void catushka(int x1,int y1,int x2,int y2){

int x3,y3;

switch(pozition(x1,y1,x2,y2)){

case 1:

if(x2>x1){

y2=y1;

x3=x1+(x2-x1)/2;

line(x1,y1,x3-15,y1);

arc(x3-10,y1,0,180,5);

arc(x3,y1,0,180,5);

arc(x3+10,y1,0,180,5);

line(x3+15,y1,x2,y2);

}

if(x2<x1){

x3=x2+(x1-x2)/2;

y2=y1;

line(x2,y2,x3-15,y2);

arc(x3-10,y2,0,180,5);

arc(x3,y2,0,180,5);

arc(x3+10,y2,0,180,5);

line(x3+15,y2,x1,y1);

}

break;

case 2:

if(y1<y2){

y3=y1+(y2-y1)/2;

x2=x1;

line(x1,y1,x1,y3-15);

arc(x1,y3-10,90,270,5);

arc(x1,y3,90,270,5);

arc(x1,y3+10,90,270,5);

line(x2,y3+15,x2,y2);

}

if(y1>y2){

y3=y2+(y1-y2)/2;

x2=x1;

line(x1,y1,x1,y3+15);

arc(x1,y3+10,90,270,5);

arc(x1,y3,90,270,5);

arc(x1,y3-10,90,270,5);

line(x1,y3-15,x2,y2);

}

break;

case 3:

if(x2>x1){

y2=y1-(x2-x1);

x3=x1+(x2-x1)/2;

y3=y1+(y2-y1)/2;

line(x1,y1,x3-14,y3+14);

arc(x3,y3,45,225,6);

arc(x3-9,y3+9,45,225,6);

arc(x3+9,y3-9,45,225,6);

line(x3+14,y3-14,x2,y2);

}

if(x2<x1){

y2=y1+(x1-x2);

x3=x2+(x1-x2)/2;

y3=y1+(y2-y1)/2;

line(x1,y1,x3+14,y3-14);

arc(x3,y3,45,225,6);

arc(x3-9,y3+9,45,225,6);

arc(x3+9,y3-9,45,225,6);

line(x3-14,y3+14,x2,y2);

}

break;

case 4:

if(x2>x1){

y2=y1+(x2-x1);

x3=x1+(x2-x1)/2;

y3=y1+(y2-y1)/2;

line(x1,y1,x3-14,y3-14);

arc(x3-9,y3-9,315,135,6);

arc(x3,y3,315,135,6);

arc(x3+9,y3+9,315,135,6);

line(x3+14,y3+14,x2,y2);

}

if(x2<x1){

y2=y1-(x1-x2);

x3=x2+(x1-x2)/2;

y3=y2+(y1-y2)/2;

line(x1,y1,x3+14,y3+14);

arc(x3-9,y3-9,315,135,6);

arc(x3,y3,315,135,6);

arc(x3+9,y3+9,315,135,6);

line(x3-14,y3-14,x2,y2);

}

break;

}

}

// Функция, рисующая реостат

void reostat(int x1,int y1,int x2,int y2,int x3,int y3){

int midle;//координата середины реостата

switch(pozition(x1,y1,x2,y2)){

case 1:

if(x2>x1){

midle=x1+(x2-x1)/2;

y2=y1;

}

if(x2<x1){

midle=x2+(x1-x2)/2;

y2=y1;

}

if(y3<y1-5){

line(midle,y1-5,midle,y3);

line(midle,y3,x3,y3);

line(midle,y1-5,midle+3,y1-10);

line(midle,y1-5,midle-3,y1-10);

}

else{

line(midle,y1+5,midle,y3);

line(midle,y3,x3,y3);

line(midle,y1+5,midle+3,y1+10);

line(midle,y1+5,midle-3,y1+10);

}

break;

case 2:

if(y1<y2){

midle=y1+(y2-y1)/2;

x2=x1;

}

if(y1>y2){

midle=y2+(y1-y2)/2;

x2=x1;

}

if(x3<x1-5){

line(x1-5,midle,x3,midle);

line(x3,midle,x3,y3);

line(x1-5,midle,x1-10,midle-3);

line(x1-5,midle,x1-10,midle+3);

}

else{

line(x1+5,midle,x3,midle);

line(x3,midle,x3,y3);

line(x1+5,midle,x1+10,midle-3);

line(x1+5,midle,x1+10,midle+3);

}

break;

}

}

Загрузка...