Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

Восстановить пароль
Повторная активизация e-mail

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 21.04.2008, 16:48   #1
Ratte
 
Регистрация: 21.04.2008
Сообщений: 5
По умолчанию Вращение 5-угольника на рабочем столе

Здравствуйте, помогите пожалуста. Нужно создать вращающийся 5-уголник на рабочем столе, выдает ошибку, что используеться не тот тип данных. Вот код, проверьте пожалуста.

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, Buttons;

type
TForm1 = class(TForm)
Button1: TButton;
Timer1: TTimer;
procedure Timer1Timer(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
tpoint=record
grad, radius, x, y: integer;
radian: real;
end;
const
dtr=0.0174;
x0=220;
y0=220;
var
Form1: TForm1;

implementation

{$R *.dfm}
function GetRGB():Integer;
begin
Randomize;
GetRGB:=RGB(Random(255),Random(255) ,Random(255));
end;
procedure TForm1.Timer1Timer(Sender: TObject);
var
pol: array[1..5] of tpoint;
ScreenDC: HDC;
Canvas: TCanvas;
i: Integer;
buffer: tbitmap;
begin
Timer1.Interval:= 175;
Timer1.Enabled:=True;
Canvas:=TCanvas.Create;
ScreenDC:=GetDC(0);
Canvas.Handle:=ScreenDC;
Canvas.Brush.Color:=GetRGB;
for i:=1 to 5 do
begin
pol[i].radian:=pol[i].grad*dtr;
pol[i].x:=x0+round(cos(pol[i].radian)*pol[i].radius);
pol[i].y:=y0+round(sin(pol[i].radian)*pol[i].radius);
end;
with buffer.Canvas do
begin
Handle:=GetDC(0);
Canvas.MoveTo(pol[1].x, pol[1].y);
Canvas.LineTo(pol[1].x, pol[1].y);
Canvas.MoveTo(pol[2].x, pol[2].y);
Canvas.LineTo(pol[2].x, pol[2].y);
Canvas.MoveTo(pol[3].x, pol[3].y);
Canvas.LineTo(pol[3].x, pol[3].y);
Canvas.MoveTo(pol[4].x, pol[4].y);
Canvas.LineTo(pol[4].x, pol[4].y);
Canvas.MoveTo(pol[5].x, pol[5].y);
Canvas.LineTo(pol[5].x, pol[5].y);
end;
Canvas.Draw(0, 0, buffer);
for i:=1 to 5 do
begin
inc(pol[i].grad);
if pol[i].grad>360 then pol[i].grad:=0;
end;

SetLength(pol, 20);
pol[1].grad := 400;
pol[1].radius := 500;
pol[2].grad := 200;
pol[2].radius := 300;
pol[3].grad := 300;
pol[3].radius := 100;
pol[4].grad := 500;
pol[4].radius := 100;
pol[5].grad := 600;
pol[5].radius := 300;
Canvas.Polygon(pol);
ReleaseDC(0,ScreenDC );
Canvas.Free;
end;
end.
Ratte вне форума Ответить с цитированием
Старый 21.04.2008, 17:04   #2
Stilet
Белик Виталий :)
Старожил
 
Аватар для Stilet
 
Регистрация: 23.07.2007
Сообщений: 57,097
По умолчанию

В какой строке.
I'm learning to live...
Stilet вне форума Ответить с цитированием
Старый 21.04.2008, 17:12   #3
K@$K@
Пользователь
 
Аватар для K@$K@
 
Регистрация: 03.08.2007
Сообщений: 26
По умолчанию

Ты используешь свой тип TPoint, а функции нужен стандартный
TPoint=record
x : integer;
y : integer;
end;

SetLength(pol, 20);- нельзя изменять размер не динамического массива, аообще не понимаю заче это здесь.

вот так вот можно решить, только что то утебя считает не правельно.
Код:
  tpoints=record
grad, radius, x, y: integer;
radian: real;
end;

const
dtr=0.0174;
x0=220;
y0=220;



var
  Form1: TForm1;

implementation

function GetRGB():Integer;
begin
Randomize;
GetRGB:=RGB(Random(255),Random(255),Random(255));
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var
pol: array[1..5] of tpoints;
pol2: array[1..5] of tpoint;
ScreenDC: HDC;
Canvas: TCanvas;
i: Integer;
buffer: tbitmap;
begin
Timer1.Interval:= 175;
Timer1.Enabled:=True;
Buffer:=TBitmap.Create;
Canvas:=TCanvas.Create;
ScreenDC:=GetDC(0);
Canvas.Handle:=ScreenDC;
Canvas.Brush.Color:=GetRGB;
for i:=1 to 5 do
begin
pol[i].x:=x0+round(cos(pol[i].radian)*pol[i].radius);
pol[i].y:=y0+round(sin(pol[i].radian)*pol[i].radius);

