133 lines
4.5 KiB
C++
133 lines
4.5 KiB
C++
//---------------------------------------------------------------------------
|
|
|
|
#include <vcl.h>
|
|
#pragma hdrstop
|
|
#include <math.h>
|
|
#include "Unit1.h"
|
|
//---------------------------------------------------------------------------
|
|
#pragma package(smart_init)
|
|
#pragma resource "*.dfm"
|
|
TForm1 *Form1;
|
|
const int S = 60; //êîë-âî âåòîê
|
|
const int N = 60; //ãèáêîñòü
|
|
const float L = 0.5; //ìàñøòàá
|
|
const int U = 5; //ñêîðîñòü
|
|
float a[N];
|
|
int colormode;
|
|
bool bl = true;
|
|
int r=0,g=255,b=128;
|
|
int mode = 0;
|
|
float x, y, tx, ty, k, d, len;
|
|
//---------------------------------------------------------------------------
|
|
__fastcall TForm1::TForm1(TComponent* Owner)
|
|
: TForm(Owner)
|
|
{
|
|
|
|
}
|
|
void color() {
|
|
if(mode==0) {
|
|
r--;
|
|
if(r<=30) mode++;
|
|
}else if(mode==1) {
|
|
g++;
|
|
if(g>=255) mode++;
|
|
}else if(mode==2) {
|
|
b++;
|
|
if(b>=255) mode++;
|
|
}else if(mode==3) {
|
|
r--; g--;
|
|
if(r<=30 || g<=30) mode++;
|
|
}else if(mode==4) {
|
|
g++; b--;
|
|
if(g>=255 || b<=30) {
|
|
mode=0;
|
|
}
|
|
}//else
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
float frand() {
|
|
randomize();
|
|
return (float) ((float)random(100)/100);
|
|
}
|
|
void __fastcall TForm1::FormPaint(TObject *Sender)
|
|
{
|
|
int width = ClientWidth;
|
|
int height = ClientHeight;
|
|
if (width > height) {
|
|
len = (float) (height / L / N);
|
|
} else {
|
|
len = (float) (width / L / N);
|
|
}
|
|
randomize();
|
|
if(random(4)==2) colormode = random(12);
|
|
//Áëîê èçìåíåíèÿ öâåòà
|
|
color();
|
|
//Áëîê ïîäãîòîâêè ýêðàíà è öâåòîâ
|
|
TRect aRect = Rect(0,0,ClientWidth,ClientHeight);
|
|
Canvas->Brush->Color=(TColor) 0;//random(0xffffff);
|
|
Canvas->FillRect(aRect);
|
|
Canvas->Pen->Color=(TColor) RGB(r,g,b);//random(0x999999)+0x444444;
|
|
//Äâèæîê âèçóàëèçàöèè
|
|
k = (float) (abs(frand() * 360) * M_PI / 180);
|
|
float r50 = (float) (abs(frand() * 50));
|
|
d = (float) (M_PI * 2 / S);
|
|
if (r50 < 2) {
|
|
k = (float) (abs(frand() * 1440) * M_PI / 180);
|
|
}
|
|
a[0] = (float) (a[0] + sin(k)/U);
|
|
for(int i = 1; i<N; i++) {
|
|
a[i] = (float) (a[i]+(a[i-1]-a[i])*0.1);
|
|
}
|
|
for(int j = 0; j<S; j++) {
|
|
x = (float) (0.5 * width);
|
|
y = (float) (0.5 * height);
|
|
for(int i = 1; i<N; i++) {
|
|
tx = (float) (x + sin(j*d+a[i])*len);
|
|
ty = (float) (y + cos(j*d+a[i])*len);
|
|
switch(colormode) {
|
|
case 0: Canvas->Pen->Color=(TColor)RGB((255 - 255 * i / N), 255 * i / N, 0); break;
|
|
case 1: Canvas->Pen->Color=(TColor)RGB(b, 255, (255 - 255 * i / N)); break;
|
|
case 2: Canvas->Pen->Color=(TColor)RGB(255, (255 - 255 * i / N), 0); break;
|
|
case 3: Canvas->Pen->Color=(TColor)RGB(r, (255 - 255 * i / N), 255); break;
|
|
case 4: Canvas->Pen->Color=(TColor)RGB((255 - 255 * i / N), 255, 0); break;
|
|
case 5: Canvas->Pen->Color=(TColor)RGB((255 - 255 * i / N), (255 - 255 * i / N), 255); break;
|
|
case 6: Canvas->Pen->Color=(TColor)RGB((255 - 255 * i / N), 255, 255); break;
|
|
case 7: Canvas->Pen->Color=(TColor)RGB(0, 255, (255 - 255 * i / N)); break;
|
|
case 8: Canvas->Pen->Color=(TColor)RGB(255, g, (255 - 255 * i / N)); break;
|
|
case 9: Canvas->Pen->Color=(TColor)RGB(255, (255 - 255 * i / N), (255 - 255 * i / N)); break;
|
|
case 10: Canvas->Pen->Color=(TColor)RGB(r, (255 - 255 * i / N), 0); break;
|
|
case 11: Canvas->Pen->Color=(TColor)RGB(255, (255 - 255 * i / N), 255); break;
|
|
case 12: Canvas->Pen->Color=(TColor)RGB((255 - 255 * i / N), 0, 255); break;
|
|
}
|
|
|
|
//Canvas->Brush->Color=Canvas->Pen->Color;
|
|
//Canvas->FillRect(Rect(x,y,tx,ty));
|
|
//Canvas->Arc(x,y,tx,ty,x+ty,y+tx,x+tx,y+ty);
|
|
//Canvas->Ellipse(x,y,x+tx,y+ty);
|
|
Canvas->MoveTo(x,y);
|
|
Canvas->LineTo(x=tx,y=ty);
|
|
}
|
|
}
|
|
//Ïàóçà
|
|
Sleep(50);
|
|
if(!bl) FormPaint(this);
|
|
}
|
|
//-------------------------------------------------------------------------
|
|
|
|
void __fastcall TForm1::FormMouseUp(TObject *Sender, TMouseButton Button,
|
|
TShiftState Shift, int X, int Y)
|
|
{
|
|
bl = !bl;
|
|
FormPaint(this);
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|
|
void __fastcall TForm1::FormMouseDown(TObject *Sender, TMouseButton Button,
|
|
TShiftState Shift, int X, int Y)
|
|
{
|
|
/*bl = !b1;
|
|
FormPaint(this); */
|
|
}
|
|
//---------------------------------------------------------------------------
|
|
|