Documente Academic
Documente Profesional
Documente Cultură
www.cniv.ro
www.icvl.eu
©
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
Daca se considera o linie poligonala formata din 3 puncte Pi(xi, yi), i=1,2, 3, atunci
aceasta se aproximeaza cu o curba B-spline ce are o extremitate in mijlocul segmentului
P1 P2, iar cealalta extremitate se afla in mijlocul segmentului P2 P3 , curba fiind un arc
de parabola (curba de gradu II) definit de drumul (aplicatia) :
γ : [0,1] R2, unde γ (t) = (x(t), y(t)),
x(t) = a x1 + b x2 + c x3
y(t) = a y1 + b y2 + c y3 , pentru t ∈ [0,1] , notatiile fiind
a = (1 – 2t + t2 )/2 , b = (1 + 2t -t2 ) /2, c = t2 /2, a+b+c = 1
P2
P1 P3
Definitie.
Linia poligonala P = P1 P2 ... Pn , unde Pi(xi, yi), i=1,2, … ,n , se aproximeaza cu o
curba B-spline γ = γ1 ∪ γ 2 ∪ ... ∪ γn-2 , avand urmatoarele proprietati ;
a) are extremitatile in mijloacele segmentolor P1 P2 si Pn-1 Pn ;
b) segmentele Pi Pi+1 , i=1,2, …, n-1 sunt tangente la curba in mijloacele segmentelor Pi
Pi+1.
c) curba este definita pe portiuni de γi : [0,1] R2, unde γi (t) = (x(t), y(t)),
i=1,2, … ,n-2 si
x(t) = a xi + b xi+1 + c xi+2
y(t) = a yi + b yi+1 + c yi+2 , pentru t ∈ [0,1] , notatiile fiind
a = (1 – 2t + t2 )/2 , b = (1 + 2t -t2 ) /2, c = t2 /2, a+b+c = 1
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
P2 P4 . . . . . Pn -2 Pn
γ1 γ2 γ3 γn-2
P1 P3 Pn -1
Programul realizeaza generarea literelor mari de tip cursiv prin citirea coordonatelor
unor puncte ce reprezinta o linie poligonala cu punctele aflate pe conturul literei. Un
exemplu de astfel de litere este prezentat mai jos.
Program litereM.cpp
#include <graphics.h>
#include <conio.h>
#include <math.h>
#include <iostream.h>
int gd, gm;
int n, i, j, k, ii, d, max, xx, yy;
int x[200];
int y[200];
float a, b, c, p, t;
Programul realizeaza generarea literelor mici de tip cursiv prin citirea dintr-un fisier a
unui numar de puncte ce reprezinta o linie poligonala cu punctele aflate pe conturul
literei.
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
int n,i,j,k,ii,d,max,x=1,y=450,xx,yy,x1[100],y1[100];
float a,b,c,p,t;
//functie "lung"
//----------------------------------------------------
int lung() // determina numarul de diviziuni ptr. discretizare
{
max=0;
for (int ij=i;ij<=i+1;ij++)
{
d =abs(x+x1[ij]-(x+x1[ij+1]));
if (d>max) max=d;
d=abs(y+y1[ij]-(y+y1[ij+1]));
if (d>max) max=d;
}
return max;
} //sfarsit functie lung
//-----------------------------------------------
//procedura "curba"
//-----------------------------------------------
void curba()
{
p=1.0/lung(); // pasul de discretizare
t=0;
for (ii=1;ii<=lung();ii++)
{
a=1-t;
a=(a*a)/2;
c=(t*t)/2;
b=1-a-c:
xx=round(a*(x+x1[i])+ b*(x+x1[j])+c*(x+x1[k]));
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
yy=getmaxy()-round(a*(y+y1[i])+b*(y+y1[j])+c*(y+y1[k]));
lineto(xx,yy);
t=t+p;
}
} //sfarsit procedura curba
//---------------------------------------------------
// procedura "litera"
//---------------------------------------------------
void litera(int x2,int y2,FILE *fp)
{
fscanf(fp,"%d",&n);
while (n !=5000)
{
moveto(x2+x1[1],getmaxy()-(y2+y1[1]));
xx=round(((x2+x1[1])+(x2+x1[2]))/2);
yy=getmaxy()-round(((y2+y1[1])+(y2+y1[2]))/2);
lineto(xx, yy);
for(i =1;i<=n-2;i++)
{
j=i+1;k=i+2;
curba();
}
//lineto(x2+x1[n],getmaxy()-y2+y1[n]);
fscanf(fp,"%d",&n);
}
}//sfarsit procedura litera
//-----------------------------------------------
ch=toascii(getch());
if (!kbhit())
{
switch(ch)
{
case 32 : if ((x+=20)>getmaxx()-30) {x=1;y-=30;};
if (y<50) {cleardevice();y=450;}
break;
case 97 : f=fopen("c:\\borlandc\\bin\\a.txt","r");
litera(x,y,f);
fclose(f);
if ((x+=20)>getmaxx()-30) {x=1;y-=30;};
if (y<50) {cleardevice();y=450;}
break;
case 98 : f=fopen("c:\\borlandc\\bin\\b.txt","r");
litera(x,y,f);
fclose(f);
if ((x+=20)>getmaxx()-30) {x=1;y-=30;};
if (y<50) {cleardevice();y=450;}
break;
case 99 : x=x-8;
f=fopen("c:\\borlandc\\bin\\c.txt","r");
litera(x,y,f);
fclose(f);
if ((x+=20)>getmaxx()-30) {x=1;y-=30;};
if (y<50) {cleardevice();y=450;}
break;
case 100 :f=fopen("c:\\borlandc\\bin\\d.txt","r");
litera(x,y,f);
fclose(f);
if ((x+=20)>getmaxx()-30) {x=1;y-=30;};
if (y<50) {cleardevice();y=450;}
break;
case 101 :f=fopen("c:\\borlandc\\bin\\e.txt","r");
litera(x,y,f);
fclose(f);
if ((x+=18)>getmaxx()-30) {x=1;y-=30;};
if (y<50) {cleardevice();y=450;}
break;
case 102 :f=fopen("c:\\borlandc\\bin\\f.txt","r");
litera(x,y,f);
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
fclose(f);
if ((x+=19)>getmaxx()-30) {x=1;y-=30;};
if (y<50) {cleardevice();y=450;}
break;
case 103 :f=fopen("c:\\borlandc\\bin\\g.txt","r");
litera(x,y,f);
fclose(f);
if ((x+=17)>getmaxx()-30) {x=1;y-=30;};
if (y<50) {cleardevice();y=450;}
break;
case 104 :f=fopen("c:\\borlandc\\bin\\h.txt","r");
litera(x,y,f);
fclose(f);
if ((x+=19)>getmaxx()-30) {x=1;y-=30;};
if (y<50) {cleardevice();y=450;}
break;
case 105 :f=fopen("c:\\borlandc\\bin\\i.txt","r");
litera(x,y,f);
putpixel(x+11,getmaxy()-y-20,15);
fclose(f);
if ((x+=20)>getmaxx()-30) {x=1;y-=30;};
if (y<50) {cleardevice();y=450;}
break;
case 106 :f=fopen("c:\\borlandc\\bin\\j.txt","r");
litera(x,y,f);
putpixel(x+11,getmaxy()-y-20,15);
fclose(f);
if ((x+=16)>getmaxx()-30) {x=1;y-=30;};
if (y<50) {cleardevice();y=450;}
break;
case 107 :f=fopen("c:\\borlandc\\bin\\k.txt","r");
litera(x,y,f);
fclose(f);
if ((x+=20)>getmaxx()-30) {x=1;y-=30;};
if (y<50) {cleardevice();y=450;}
break;
case 108 :f=fopen("c:\\borlandc\\bin\\l.txt","r");
litera(x,y,f);
fclose(f);
if ((x+=20)>getmaxx()-30) {x=1;y-=30;};
if (y<50) {cleardevice();y=450;}
break;
case 109 :f=fopen("c:\\borlandc\\bin\\m.txt","r");
litera(x,y,f);
fclose(f);
if ((x+=20)>getmaxx()-30) {x=1;y-=30;};
if (y<50) {cleardevice();y=450;}
break;
case 110 :f=fopen("c:\\borlandc\\bin\\n.txt","r");
litera(x,y,f);
fclose(f);
if ((x+=17)>getmaxx()-30) {x=1;y-=30;};
if (y<50) {cleardevice();y=450;}
break;
case 111 :f=fopen("c:\\borlandc\\bin\\o.txt","r");
litera(x,y,f);
fclose(f);
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
if ((x+=18)>getmaxx()-30) {x=1;y-=30;};
if (y<50) {cleardevice();y=450;}
break;
case 112 :f=fopen("c:\\borlandc\\bin\\p.txt","r");
litera(x,y,f);
fclose(f);
if ((x+=20)>getmaxx()-30) {x=1;y-=30;};
if (y<50) {cleardevice();y=450;}
break;
case 113 :f=fopen("c:\\borlandc\\bin\\q.txt","r");
litera(x,y,f);
fclose(f);
if ((x+=20)>getmaxx()-30) {x=1;y-=30;};
if (y<50) {cleardevice();y=450;}
break;
case 114 :f=fopen("c:\\borlandc\\bin\\r.txt","r");
litera(x,y,f);
fclose(f);
if ((x+=20)>getmaxx()-30) {x=1;y-=30;};
if (y<50) {cleardevice();y=450;}
break;
case 115 :f=fopen("c:\\borlandc\\bin\\s.txt","r");
litera(x,y,f);
fclose(f);
if ((x+=20)>getmaxx()-30) {x=1;y-=30;};
if (y<50) {cleardevice();y=450;}
break;
case 116 :f=fopen("c:\\borlandc\\bin\\t.txt","r");
litera(x,y,f);
fclose(f);
if ((x+=20)>getmaxx()-30) {x=1;y-=30;};
if (y<50) {cleardevice();y=450;}
break;
case 117 :f=fopen("c:\\borlandc\\bin\\u.txt","r");
litera(x,y,f);
fclose(f);
if ((x+=20)>getmaxx()-30) {x=1;y-=30;};
if (y<50) {cleardevice();y=450;}
break;
case 118 :f=fopen("c:\\borlandc\\bin\\v.txt","r");
litera(x,y,f);
fclose(f);
if ((x+=20)>getmaxx()-30) {x=1;y-=30;};
if (y<50) {cleardevice();y=450;}
break;
case 119 :f=fopen("c:\\borlandc\\bin\\w.txt","r");
litera(x,y,f);
fclose(f);
if ((x+=20)>getmaxx()-30) {x=1;y-=30;};
if (y<50) {cleardevice();y=450;}
break;
case 120 :f=fopen("c:\\borlandc\\bin\\x.txt","r");
litera(x,y,f);
fclose(f);
if ((x+=20)>getmaxx()-30) {x=1;y-=30;};
if (y<50) {cleardevice();y=450;}
break;
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
case 121 :f=fopen("c:\\borlandc\\bin\\y.txt","r");
litera(x,y,f);
fclose(f);
if ((x+=20)>getmaxx()-30) {x=1;y-=30;};
if (y<50) {cleardevice();y=450;}
break;
case 122 :f=fopen("c:\\borlandc\\bin\\z.txt","r");
litera(x,y,f);
fclose(f);
if ((x+=20)>getmaxx()-30) {x=1;y-=30;};
if (y<50) {cleardevice();y=450;}
break;
case 13 : x=1;
if((y=y-30)<50) {cleardevice();y=450;}
break;
default: bool=0;
}
}
};
closegraph();
}
Fsiere de intrare :
uses crt,graph;
const esc=#27;
enter=#13;
sus=#72;
jos=#80;
dr=#77;
st=#75;
raz=5;
var gd,gm:integer;
ii,i,j,k,d,max,xx,yy:integer;
x,y,xu,yu:integer;
lx,ly:integer;
ch:char;
vx:array[0..100]of integer;
vy:array[0..100]of integer;
nk:integer;
a,b,c,p,t:real;
function lung:integer;
begin
max:=0;
for ii:=i to i+1 do
begin
c:=abs(vx[ii]-vx[ii+1]);
if d>max then max:=d;
c:=abs(vy[ii]-vy[ii+1]);
if d>max then max:=d;
end;
lung:=max;
end;
procedure curba;
begin
p:=1/lung;
t:=0;
for ii:=1 to lung do
begin
a:=1-t;a:=(a*a)/2;c:=(t*t)/2;b:=1-a-c:
xx:=round(a*vx[i]+b*vx[j]+c*vx[k]);
yy:=round(a*vy[i]+b*vy[j]+c*vy[k]);
lineto(xx,yy);
t:=t+p;
end;
end;
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
procedure bspline;
begin
moveto(vx[1],vy[1]);
xx:=round((vx[1]+vx[2])/2);
yy:=round((vy[1]+vy[2])/2);
lineto(xx, yy);
for i:=1 to nk-2 do
begin
j:=i+1;k:=i+2;
curba;
end;
lineto(vx[nk],vy[nk]);
end;
procedure draw_cursor(xc,yc:integer);
begin
moveto (xc,yc);linerel(lx,0);
moveto (xc,yc);linerel(-lx,0);
moveto (xc,yc);linerel(0,ly);
moveto (xc,yc);linerel(0,-lx);
end;
BEGIN
gc:=detect;
initgraph(gd,gm,'c:\TP\BGI');
lx:=(getmaxx+1)div 50;
ly:=(getmaxy+1)div 50;
SetWriteMode(XorPut);
x:=GetMaxX div 2;
y:=GetMaxY div 2;
nk:=1;
repeat
draw_cursor(x,y);
ch:=readkey;
xu:=x;
yu:=y;
case ch of
enter:begin
if nk=1 then
begin
VX[nK]:=XU;
VY[nK]:=YU;
nk:=nk+1;
circle(xu,yu,raz);
end
else
begin
circle(xu,yu,raz);
line(vx[nk-1],vy[nk-1],xu,yu);
VX[NK]:=XU;
VY[NK]:=YU;
nK:=nK+1;
end;
end;
sus:begin
yu:=y-5;
end;
jos:begin
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
yu:=y+5;
end;
dr:begin
xu:=x+7;
end;
st:begin
xu:=x-7;
end;
end;
draw_cursor(x,y);
x:=xu;
y:=yu;
until ch=esc:
cleardevice;
SetWriteMode(NormalPut);
NK:=NK-1;
bspline;
readln;
closegraph;
END.
Sarpe.cpp
#include<conio.h>
#include<stdlib.h>
#include<dos.h>
#include<stdio.h>
#include<graphics.h>
#include<ctype.h>
int ch,i,j,f,r,a[10][2],s=0,len=30;
unsigned int time0=0;
FILE *fp;
struct q
{
int x1,x2,y1,y2;
}q[100]={320,320,210,210},t={320,320,210,210},c;
void initializare()
{
int gdriver = DETECT, gmode, errorcode;
initgraph(&gdriver, &gmode, "c:\\borlandc\\bgi");
errorcode = graphresult();
if (errorcode != grOk)
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
{
printf("Eroare: %s\n", grapherrormsg(errorcode));
printf("Apasa orice tasta pentru iesire!");
getch();
exit(1);
}
}
void push(struct q t)
{
f++;
q[f].x1=t.x1;
q[f].y1=t.y1;
q[f].x2=t.x2;
q[f].y2=t.y2;
};
struct q pop(void)
{
r++;
return(q[r-1]);
};
//procedura de verificare
void chk(void)
{
for(i=0;i<15;i++)
{
//verifica daca s-a capturat ceva
if (((c.x2 - a[i][0] < 4) && (c.x2 - a[i][0] > - 4)) &&
((c.y2 - a[i][1] < 4) && (c.y2 - a[i][1] > - 4)) && a[i][0] != 0)
{
s++;
len+=4;
time0=time0-25;
delay(50);
gotoxy(65,5);
printf(" \a Score : %d",s);
if(s >= 10)
{
closegraph();
printf("Felicitari ai castigat!");
printf(" \nApasa orice tasta pentru a iesi!");
while(!kbhit())
{
sound(random(2000));
delay(100);
}
nosound();
exit(0);
}
setcolor(WHITE);
circle(a[i][0],a[i][1],2);
a[i][0]=a[i][1]=0;
}
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
}
//verifica daca se intalneste capul cu corpul
for(i=r;i<=f;i++)
{
if ((q[i].x1 == c.x2) && (q[i].y1 == c.y2))
{
closegraph();
exit(0);
}
}
main()
{
initializare();
randomize();
setbkcolor(LIGHTBLUE);
c.x1=c.x2=320;
c.y1=c.y2=210;
setcolor(YELLOW);
rectangle(30,20,500,460);
setcolor(RED);
for(i=0;i<10;i++)
{
a[i][0]=45+random(450);
a[i][1]=30+random(425);
circle(a[i][0],a[i][1],2);
}
setlinestyle(SOLID_LINE,2,3);
while(1)
{
ch=toascii(getch());
while(!kbhit())
{
t=c;
switch(ch)
{
case 72 : // Sus
t.x1=t.x2;
t.y1=t.y2;
t.y2=t.y1-5;
break;
case 80 : // Jos
t.x1=t.x2;
t.y1=t.y2;
t.y2=t.y1+5;
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
break;
case 75 : // Stanga
t.y1=t.y2;
t.x1=t.x2;
t.x2=t.x1-5;
break;
case 77 : // Dreapta
t.y1=t.y2;
t.x1=t.x2;
t.x2=t.x1+5;
break;
case 27 :
closegraph(); // Esc
exit(0);
default: printf("\a");break;
}
c=t;
setcolor(LIGHTRED);
push(t);
line(t.x1,t.y1,t.x2,t.y2);
if ((f - r) > len)
{
t=pop();
setcolor(LIGHTBLUE);
line(t.x1,t.y1,t.x2,t.y2);
}
chk();
sq();
delay(50);
gotoxy(65,10);
textcolor(7);
printf("Time : %u",time0++);
if (time0 >= 1200 )
{
closegraph();
delay(2000);
getch();
exit(0);
}
};
};
}
void sq(void)
{
if (r > 8)
{
for(i=r;i<=f;i++)
q[i-r]=q[i];
f=f-r;
r=0;
}
return;
}
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
Program planete.cpp
u = 2*3.14/360*deplasare;
x = (razax * cos(u));
y = (razay * sin(u));
setcolor(culoare);
setfillstyle(1,culoare);
fillellipse((int)x,(int)y, raza,raza);
if (saturn == 1)
{
setcolor(7);
ellipse((int)x,(int)y, 140,390,11,5);
}
if (luna != 0)
{
setviewport(getmaxx()/4+(int)x+1,
getmaxy()/2+(int)y+64,getmaxx()/2, getmaxy(), 0);
drawplanet(luna, 12,17,59,2);
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
setviewport( getmaxx()/4+1, getmaxy()/2+64,getmaxx()/2,
getmaxy(),0);
}
}
//-----------------------------------------------------------
/* stergerea planetei */
void delplanet(float deplasare, int razax,int razay, int raza, int
saturn=0,
int luna = 0)
{
float u=0,x=0,y=0;
u = 2*3.14/360 * deplasare;
x = (razax * cos(u));
y = (razay * sin(u));
setcolor(0);
setfillstyle(1,0);
fillellipse(x, y, raza, raza);
setcolor(0);
if (saturn == 1)
ellipse(x,y, 140,390,11,5);
if (luna != 0)
{
setviewport( getmaxx()/4+(int)x+1, getmaxy()/2+(int)y+64,
getmaxx()/2, getmaxy(), 0);
delplanet(luna, 12,17,2);
setviewport( getmaxx()/4+1, getmaxy()/2+64,getmaxx()/2,
getmaxy(),0);
}
}
//------------------------------------------------------------
if (contor%8 == 0)
{
u = 2*3.14/360 * (deplasare - 7*rotatie);
x = (razax * cos(u));
y = (razay * sin(u));
putpixel((int) x, (int)y, 7);
}
if (fabs(rotatie) <= 0.095 && contor%42 == 0 && contor>42)
{
u = 2*3.14/360 * (deplasare - 84*rotatie);
x = (razax * cos(u));
y = (razay * sin(u));
putpixel((int) x, (int)y, 7);
}
}
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
//------------------------------------------------------------
if (contor>0)
{
if (planeta == 1 && contor%361 == 0)
u = 2*3.14/360 * (deplasare - 361*rotatie);
if (planeta == 2 && contor%500 == 0)
u = 2*3.14/360 * (deplasare - 500*rotatie);
if (planeta == 3 && contor%600 == 0)
u = 2*3.14/360 * (deplasare - 600*rotatie);
if (planeta == 4 && contor%700 == 0)
u = 2*3.14/360 * (deplasare - 700*rotatie);
if (planeta == 5 && contor%800 == 0)
u = 2*3.14/360 * (deplasare - 800*rotatie);
x = (razax * cos(u));
y = (razay * sin(u));
putpixel((int) x, (int)y, 7);
}
}
//---------------------------------------------------------------
delplanet(miscmercur,14,20,2);
miscmercur += rotmercur;
drawplanet(miscmercur, 14,20,230,2);
detpozitie(cmercur++,miscmercur,rotmercur,14,20);
}
//------------------------------------------------------------
delplanet(miscvenus,36,37,5);
miscvenus -= rotvenus;
drawplanet(miscvenus,36,37,56,5);
detpozitie(cvenus++,miscvenus,-rotvenus,36,37);
}
//--------------------------------------------------------------
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
/* Miscarea Pamantului si a Lunii */
void pamantsiluna()
{
static float miscpamant = 0, miscluna = 0;
static unsigned int cpamant;
delplanet(miscpamant,61,63,6,0,miscluna);
miscpamant += rotpamant;
miscluna += rotluna;
drawplanet(miscpamant,61,63,1,6,0,miscluna);
// delay(2);
detpozitie(cpamant++,miscpamant,rotpamant,61,63);
}
//--------------------------------------------------------------
delplanet(miscmarte,88,104,3);
miscmarte += rotmarte;
drawplanet(miscmarte,88,104,4,3);
// delay(2);
detpozitie(cmarte++,miscmarte,rotmarte,88,104);
}
//------------------------------------------------------------
delplanet(miscjupiter,140,155,15);
miscjupiter += rotjupiter;
drawplanet(miscjupiter,140,155,50,15);
// delay(2);
detpozitie(cjupiter++,miscjupiter,rotjupiter,140,155);
}
//-----------------------------------------------------------
delplanet(miscjupiter2,26,28,10);
miscjupiter2 += rotjupiter;
drawplanet(miscjupiter2,26,28,50,10);
detpozitie2(cjupiter2++,miscjupiter2,rotjupiter,26,28,1);
}
//------------------------------------------------------------
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
delplanet(miscsaturn,48,54,8,1);
miscsaturn += rotsaturn;
drawplanet(miscsaturn,48,54,22,8,1);
detpozitie2(csaturn++,miscsaturn,rotsaturn,48,54,2);
}
//-------------------------------------------------------------
delplanet(miscuranus,97,106,4);
miscuranus -= roturanus;
drawplanet(miscuranus,97,106,23,4);
detpozitie2(curanus++,miscuranus,-roturanus,97,106,3);
}
//-------------------------------------------------------------
delplanet(miscneptun,140,143,3);
miscneptun += rotneptun;
drawplanet(miscneptun,140,143,9,3);
detpozitie2(cneptun++,miscneptun,rotneptun,140,143,4);
}
//------------------------------------------------------------
delplanet(miscpluto,151,220,1);
miscpluto -= rotpluto;
drawplanet(miscpluto,151,220,12,1);
detpozitie2(cpluto++,miscpluto,-rotpluto,151,220,5);
}
//------------------------------------------------------------
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
void afisareplanete()
{
setcolor(7);
outtextxy(8,15,"Planetele din acest cadru:");
setviewport(5,50,50,50,0);
drawplanet(0,30,0,14,10);
outtextxy(10,20,"Soare"); /* desenarea planetelor */
drawplanet(0,95,0,230,2); /* din cadrul 1 (partea stanga)*/
outtextxy(72,20,"Mercur");
drawplanet(0,156,0,56,5);
outtextxy(136,20,"Venus");
drawplanet(0,215,0,1,6);
outtextxy(195,20,"Pamant");
drawplanet(0,272,0,59,2);
outtextxy(256,20,"Luna");
setcolor(15);
outtextxy(90,0,"Este anul: ");
outtextxy(90,15,"si ziua: ");
setcolor(15);
setviewport(0,0,getmaxx(),getmaxy(),0);
setlinestyle(0,1,1);
}
//-----------------------------------------------------
/*functie pt crearea liniilor care delimiteaza partea stanga si cea
dreapta*/
/* adica cadrul 1 si 2 */
void incadrare()
{
setcolor(15);
line(0,0,0,getmaxy());/* se traseaza liniile cadrului 1 */
line(0,0,getmaxx()/2,0);
line(getmaxx()/2,0,getmaxx()/2,getmaxy());
line(0,getmaxy(),getmaxx()/2,getmaxy());
line(3,5,3,getmaxy()-5);
line(3,5,getmaxx()/2-3,5);
line(getmaxx()/2-3,5,getmaxx()/2-3,getmaxy()-5);
line(3,getmaxy()-5,getmaxx()/2-3,getmaxy()-5);
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
line(getmaxx()/2,0,getmaxx(),0); /* trasare linii cadru 2 */
line(getmaxx(),0,getmaxx(),getmaxy());
line(getmaxx(),getmaxy(),getmaxx()/2,getmaxy());
line(getmaxx()/2+3,5,getmaxx()-3,5);
line(getmaxx()-3,5,getmaxx()-3,getmaxy()-5);
line(getmaxx()-3,getmaxy()-5,getmaxx()/2+3,getmaxy()-5);
line(getmaxx()/2+3,5,getmaxx()/2+3,getmaxy()-5);
setviewport(350,25,360,40,0);
drawplanet(0,0,0,22,8,1); /* desenare Saturn */
setcolor(22);
outtextxy(-20,20,"Saturn");
drawplanet(0,0,0,22,8,1);
setlinestyle(1,1,1);
line(-25,-12,35,-12);
line(-25,-12,-25,32);
line(-25,32,35,32);
line(35,32,35,-12);
}
//---------------------------------------------------------------------
-----
/* functie pentru desenarea planetelor Neptun si Pluto si incadrarea
lor */
void neptunsipluto()
{
setviewport(350,435,360,470,0);
drawplanet(0,2,0,9,3);
outtextxy(-20,20,"Neptun");
setlinestyle(1,1,1);
line(-25,-12,35,-12);
line(-25,-12,-25,32);
line(-25,32,35,32);
line(35,32,35,-12);
drawplanet(0,248,0,12,1);
outtextxy(228,20,"Pluto");
line(220,-12,280,-12);
line(280,-12,280,32);
line(280,32,220,32);
line(220,32,220,-12);
}
//----------------------------------------------------------
void main()
{
int driver = DETECT, mod, error;
unsigned int i=1;
int anul,ziua;
char an[10],zi[8];
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
sist-solar.html
<html>
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
<head>
<!--
/*************************************************************/
/*
* Neata Paul, Facultatea de Matematica si Informatica, Universitatea
Bucuresti, 2006
*
*
* Proiect - SIMULAREA SISTEMULUI SOLAR
*
* Program adaptat dupa "planete.cpp" realizat de Irimia Bogdan sub
indrumarea Conf. Dr. Vlada Marin
*
* numele de variabile/funcii in englezo-romana.
http://www.dustbunny.com/afk/planets/
*/
/***************************************************************/
-->
notsarted = true;
alert("SISTEMUL SOLAR - Neata Paul, grupa 433, anul IV, 2006\n\
Pentru alte informatii uitati-va in sursa.\n\n\
Pentru a porni/suspenda miscarea planetelor dati un clic pe suprafata
HTML-ului.\n\
In titlul ferestrei sunt informatiile despre ani si zile.\n\n\
Dimesiunile orbitelor au fost alterate, ficare, cu un factor.\n\
Daca vreti o afisare \"normala\"(nerecomandat), modificati, in sursa,
factorul la 1 pentru fiecare planeta.\n\n\
Avand in vedere faptul ca JavaScript este interpretat diferit de la
browser la browser, s-ar putea sa apara\
mici probleme la afisare.");
//screen.availHeight/2+50;
// punem sorii si apoi ii pozitionam
insert_planet(soare1);
insert_planet(soare2);
place_img_at(soare1.id, soare1.x_orb, soare1.y_orb);
place_img_at(soare2.id, soare2.x_orb, soare2.y_orb);
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
//trasam orbitele
if(confirm("Vreti sa afisati orbitele planetelor ? \nDaca da
aveti grija ca asta dureaza ceva de tipul 10 sec pe un Pentium 4\n")) {
mercur.draw_orbit();
venus.draw_orbit();
pamant.draw_orbit();
marte.draw_orbit();
jupiter.draw_orbit();
terjupi.draw_orbit();
saturn.draw_orbit();
uranus.draw_orbit();
neptun.draw_orbit();
pluto.draw_orbit();
}
terjupi.re_pos();
saturn.re_pos();
uranus.re_pos();
neptun.re_pos();
pluto.re_pos();
}
// functia de pozitionare a unei planate
// c_x, c_y reprezinta coordonatele centrului in jurul caruia se face
rotatia
function re_pos()
{
img = document.getElementById(this.center.id);
c_x = parseInt(img.style.left) + parseInt(img.width) / 2;
c_y = parseInt(img.style.top) + parseInt(img.height) / 2;
u = 2*Math.PI/360 * this.cur_depl; // unghiul in functie de
deplasare
x = c_x + this.factor * this.x_orb * Math.cos(u); // coordonatele
y = c_y + this.factor * this.y_orb * Math.sin(u); // ...
place_img_at(this.id, x, y);
this.cur_depl += this.inc_depl;
}
// plaseaza centrul unei imagini la coordonatele date
function place_img_at(id, x, y)
{
img = document.getElementById(id);
img.style.left = x - parseInt(img.width) / 2;
img.style.top = y - parseInt(img.height) / 2;
}
// deseneaza orbita
function draw_orbit()
{
img = document.getElementById(this.center.id);
c_x = parseInt(img.style.left) + parseInt(img.width) / 2;
c_y = parseInt(img.style.top) + parseInt(img.height) / 2;
u = 0;
x = 0;
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
y = 0;
for(this.cur_depl = 0; Math.abs(this.cur_depl) <= 360;
this.cur_depl += this.orb_factor*this.inc_depl) {
u = 2*Math.PI/360 * this.cur_depl; // unghiul in functie de
deplasare
x = c_x + this.factor * this.x_orb * Math.cos(u); //
coordonatele
y = c_y + this.factor * this.y_orb * Math.sin(u); // ...
x -= 5;
y -= 12;
ch = '.';
document.body.innerHTML += "<div
style='valign:top;align:left;color:#eeeeee;position:absolute;left:"+x+"
;top:"+y+"'>"+ch+"</div>"
}
this.cur_depl = 0;
}
</script>
<noscript>
Interpretarea JavaScript nu este activata in browser.
<br /><br />
Vedeti Edit->Preferences (pe Mozilla) sau Tools->Internet Options (pe
Internet Explorer) !
<br /><br />
</noscript>
</head>
<body background="img/back.bmp" onload="on_load();"
onclick="on_click();">
<!-- N I M I C -->
</body>
</html>
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
PROIECT – ceas
Nota: Codul in Pascal/Delphi; sa se scrie si codul in C++
uses dos,crt,graph;
var
i,Gd,Gm,x,y,r: integer;
angle4,angle,angle1,angle2,angle3: integer;
rad4,rad3,rad,rad1,rad2: real;
temp,h,m,s,hunc: word;
d : string;
begin
gd :=DETECT;
initgraph(Gd,Gm,'c:\TP\BGI');
setbkcolor(15); {culoarea de fond este alba}
x:=300; y:=250; { x SI y pentru centrul cercului }
r:=150; { raza cercului }
SetColor(9); {culoarea pentru cercuri este }
SETLINESTYLE(solidln,0,3);{liniile}
circle(x,y,r); { deseneaza cercul }
circle(x,y,r+20); { deseneaza un cerc cu raza mai mare cu 20 decat
primul}
setcolor(4);{deseneaza cercuri rosii}
for i:=1 to 148 do circle(x,y,i);
setcolor(14); {deseneaza cercuri galbene}
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
for i:=3 to 17 do circle(x,y,r+i);
setcolor(4); {culoarea rosie pentru scris }
for i:=1 to 12 do
begin
angle3:=i*30-90; { DESENEAZA NUMERELE }
rad3:=angle3*pi/180;
if i<10 then
begin
moveto(round(cos(rad3)*(r+35)+x),round(sin(rad3)*(r+35)+y));
Str(i, d);
outtext(d)
end
else
begin
moveto(round(cos(rad3)*(r+44)+x),round(sin(rad3)*(r+44)+y));
Str(I, d);
outtext(d);
end;
end;
setcolor(2);{setez culoare verde pentru linii}
for i:=1 to 60 do { deseneaza liniile pentru ceas }
begin
if (i mod 5 = 0) then
begin
angle4:=i*6-90;
rad4:=angle4*pi/180; {linii mari}
line( round(cos(rad4)*r+x),
round(sin(rad4)*r+y),
round(cos(rad4)*(r+20)+x),
round(sin(rad4)*(r+20)+y));
end
else
begin {lini mici}
angle4:=i*6-90;
rad4:=angle4*pi/180;
line( round(cos(rad4)*r+x),
round(sin(rad4)*r+y),
round(cos(rad4)*(r+10)+x),
round(sin(rad4)*(r+10)+y));
end;
end;
repeat
gettime(h,m,s,hund); { obtin ora curenta de la PC}
if temp<>s then
begin
setcolor(4);{culoarea rosie}
line(x, y, round(cos(rad)*(r-10)+x),
round(sin(rad)*(r-10)+y)); { DESENEAZA SECUNDELE }
line(x, y, round(cos(rad1)*(r-30)+x),
round(sin(rad1)*(r-30)+y)); { DESENEAZA ORELE }
line(x, y, round(cos(rad2)*(r-15)+x),
round(sin(rad2)*(r-15)+y)); { DESENEAZA MINUTELE }
Referinta:
M. Vlada, A,.Posea,…, Grafica pe calculator in limbajele Pascal si C, vol. II, , Implementare si
aplicatii, Ed. Tehnica,1992 pag. 3-94
program fractal_julia;
uses graph;
Type complex = object
x, y : real;
procedure InitializatCu( x1, y1 : real);
procedure InmultitCu( z : complex);
procedure AdunatCu( z : complex);
function raza : real;
end;
Const XMin = -2; {fereastra virtuala de afisare}
YMin = -0.81;
XMax = 2;
YMax = 0.81;
MaxRaza = 25;
MaxCulori = 30; {Numarul maxim de culori limiteaza si nr de
iteratii}
kz : complex = ( x:-1.3; y:0.1);
var Gd, Gm : integer;
{procedure initiaza}
procedure complex.InitializatCu( x1, y1 : real);
begin x := x1; y := y1; end;
{procedura inmulteste}
procedure complex.InmultitCu( z : complex );
var temp : complex;
begin
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
temp.InitializatCu( x*z.x-y*z.y, x*z.y+z.x*y );
x := temp.x; y := temp.y;
end;
{procedura aduna}
procedure complex.AdunatCu( z : complex );
begin x := x+z.x; y := y+z.y; end;
{functia raza}
function complex.raza : real;
begin raza := x*x + y*y; end;
{procedura julia}
procedure FractalJulia;
function culoare ( x, y : real) : byte;
var c : word;
z : complex;
begin
c := 1;
z.InitializatCu( x, y );
repeat
z.InmultitCu( z ); z.AdunatCu( kz );
c := c+1;
until (z.raza > MaxRaza) or (c = MaxCulori);
culoare := c:
end;
var x, y : integer;
ScalaX, Scalay : real;
begin
ScalaX := (XMax-XMin)/getmaxx;
ScalaY := (YMax-YMin)/getmaxy;
for x := 1 to getmaxx do
for y := 1 to getmaxy do
putPixel( x, y, culoare( XMin+x*ScalaX,YMin+y*ScalaY));
end;
begin
InitGraph( Gd, Gm, '' );
FractalJulia;
readln;
closeGraph;
end.
Referinta
M. Vlada, A,.Posea,…, Grafica pe calculator in limbajele Pascal si C, vol. II, , Implementare si
aplicatii, Ed. Tehnica,1992 pag. 3-94
program fractal_mandelbrot;
uses graph;
Type complex = object
x, y : real;
procedure InitializatCu( x1, y1 : real);
procedure InmultitCu( z : complex);
procedure AdunatCu( z : complex);
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
function raza : real;
end;
Const XMin = -2.7; {fereastra virtuala de afisare}
YMin = -1.5;
XMax = 1;
YMax = 1.5;
MaxRaza = 20;
MaxCulori = 32; {Numarul maxim de culori limiteaza si nr de
iteratii}
kz : complex = ( x:-1.3; y:0.1);
var Gd, Gm : integer;
procedure complex.InitializatCu( x1, y1 : real);
begin x := x1; y := y1; end;
procedure complex.InmultitCu( z : complex );
var temp : complex;
begin
temp.InitializatCu( x*z.x-y*z.y, x*z.y+z.x*y );
x := temp.x; y := temp.y;
end;
procedure complex.AdunatCu( z : complex );
begin x := x+z.x; y := y+z.y; end;
function complex.raza : real;
begin raza := x*x + y*y; end;
procedure FractalJulia;
function culoare ( x, y : real) : byte;
var c : word;
z : complex;
begin
c := 1;
z.InitializatCu( 0, 0 );
kz.InitializatCu( x, y );
repeat
z.InmultitCu( z ); z.AdunatCu( kz );
c := c+1;
until (z.raza > MaxRaza) or (c = MaxCulori);
culoare := c:
end;
var x, y : integer;
ScalaX, Scalay : real;
begin
ScalaX := (XMax-(XMin))/getmaxx;
ScalaY := (YMax-(YMin))/getmaxy;
for x := 1 to getmaxx do
for y := 1 to getmaxy do
putPixel( x, y, culoare( XMin+x*ScalaX,YMin+y*ScalaY));
end;
begin
InitGraph( Gd, Gm, '' );
FractalJulia;
readln;
closeGraph;
end.
else return b;
}
//3*******************************************************************
int trans(int n)//schimba din lui oy de la (sus in jos) la (jos in sus)
{
int r,i;
i=getmaxy();
r=i-n;
return r;
}
//3*****************************************************************
double rad(double n)//transforma grade in radian
{
return (double)M_PI*n/180;
}
//3*****************************************************************
void d3d2(double a,double b,double c,double x1,double y1,double z1,
double &x,double &y)
{
x=x1*cos(rad(a))+y1*cos(rad(b))+z1*cos(rad(c));
y=y1*sin(rad(a))+y1*sin(rad(b))+z1*sin(rad(c));
}
//3*****************************************************************
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
void defpoint(double *x,double *y,double *z)
{
x[0]=0; y[0]=0; z[0]=0;//originea
x[1]=100; y[1]=0; z[1]=0;//axa ox
x[2]=0; y[2]=100; z[2]=0;//axa oy
x[3]=0; y[3]=0; z[3]=100;//axa oy
//coord cubului
/*
x[4]=0; y[4]=0; z[4]=0; //1
x[5]=50; y[5]=0; z[5]=0; //2
x[6]=50; y[6]=0; z[6]=50; //3
x[7]=0; y[7]=0; z[7]=50; //4
x[8]=0; y[8]=50; z[8]=50; //5
x[9]=0; y[9]=50; z[9]=0; //6
x[10]=50; y[10]=50; z[10]=0; //7
x[11]=50; y[11]=50; z[11]=50; //8
*/
}
//3*****************************************************************
void desen(double *x,double *y,double *z)
{
double ox=getmaxx()/2,oy=getmaxy()/2,a,b,c,d;
/*
setcolor(15);
d3d2(0,90,225,x[0],y[0],z[0],a,b);
d3d2(0,90,225,x[1],y[1],z[1],c,d);
line(ox+round(a),trans(oy+round(b)),ox+round(c),trans(oy+round(d)));
d3d2(0,90,225,x[2],y[2],z[2],c,d);
line(ox+round(a),trans(oy+round(b)),ox+round(c),trans(oy+round(d)));
d3d2(0,90,225,x[3],y[3],z[3],c,d);
line(ox+round(a),trans(oy+round(b)),ox+round(c),trans(oy+round(d)));
*/
setcolor(4);
d3d2(0,90,225,x[4],y[4],z[4],a,b);
d3d2(0,90,225,x[5],y[5],z[5],c,d);
line(ox+round(a),trans(oy+round(b)),ox+round(c),trans(oy+round(d)));
d3d2(0,90,225,x[7],y[7],z[7],c,d);
line(ox+round(a),trans(oy+round(b)),ox+round(c),trans(oy+round(d)));
d3d2(0,90,225,x[9],y[9],z[9],c,d);
line(ox+round(a),trans(oy+round(b)),ox+round(c),trans(oy+round(d)));
d3d2(0,90,225,x[10],y[10],z[10],a,b);
d3d2(0,90,225,x[5],y[5],z[5],c,d);
line(ox+round(a),trans(oy+round(b)),ox+round(c),trans(oy+round(d)));
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
d3d2(0,90,225,x[11],y[11],z[11],c,d);
line(ox+round(a),trans(oy+round(b)),ox+round(c),trans(oy+round(d)));
d3d2(0,90,225,x[9],y[9],z[9],c,d);
line(ox+round(a),trans(oy+round(b)),ox+round(c),trans(oy+round(d)));
d3d2(0,90,225,x[6],y[6],z[6],a,b);
d3d2(0,90,225,x[5],y[5],z[5],c,d);
line(ox+round(a),trans(oy+round(b)),ox+round(c),trans(oy+round(d)));
d3d2(0,90,225,x[11],y[11],z[11],c,d);
line(ox+round(a),trans(oy+round(b)),ox+round(c),trans(oy+round(d)));
d3d2(0,90,225,x[7],y[7],z[7],c,d);
line(ox+round(a),trans(oy+round(b)),ox+round(c),trans(oy+round(d)));
d3d2(0,90,225,x[8],y[8],z[8],a,b);
d3d2(0,90,225,x[7],y[7],z[7],c,d);
line(ox+round(a),trans(oy+round(b)),ox+round(c),trans(oy+round(d)));
d3d2(0,90,225,x[11],y[11],z[11],c,d);
line(ox+round(a),trans(oy+round(b)),ox+round(c),trans(oy+round(d)));
d3d2(0,90,225,x[9],y[9],z[9],c,d);
line(ox+round(a),trans(oy+round(b)),ox+round(c),trans(oy+round(d)));
}
//3****************************************************************
void rot_oz(double &x,double &y,double &z,double grad)
{
double x1=x,y1=y,z1=z;
x=x1*cos(rad(grad))-y1*sin(rad(grad));
y=x1*sin(rad(grad))+y1*cos(rad(grad));
z=z1;
}
//3****************************************************************
void rot_ox(double &x,double &y,double &z,double grad)
{
double x1=x,y1=y,z1=z;
x=x1;
y=y1*cos(rad(grad))-z1*sin(rad(grad));
z=y1*sin(rad(grad))+z1*cos(rad(grad));
}
//3****************************************************************
void rot_oy(double &x,double &y,double &z,double grad)
{
double x1=x,y1=y,z1=z;
x=x1*cos(rad(grad))+z1*sin(rad(grad));
y=y1;
z=-x1*sin(rad(grad))+z1*cos(rad(grad));
}
//3****************************************************************
void rotplan(double xc,double yc,double zc,double &x,double &y,double
z,double unghi)
//cx,yc==punctul fata de care puctul x,y se roteste cu unghiul unghi
{
double x1=x,y1=y,z1=z;;
x=xc+(x1-xc)*cos(rad(unghi))-(y1-yc)*sin(rad(unghi));
y=yc+(x1-xc)*sin(rad(unghi))+(y1-yc)*cos(rad(unghi));
z=z1;
}
//3*****************************************************************
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
void main(void){
initg();
double xx[20],yy[20],zz[20],grad=270;
int i;
defpoint(xx,yy,zz);
setwritemode(1);
desen(xx,yy,zz);
//*
//***********************************
getch();
for(i=0;i<360;i++)
{
delay(1);
desen(xx,yy,zz);
rot_ox(xx[4],yy[4],zz[4],1);
rot_ox(xx[5],yy[5],zz[5],1);
rot_ox(xx[6],yy[6],zz[6],1);
rot_ox(xx[7],yy[7],zz[7],1);
rot_ox(xx[8],yy[8],zz[8],1);
rot_ox(xx[9],yy[9],zz[9],1);
rot_ox(xx[10],yy[10],zz[10],1);
rot_ox(xx[11],yy[11],zz[11],1);
desen(xx,yy,zz);
}
//***********************************
getch();
for(i=0;i<360;i++)
{
delay(1);
desen(xx,yy,zz);
rot_oy(xx[4],yy[4],zz[4],1);
rot_oy(xx[5],yy[5],zz[5],1);
rot_oy(xx[6],yy[6],zz[6],1);
rot_oy(xx[7],yy[7],zz[7],1);
rot_oy(xx[8],yy[8],zz[8],1);
rot_oy(xx[9],yy[9],zz[9],1);
rot_oy(xx[10],yy[10],zz[10],1);
rot_oy(xx[11],yy[11],zz[11],1);
desen(xx,yy,zz);
}
//***********************************
getch();
for(i=0;i<360;i++)
{
delay(1);
desen(xx,yy,zz);
rot_oz(xx[4],yy[4],zz[4],1);
rot_oz(xx[5],yy[5],zz[5],1);
rot_oz(xx[6],yy[6],zz[6],1);
rot_oz(xx[7],yy[7],zz[7],1);
rot_oz(xx[8],yy[8],zz[8],1);
rot_oz(xx[9],yy[9],zz[9],1);
rot_oz(xx[10],yy[10],zz[10],1);
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
rot_oz(xx[11],yy[11],zz[11],1);
desen(xx,yy,zz);
}
//***********************************
getch();
for(i=0;i<360;i++)
{
delay(10);
desen(xx,yy,zz);
rotplan(25,25,25,xx[4],yy[4],zz[4],1);
rotplan(25,25,25,xx[5],yy[5],zz[5],1);
rotplan(25,25,25,xx[6],yy[6],zz[6],1);
rotplan(25,25,25,xx[7],yy[7],zz[7],1);
rotplan(25,25,25,xx[8],yy[8],zz[8],1);
rotplan(25,25,25,xx[9],yy[9],zz[9],1);
rotplan(25,25,25,xx[10],yy[10],zz[10],1);
rotplan(25,25,25,xx[11],yy[11],zz[11],1);
desen(xx,yy,zz);
}
//***********************************
//*/
getch();
endg();
}
//9*****************************************************************
Arie.java
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public Arie(){
super("Aria poligonului");
initialize();
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
}
});
}
optiuni.add(itm1);
optiuni.add(itm2);
meniuBara.add(optiuni);
}
return meniuBara;
}
this.setMenuBar(getJMeniuBara());
this.getContentPane().setLayout(new java.awt.BorderLayout());
this.getContentPane().add(getCanvas(),
java.awt.BorderLayout.CENTER);
this.getContentPane().add(getJButton(),
java.awt.BorderLayout.SOUTH);
setVisible(true);
new Thread(){
public void run(){
while(getCanvas().getNumarPuncte()<3);
buton.setEnabled(true);
}
}.start();
}
Surface.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.JPanel;
public Surface(){
this.setBackground(Color.red);
this.addMouseListener(new MouseAdapter()
{
public void mousePressed(MouseEvent e){
if (!gata){
x[i] = e.getX();
y[i] = e.getY();
i++;
}
repaint();
}
});
}
Roza.java
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public Roza(){
super("Roza");
Dimension marimeEcran =
Toolkit.getDefaultToolkit().getScreenSize();
setSize(marimeEcran.width * 3/4, (int)(marimeEcran.height *
0.80));
setLocation(
marimeEcran.width / 2 - this.getWidth() / 2,
marimeEcran.height / 2 - this.getHeight() / 2-
(int)(marimeEcran.height*0.01));
initialize();
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
System.exit(0);
}
});
}
optiuni.add(itm1);
optiuni.add(itm2);
meniuBara.add(optiuni);
}
return meniuBara;
}
this.setMenuBar(getJMeniuBara());
this.getContentPane().setLayout(new java.awt.BorderLayout());
this.getContentPane().add(getCanvas(),
java.awt.BorderLayout.CENTER);
setVisible(true);
while(!pasValid(getPas()));
int pas = Integer.parseInt(x);
while(!petaleValid(getPetale()));
int petale = Integer.parseInt(y);
suprafata.setPas(pas);
suprafata.setPetale(petale);
}
Surface.java
import java.awt.*;
import java.awt.event.*;
public Surface(){
this.setBackground(Color.black);
}
g.drawLine((int)(Math.sin(cont)*200)+330,(int)(Math.cos(cont)*200)+240,
(int)(Math.sin(petale*cont)*200)+330,(int)(Math.cos(petale*cont)*200)+2
40);
cont = cont + Math.PI / pas;
}
}
init();
}
Cod VB
VERSION 5.00
Begin VB.Form Form1
AutoRedraw = -1 'True
BackColor = &H000080FF&
Caption = "Form1"
ClientHeight = 4725
ClientLeft = 165
ClientTop = 855
ClientWidth = 7335
DrawWidth = 3
LinkTopic = "Form1"
ScaleHeight = 315
ScaleMode = 3 'Pixel
ScaleWidth = 489
StartUpPosition = 3 'Windows Default
Begin VB.TextBox txt4
Height = 375
Left = 2160
TabIndex = 4
Top = 3360
Width = 1095
End
Begin VB.TextBox txt3
Height = 375
Left = 2160
TabIndex = 3
Top = 2760
Width = 1095
End
Begin VB.TextBox txt2
Height = 375
Left = 2160
TabIndex = 2
Top = 2160
Width = 1095
End
Begin VB.TextBox txt1
Height = 375
Left = 2160
TabIndex = 1
Top = 1560
Width = 1095
End
Begin VB.CommandButton Command1
Caption = "DESENEAZA"
Height = 375
Left = 5640
TabIndex = 0
Top = 4080
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
Width = 1335
End
Begin VB.Label Lbl5
Alignment = 2 'Center
BackColor = &H000080FF&
Caption = "ALGORITMUL LUI BRESENHAM PENTRU DREAPTA SI
CERC"
BeginProperty Font
Name = "MS Sans Serif"
Size = 12
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 735
Left = 1200
TabIndex = 9
Top = 120
Width = 5295
End
Begin VB.Label Lbl4
BackColor = &H000080FF&
Caption = "Dati y1 :"
BeginProperty Font
Name = "Times New Roman"
Size = 12
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 840
TabIndex = 8
Top = 3360
Width = 855
End
Begin VB.Label Lbl3
BackColor = &H000080FF&
Caption = "Dati y0 :"
BeginProperty Font
Name = "Times New Roman"
Size = 12
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 840
TabIndex = 7
Top = 2760
Width = 1215
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
End
Begin VB.Label Lbl2
BackColor = &H000080FF&
Caption = "Dati x1 :"
BeginProperty Font
Name = "Times New Roman"
Size = 12
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 840
TabIndex = 6
Top = 2160
Width = 855
End
Begin VB.Label Lbl1
BackColor = &H000080FF&
Caption = "Dati x0 :"
BeginProperty Font
Name = "Times New Roman"
Size = 12
Charset = 0
Weight = 700
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
Height = 375
Left = 840
TabIndex = 5
Top = 1560
Width = 855
End
Begin VB.Menu mnuDreapta
Caption = "&Dreapta"
End
Begin VB.Menu mnuCerc
Caption = "&Cerc"
End
Begin VB.Menu mnuExit
Caption = "&Exit"
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Dim ind As Integer
Dim dy As Double
Dim dx As Double
Dim m As Double
Dim y As Double
Dim d As Double
Dim pas As Boolean
Dim a, b As Double
Dim c, e As Double
Dim ypas As Integer
If (pas) Then
a = x0
x0 = y0
y0 = a
b = x1
x1 = y1
y1 = b
End If
If x0 > x1 Then
c = x0
x0 = x1
x1 = c
e = y0
y0 = y1
y1 = e
End If
dx = x1 - x0
dy = Abs(y1 - y0)
d = 0
m = dy / dx
y = y0
If y0 < y1 Then
ypas = 1
Else
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
ypas = -1
End If
For x = x0 To x1
If (pas) Then
PSet (y, x), QBColor(5)
Else
PSet (x, y), QBColor(4)
End If
d = d + m
Next x
txt1.Visible = False
txt2.Visible = False
txt3.Visible = False
txt4.Visible = False
Lbl1.Visible = False
Lbl2.Visible = False
Lbl3.Visible = False
Lbl4.Visible = False
End Sub
Dim y As Integer
Dim x As Integer
Dim dx As Integer
Dim dy As Integer
Dim f As Integer
f = 1 - r
dx = 0
dy = -2 * r
x = 0
y = r
PSet (x0, y0 + r)
PSet (x0, y0 - r)
PSet (x0 + r, y0)
PSet (x0 - r, y0)
While (x < y)
If (f >= 0) Then
y = y - 1
dy = dy + 2
f = f + dy
End If
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
x = x + 1
dx = dx + 2
f = f + dx + 1
PSet (x0 + x, y0 + y)
PSet (x0 - x, y0 + y)
PSet (x0 + x, y0 - y)
PSet (x0 - x, y0 - y)
PSet (x0 + y, y0 + x)
PSet (x0 - y, y0 + x)
PSet (x0 + y, y0 - x)
PSet (x0 - y, y0 - x)
Wend
txt1.Visible = False
txt2.Visible = False
txt3.Visible = False
txt4.Visible = False
Lbl1.Visible = False
Lbl2.Visible = False
Lbl3.Visible = False
Lbl4.Visible = False
End Sub
txt1.Text = ""
txt2.Text = ""
txt3.Text = ""
txt4.Text = ""
txt1.Visible = True
txt2.Visible = True
txt3.Visible = True
txt4.Visible = True
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
Lbl1.Visible = True
Lbl2.Visible = True
Lbl3.Visible = True
Lbl4.Visible = True
End Sub
Private Sub afisare_cerc()
ind = 1
txt1.Text = ""
txt2.Text = ""
txt3.Text = ""
txt1.Visible = True
txt2.Visible = True
txt3.Visible = True
txt4.Visible = False
Lbl1.Visible = True
Lbl2.Visible = True
Lbl3.Visible = True
Lbl4.Visible = False
End Sub
Visual C++
Program.cs
using System;
using System.Collections.Generic:
using System.Windows.Forms;
namespace Grafica
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
Form1.cs
using System;
using System.Collections.Generic:
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace Grafica
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
culoare = Color.Black;
InitBitmap();
}
switch (forma)
{
case 1:
{
Algorithms alg = new Algorithms();
alg.Bresenham_line(p0.X, p1.X, p0.Y, p1.Y, gr,
culoare);
break;
}
case 2:
{
Algorithms alg = new Algorithms();
double dist = Math.Sqrt(Math.Pow((p1.X - p0.X),
2) + Math.Pow((p1.Y - p0.Y), 2));
raza = (int)Math.Round(dist);
alg.rasterCircle(p0.X + (p1.X - p0.X) / 2, p0.Y
+ (p1.Y - p0.Y) / 2, raza / 2, gr, culoare);
break;
}
#region
//case 3:
// {
// Algorithms alg = new Algorithms();
// double dist = Math.Sqrt(Math.Pow((p1.X -
p0.X), 2) + Math.Pow((p1.Y - p0.Y), 2));
// raza = (int)Math.Round(dist);
// int raza1;
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
// double dist1 = Math.Sqrt(Math.Pow(raza, 2) -
Math.Pow(raza / 2, 2));
// raza1 = (int)Math.Round(dist1);
// alg.PlotEllipse(p0.X,p0.Y, raza / 2, 30, gr,
culoare);
// break;
// }
#endregion
}
}
}
}
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
Algorithms.cs
using System;
using System.Collections.Generic:
using System.Text;
using System.Drawing;
using System.Windows.Forms;
namespace Grafica
{
class Algorithms
{
public void Bresenham_line(int x0, int x1, int y0, int y1,
Graphics gr, Color culoare)
{
bool verif;
if (Math.Abs(y1 - y0) - Math.Abs(x1 - x0) > 0) verif =
true;
else verif = false;
if (verif)
{
int aux = x0;
x0 = y0;
y0 = aux;
aux = x1;
x1 = y1;
y1 = aux;
}
if (x0 > x1)
{
int aux = x0;
x0 = x1;
x1 = aux;
aux = y0;
y0 = y1;
y1 = aux;
}
while (x < y)
{
if (f >= 0)
{
y--;
ddF_y += 2;
f += ddF_y;
}
x++;
ddF_x += 2;
f += ddF_x + 1;
}
}
}
}
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
DecupareSegmente.java
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
class Point
{
double x,y;
Point(double thisx, double thisy)
{
x=thisx;
y=thisy;
}
Conf. Dr. Marin Vlada, Universitatea din Bucuresti
www.ad-astra.ro/marinvlada
}
Point P0,P1;
CvSegmente()
{
resize( xMax, yMax );
this.addMouseListener(new MouseAdapter(){
public void mousePressed(MouseEvent evt)
{
if(points == 0) { firstX=evt.getX(); firstY=evt.getY(); points++;}
else if (points == 1)
{lastX=evt.getX(); lastY=evt.getY(); points = 0;
P0 = new Point((double)firstX,(double)firstY);
P1 = new Point((double)lastX,(double)lastY);
paint(getGraphics());}
}});
show();
}
return Cod;
}