pol2[i].x:=x0+round(cos(pol[i].radian)*pol[i].radius);
pol2[i].y:=y0+round(sin(pol[i].radian)*pol[i].radius);
end;
with buffer.Canvas do
begin
Handle:=GetDC(0);
Canvas.MoveTo(pol[1].x, pol[1].y);
Canvas.LineTo(pol[1].x, pol[1].y);
Canvas.MoveTo(pol[2].x, pol[2].y);
Canvas.LineTo(pol[2].x, pol[2].y);
Canvas.MoveTo(pol[3].x, pol[3].y);
Canvas.LineTo(pol[3].x, pol[3].y);
Canvas.MoveTo(pol[4].x, pol[4].y);
Canvas.LineTo(pol[4].x, pol[4].y);
Canvas.MoveTo(pol[5].x, pol[5].y);
Canvas.LineTo(pol[5].x, pol[5].y);
end;
for i:=1 to 5 do
begin
inc(pol[i].grad);
if pol[i].grad>360 then pol[i].grad:=0;
end;

pol[1].grad := 400;
pol[1].radius := 500;
pol[2].grad := 200;
pol[2].radius := 300;
pol[3].grad := 300;
pol[3].radius := 100;
pol[4].grad := 500;
pol[4].radius := 100;
pol[5].grad := 600;
pol[5].radius := 300;
Canvas.Draw(0, 0, buffer);
Canvas.Polygon(pol2);
ReleaseDC(0,ScreenDC );
Canvas.Free;
end;

Последний раз редактировалось K@$K@; 21.04.2008 в 17:27.
K@$K@ вне форума Ответить с цитированием
Старый 21.04.2008, 17:22   #4
Ratte
 
Регистрация: 21.04.2008
Сообщений: 5
По умолчанию

SetLength(pol);(79 строка)

и

Canvas.Polygon(pol);(90 строка)
Ratte вне форума Ответить с цитированием
Старый 21.04.2008, 17:26   #5
Карась
Участник клуба
 
Аватар для Карась
 
Регистрация: 26.10.2007
Сообщений: 1,244
По умолчанию

Както всё сложно и запутанно...

Код:
Const Pi = 3.1415926;

var
  Form1: TForm1;
  H : HDC;
  x, y, i, n, R :integer;
  GV : array [1..10, 1..10] of Real;
  a : Real;
  Procedure PrintM;

implementation

{$R *.dfm}

procedure TForm1.Timer1Timer(Sender: TObject);
begin
For i := 1 To (n + 1) Do
LineTo(H, Round(GV[i,1]) + 450, Round(GV[i,2]) + 450);
a := a + 10;
PrintM;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
PrintM;
H := GetDC(0);
end;

Procedure PrintM;
var z : Integer;
Begin
n := 6; R := 100;
For z := 1 To n Do
  Begin
    GV[z,1] := R * cos(a * Pi/180);
    GV[z,2] := R * sin(a * Pi/180);
    a := a + 360/n;
  End;
GV[n + 1,1] := GV[1,1];
GV[n + 1,2] := GV[1,2];
End;

end.
Можно взять за основу.
Умом Россию не понять, пока не выпито ноль пять,
А если выпито ноль пять всё делом кажется не хитрым,
Попытка глубже понимать уже попахивает литром...
Карась вне форума Ответить с цитированием
Старый 21.04.2008, 18:27   #6
Ratte
 
Регистрация: 21.04.2008
Сообщений: 5
По умолчанию

Вообщето ты просто вывел на изображение, последнее значение в цикле
pol2[i].x:=x0+round(cos(pol[i].radian)*pol[i].radius);
pol2[i].y:=y0+round(sin(pol[i].radian)*pol[i].radius);
т.к. дальше они ни где не фигурируют, а все операции, проходят с "pol[i]",
вот его то мне и надо вывести на экран.
Ratte вне форума Ответить с цитированием
Старый 21.04.2008, 18:39   #7
Ratte
 
Регистрация: 21.04.2008
Сообщений: 5
По умолчанию

Есть еще у кого какие идеи???
Ratte вне форума Ответить с цитированием
Старый 21.04.2008, 18:41   #8
Карась
Участник клуба
 
Аватар для Карась
 
Регистрация: 26.10.2007
Сообщений: 1,244
По умолчанию

Цитата:
Сообщение от Ratte Посмотреть сообщение
Есть еще у кого какие идеи???
А чем не нравится идея в 5-ом посте?
Умом Россию не понять, пока не выпито ноль пять,
А если выпито ноль пять всё делом кажется не хитрым,
Попытка глубже понимать уже попахивает литром...
Карась вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц



Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Вращение 5-угольника..? Roberto Помощь студентам 4 17.04.2008 09:38
Значки на рабочем столе Xardas Свободное общение 4 01.03.2008 20:21
Создать окно на рабочем столе AidarBik Win Api 19 09.02.2008 17:47
SpeedButton на рабочем столе ERASERROR Общие вопросы Delphi 10 22.01.2008 16:58
html на рабочем столе >AdepT< Win Api 4 28.02.2007 20:06