Hello, dear programmers! There are a couple of small problems: Similar to this program: the so-called Julia sets are graphically represented on the monitor. You need to do a couple of prog programs in C ++ Builder so that instead of ellipses the Paint Box space is filled with: 1) Points 2) Draws Besides the C ++ code of the 3rd part , there is a training manual for all 3 programs on Delphi Help please, I will be very grateful, gratitude in the form of money for mobile will not take long
Code of the 3rd part in C ++ Builder:
//--------------------------------------------------------------------------- #include <vcl.h> #pragma hdrstop #include "Unit1.h" #include <math.h> //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } float RE,IM,RE1,IM1; // вывод точки заданного цвета void TForm1::putpixel(int x, int y, int c) { TColor cc; switch (c % 8) { case 0:{cc=clBlack;break;} case 1:{cc=clRed;break;} case 2:{cc=clLime;break;} case 3:{cc=clYellow;break;} case 4:{cc=clBlue;break;} case 5:{cc=clFuchsia;break;} case 6:{cc=clAqua;break;} case 7:{cc=clWhite;break;} } PaintBox1->Canvas->Pixels[x][y] = cc; } void TForm1::KUB(void) { RE1=RE*(RE*RE-3*IM*IM); IM1=IM*(3*RE*RE-IM*IM); RE=RE1; IM=IM1; } //--------------------------------------------------------------------------- void __fastcall TForm1::Button1Click(TObject *Sender) { int i,x,y,V, X, Y, x2, y2; randomize(); PaintBox1->Canvas->Brush->Color = RGB(0,0,0); PaintBox1->Canvas->FillRect(Rect(0,0, 640,480)); for (i=1; i<300; i++) { x=random(100); y=random(100); PaintBox1->Canvas->Pixels[x][y]=RGB(random(255),random(255),random(255) ); PaintBox1->Canvas->Pen->Color = RGB(random(255),random(255),random(255)); PaintBox1->Canvas->Pen->Width = random(3)+1; x = random(100); y = random(100); PaintBox1->Canvas->MoveTo(x,y); x = random(100); y = random(100); PaintBox1->Canvas->LineTo(x,y); // цвет и ширина каймы будущего эллипса PaintBox1->Canvas->Pen->Color = RGB(random(255),random(255),random(255)) ; PaintBox1->Canvas->Pen->Width = random(3)+1; // цвет заливки внутренности эллипса PaintBox1->Canvas->Brush->Color = RGB(random(255),random(255),random(255)) ; // координаты углов прямоугольника, в который вписывается эллипс x = random(150); y = random(150); x2 = random(150); y2 = random(150); // впиисываем эллипс //PaintBox1->Canvas->Ellipse(x,y,x2,y2); PaintBox1->Canvas->FillRect(Rect(x,y,x2,y2)); } // Множества Жюлиа PaintBox1->Canvas->Brush->Color = RGB(0,0,0); PaintBox1->Canvas->FillRect(Rect(0,0, 640,480)); X=-320 ; do { Y=-240 ; do { V=0 ; RE=-1.+0.001*X ; IM=0+0.001*Y ; do { KUB(); RE=RE+1.00003 ; IM=IM+1.01828201638 ; if (RE*RE > 50) break; if (IM*IM > 50) break; V=V+1 ; } while (V<40) ; if (( abs(RE) > 10 ) || ( abs(IM) > 1000) ) { putpixel((X+320),(Y+240),V) ; } else putpixel((X+320),(Y+240),0); Y=Y+1 ; } while (Y < 241) ; X=X+1 ; } while (X < 320) ; } //--------------------------------------------------------------------------- Manual of all 3 prog on Delphi
Для рисования статичных рисунков используется компонент PaintBox (панель System). Этот компонент размещается на форме в виде прозрачного пунктирного квадрата, и в его пределах можно рисовать. Рисование выполняется обращением к свойству Canvas (графическая канва) этого компонента: PaintBox1.Canvas. У него в свою очередь есть свойство Pixels (PaintBox1.Canvas.Pixels), которое представляет собой матрицу, двумерный массив заданного размера - поточечный образ канвы, каждый элемент - отдельная точка. В Pixels[] отсчет точек (пикселов экрана) начинается с 0. Координаты x, y отсчитываются от верхнего левого угла, то есть он считается точкой с координатой (0, 0), увеличение по оси x идет слева направо, а по оси y - сверху вниз. Для конкретной точки указывается цвет. Функция RGB() формирует цвет комбинацией интенсивности красного, зеленого и синего (интенсивность задается числом от 0 до 255). For example, black - RGB (0,0,0), red - rgb (255,0,0), blue - rgb (0,0,255), white - rgb (255,255,255). The purpose of the work is to create a program that performs the following actions: 1. Place the PaintBox component on the form. 2. Fill the available outline with 300 red dots in random positions by pressing a certain button. 3. To exit the program, click on the closing button in the title bar. 4. Write the code in the click handler.
Fig. one
procedure TForm1.Button1Click(Sender: TObject); var i,x,y: Integer; begin randomize; for i := 1 to 300 do begin x := random(100); y := random(100); PaintBox1.Canvas.Pixels[x,y] := RGB(255,0,0); end end; - Change RGB (255,0,0) to RGB (random (255), random (255), random (255)).
Fig. 2
- Fill the background with black color before starting the program execution using the FillRect canvas method. The method is called with the indication of the rectangular area of the color fill: FillRect (Rect (0, 0, 100, 100)) // coordinates of the upper left and right lower corners. The enclosed word Rect forms the given "rectangle" type. Before calling FillRect, you must specify the fill color: PaintBox1.Canvas.Brush.Color: = RGB (0,0,0);
Fig. 3
procedure TForm1.Button1Click(Sender: TObject); var i,x,y: Integer; begin PaintBox1.Canvas.Brush.Color := RGB(0,0,0); PaintBox1.Canvas.FillRect(Rect(0,0,100,100)); for i := 1 to 300 do begin x := random(100); y := random(100); PaintBox1.Canvas.Pixels[x,y] := RGB(random(255),random(255),random(255)); end end; 7. Заполнить канву случайными разноцветными линиями разной толщины. Линия рисуется с помощью методов (сначала задается начальная точка, потом конечная): PaintBox1.Canvas.MoveTo(10,10); PaintBox1.Canvas.LineTo(50,50); Line color and thickness are set by the Pen property (pencil). Pen.Color is the color of the pencil) Pen.Width is the thickness of the line in pixels (1 by default).
Fig. four
for i := 1 to 300 do begin PaintBox1.Canvas.Pen.Color := RGB(random(255),random(255),random(255)); PaintBox1.Canvas.Pen.Width := random(3)+1; x := random(100); y := random(100); PaintBox1.Canvas.MoveTo(x,y); x := random(100); y := random(100); PaintBox1.Canvas.LineTo(x,y); end - Fill the canvas with ellipses at random (circles, circles - a special case of an ellipse). Ellipses are drawn using the Ellipse () method with four parameters — the coordinates of the upper left and right lower corners of the rectangle into which the ellipse fits. The border of the ellipse is drawn in accordance with the parameters of the Pen property of the canvas, and the ellipse inside is filled with the color of the brush Brush of the canvas.
Fig. five.
for i := 1 to 300 do begin // цвет и ширина каймы будущего эллипса PaintBox1.Canvas.Pen.Color := RGB(random(255),random(255),random(255)) ; PaintBox1.Canvas.Pen.Width := random(3)+1; // цвет заливки внутренности эллипса PaintBox1.Canvas.Brush.Color := rgb(random(255),random(255),random(255)) ; // координаты углов прямоугольника, в который вписывается эллипс x := random(150); y := random(150); x2 := random(150); y2 := random(150); // вписываем эллипс PaintBox1.Canvas.Ellipse(x,y,x2,y2); end; - Make an outline on the whole screen. Fill with multi-colored rectangles in random positions and random sizes using FillRect ().
- Create a graphic image of the so-called Julia set.
procedure TForm1.Button1Click(Sender: TObject); var RE,IM,RE1,IM1: REAL ; V,X,Y : INTEGER; // вывод точки заданного цвета procedure PUTPIXEL(x,y,c:Integer); var cc: TColor; begin case c mod 8 of 0:cc:=clBlack; 1:cc:=clRed; 2:cc:=clLime; 3:cc:=clYellow; 4:cc:=clBlue; 5:cc:=clFuchsia; 6:cc:=clAqua; 7:cc:=clWhite; end; PaintBox1.Canvas.Pixels[x,y] := cc; end; procedure QWA ; begin RE1:=RE*RE-IM*IM; IM1:=2*RE*IM; RE:=RE1; IM:=IM1; end; procedure KUB; begin RE1:=RE*(RE*RE-3*IM*IM); IM1:=IM*(3*RE*RE-IM*IM); RE:=RE1; IM:=IM1; end ; Begin PaintBox1.Canvas.Brush.Color := rgb(0,0,0); PaintBox1.Canvas.FillRect(Rect(0,0,640,480)); X:=-320 ; REPEAT Y:=-240 ; REPEAT V:=0 ; RE:=-1.+0.001*X ; IM:=0+0.001*Y ; REPEAT KUB; RE:=RE+1.00003 ; IM:=IM+1.01828201638 ; if RE*RE > 50 then break; if IM*IM > 50 then break; V:=V+1 ; UNTIL V>40 ; if ( ABS(RE) > 10 ) or ( ABS(IM) > 1000) then begin PUTPIXEL((X+320),(Y+240),TRUNC(V)) ; end else PUTPIXEL((X+320),(Y+240),0); Y:=Y+1 ; UNTIL Y > 241 ; X:=X+1 ; UNTIL X>320 ; End;