#ifndef m_treeH
#define m_treeH
//---------------------------------------------------------------------------
#include <stdlib.h>
#include <time.h>
#include <vcl.h>
class draw_Tree
{
private:
float x1[5],x2[5],x3[5],x4[5],x5[6],x6[6],x7[6],x8[6],x9[6],
x10[6],x11[6],x12[6];
TForm *tf;
public:
draw_Tree();
void init_Date();
void Draw(TForm *form);
} ;
#endif
file - m_tree.cpp
#include <stdlib.h>
#include <time.h>
#include <vcl.h>
#pragma hdrstop
#include "m_tree.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#define my_MAX 65535
draw_Tree::draw_Tree()
{
srand(time(NULL));
}
void draw_Tree::init_Date()
{
int i,value,temp;
for(i=0;i<5;i++)
{
value=rand()%100+1;
temp=rand()%7;
x1[i]=(1.0*value/100.);
if(temp<4)
x1[i]*=-1.;
x2[i]=(1.0*value/100.);
if(temp<4)
x2[i]*=-1.;
x3[i]=(1.0*value/100.);
if(temp<4)
x3[i]*=-1.;
x4[i]=(1.0*value/100.);
if(temp<4)
x4[i]*=-1.;
x5[i]=(1.0*value/100.);
if(temp<4)
x5[i]*=-1.;
x6[i]=(1.0*value/100.);
if(temp<4)
x6[i]*=-1.;
x7[i]=(1.0*value/100.);
if(temp<4)
x7[i]*=-1.;
x8[i]=(1.0*value/100.);
if(temp<4)
x8[i]*=-1.;
x9[i]=(1.0*value/100.);
if(temp<4)
x9[i]*=-1.;
x10[i]=(1.0*value/100.);
if(temp<4)
x10[i]*=-1.;
x11[i]=(1.0*value/100.);
if(temp<4)
x11[i]*=-1.;
x12[i]=(1.0*value/100.);
if(temp<4)
x12[i]*=-1.;
}
}
void draw_Tree::Draw(TForm *form)
{
int i,j,k;
float vx_value,vy_value;
tf=form;
vx_value=rand()%my_MAX+1;
vy_value=rand()%my_MAX+1;
i=0;
do
{
j=rand()%8;
switch(j)
{
case 0:
vx_value=vx_value*x1[0]+vy_value*x2[0]+x3[0];
vy_value=vx_value*x4[0]+vy_value*x5[0]+x6[0];
break;
case 1:
vx_value=vx_value*x1[1]+vy_value*x2[1]+x3[1];
vy_value=vx_value*x4[1]+vy_value*x5[1]+x6[1];
break;
case 2:
vx_value=vx_value*x1[2]+vy_value*x2[2]+x3[2];
vy_value=vx_value*x4[2]+vy_value*x5[2]+x6[2];
break;
case 3:
vx_value=vx_value*x1[3]+vy_value*x2[3]+x3[3];
vy_value=vx_value*x4[3]+vy_value*x5[3]+x6[3];
break;
case 4:
vx_value=vx_value*x7[0]+vy_value*x8[0]+x9[0];
vy_value=vx_value*x10[0]+vy_value*x11[0]+x12[0];
break;
case 5:
vx_value=vx_value*x7[1]+vy_value*x8[1]+x9[1];
vy_value=vx_value*x10[1]+vy_value*x11[1]+x12[1];
break;
case 6:
vx_value=vx_value*x7[2]+vy_value*x8[2]+x9[2];
vy_value=vx_value*x10[2]+vy_value*x11[2]+x12[2];
break;
case 7:
vx_value=vx_value*x7[3]+vy_value*x8[3]+x9[3];
vy_value=vx_value*x10[3]+vy_value*x11[3]+x12[3];
break;
}
tf->Canvas->Pixels[0.5*tf->Width+Floor(5*vx_value)]
[0.5*tf->Height-Floor(5*vy_value)]=clGreen;
++i;
}while(i<(5.*my_MAX));
}
Use class in the programm :
void __fastcall TForm1::Button1Click(TObject *Sender)
{
draw_Tree DRAW;
DRAW.init_Date();
DRAW.Draw(Form1);
}
Brak komentarzy:
Prześlij komentarz