Registriert seit: 10. Aug 2007
609 Beiträge
FreePascal / Lazarus
|
Re: Muss einen Kompass programmieren...
22. Nov 2007, 09:39
Ui, sowas macht ihr in Info?
Ist ja imho mehr Mathe als Info...
Zitat von volcano57:
müssen wir ein programm schreiben, wo auf der zeichenfläche 2 kompasse erscheinen und wo die zeiger sich immer zur maus drehen, die maus bildet also egal wo sie sich grade auf der zeichenfläche befindet den Nordpol.
So, hatte langeweile und wollte eh meine Kenntnisse in Kreis/Dreiecksberechnungen mal wieder auffrischen. doppelnutzen kann ja nie Schaden )
Falls etwas nicht passt, kannst du ja etwas zur Übung umschreiben.
Kopier den Haufen mal in den Quelltext als Onmousemove-Ereignis von der Form.
Delphi-Quellcode:
procedure TForm1.FormMouseMove(Sender:TObject;Shift:TShiftState;X,Y:Integer);
const radius=100; //Hier kannst du die Größe der Kreise bestimmen!
begin
Canvas.MoveTo(round(Form1.Width/2+radius),round(Form1.Height/2));Canvas.Ellipse(round(Form1.Width/2+radius-radius),round(Form1.Height/2-radius),round(Form1.Width/2+radius+radius),round(Form1.Height/2+radius));
if(Form1.Width/2+radius-x)<>0then
begin
if(Floor(Sqrt(Power(Form1.Width/2+radius+Form1.Left+4-Mouse.CursorPos.X,2)+Power(Form1.Height/2+Form1.Top+30-Mouse.CursorPos.Y,2)))>radius-1)then
begin
if(x<Form1.Width/2+radius)then Canvas.LineTo(round(Form1.Width/2+radius-Cos(round(RadToDeg(ArcTan((Form1.Height/2-y)/(Form1.Width/2+radius-x))))*0.017453277)*radius),round(Form1.Height/2-Sin(round(RadToDeg(ArcTan((Form1.Height/2-y)/(Form1.Width/2+radius-x))))*0.017453277)*radius))
else if(x>=Form1.Width/2+radius)then
begin
if(y<Form1.Height/2)and(x=Form1.Width/2+radius)then Canvas.LineTo(round(Form1.Width/2+radius+Cos(round(RadToDeg(ArcTan((Form1.Height/2-y) / (Form1.Width/2+radius-x))))*0.017453277)*radius),round(Form1.Height/2+Sin(round(RadToDeg(ArcTan((Form1.Height/2-y)/(Form1.Width/2+radius-x))))*0.017453277)*radius)-radius*2)
else Canvas.LineTo(round(Form1.Width/2+radius+Cos(round(RadToDeg(ArcTan((Form1.Height/2-y)/(Form1.Width/2+radius-x))))*0.017453277)*radius),round(Form1.Height/2+Sin(round(RadToDeg(ArcTan((Form1.Height/2-y)/(Form1.Width/2+radius-x))))*0.017453277)*radius))
end else Canvas.LineTo(Mouse.CursorPos.X-Form1.Left-4,Mouse.CursorPos.Y-Form1.Top-30);
end else Canvas.LineTo(Mouse.CursorPos.X-Form1.Left-4,Mouse.CursorPos.Y-Form1.Top-30);
end else
begin
if(Floor(Sqrt(Power(Form1.Width/2+radius+Form1.Left+4-Mouse.CursorPos.X,2)+Power(Form1.Height/2+Form1.Top+30-Mouse.CursorPos.Y,2)))>radius-1)then
begin
if(x<Form1.Width/2+radius)then Canvas.LineTo(round(Form1.Width/2+radius-0.000001326794896*radius),round(Form1.Height/2-0.99999999999912*radius))
else if(x>=Form1.Width/2+radius)then
begin
if(y<Form1.Height/2)and(x=Form1.Width/2+radius)then Canvas.LineTo(round(Form1.Width/2+radius+0.000001326794896*radius),round(Form1.Height/2+0.99999999999912*radius)-radius*2)
else Canvas.LineTo(round(Form1.Width/2+radius+0.000001326794896*radius),round(Form1.Height/2+0.99999999999912*radius))
end else Canvas.LineTo(Mouse.CursorPos.X-Form1.Left-4,Mouse.CursorPos.Y-Form1.Top-30);
end else Canvas.LineTo(Mouse.CursorPos.X-Form1.Left-4,Mouse.CursorPos.Y-Form1.Top-30);
end; Canvas.MoveTo(round(Form1.Width/2-radius),round(Form1.Height/2)); Canvas.Ellipse(round(Form1.Width/2-radius-radius),round(Form1.Height/2-radius),round(Form1.Width/2-radius+radius),round(Form1.Height/2+radius));
if(Form1.Width/2-radius-x)<>0then
begin
if(Floor(Sqrt(Power(Form1.Width/2-radius+Form1.Left+4-Mouse.CursorPos.X,2)+Power(Form1.Height/2+Form1.Top+30-Mouse.CursorPos.Y,2)))>radius-1)then
begin
if(x<Form1.Width/2-radius)then Canvas.LineTo(round(Form1.Width/2-radius-Cos(round(RadToDeg(ArcTan((Form1.Height/2-y)/(Form1.Width/2-radius-x))))*0.017453277)*radius),round(Form1.Height/2-Sin(round(RadToDeg(ArcTan((Form1.Height/2-y)/(Form1.Width/2-radius-x))))*0.017453277)*radius))
else if(x>=Form1.Width/2-radius)then
begin
if(y<Form1.Height/2)and(x=Form1.Width/2-radius)then Canvas.LineTo(round(Form1.Width/2-radius+Cos(round(RadToDeg(ArcTan((Form1.Height/2-y) / (Form1.Width/2-radius-x))))*0.017453277)*radius),round(Form1.Height/2+Sin(round(RadToDeg(ArcTan((Form1.Height/2-y)/(Form1.Width/2-radius-x))))*0.017453277)*radius)-radius*2)
else Canvas.LineTo(round(Form1.Width/2-radius+Cos(round(RadToDeg(ArcTan((Form1.Height/2-y)/(Form1.Width/2-radius-x))))*0.017453277)*radius),round(Form1.Height/2+Sin(round(RadToDeg(ArcTan((Form1.Height/2-y)/(Form1.Width/2-radius-x))))*0.017453277)*radius))
end else Canvas.LineTo(Mouse.CursorPos.X-Form1.Left-4,Mouse.CursorPos.Y-Form1.Top-30);
end else Canvas.LineTo(Mouse.CursorPos.X-Form1.Left-4,Mouse.CursorPos.Y-Form1.Top-30);
end else
begin
if(Floor(Sqrt(Power(Form1.Width/2-radius+Form1.Left+4-Mouse.CursorPos.X,2)+Power(Form1.Height/2+Form1.Top+30-Mouse.CursorPos.Y,2)))>radius-1)then
begin
if(x<Form1.Width/2-radius)then Canvas.LineTo(round(Form1.Width/2-radius-0.000001326794896*radius),round(Form1.Height/2-0.99999999999912*radius))
else if(x>=Form1.Width/2-radius)then
begin
if(y<Form1.Height/2)and(x=Form1.Width/2-radius)then Canvas.LineTo(round(Form1.Width/2-radius+0.000001326794896*radius),round(Form1.Height/2+0.99999999999912*radius)-radius*2)
else Canvas.LineTo(round(Form1.Width/2-radius+0.000001326794896*radius),round(Form1.Height/2+0.99999999999912*radius))
end else Canvas.LineTo(Mouse.CursorPos.X-Form1.Left-4,Mouse.CursorPos.Y-Form1.Top-30);
end else Canvas.LineTo(Mouse.CursorPos.X-Form1.Left-4,Mouse.CursorPos.Y-Form1.Top-30);
end;
end;
Btw: Würd mich mal interressieren was dein Lehrer zu dir dann sagt. (ob der 'ne Herleitung etc. haben will?)
|