AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Muss einen Kompass programmieren...

Ein Thema von volcano57 · begonnen am 18. Nov 2007 · letzter Beitrag vom 23. Nov 2007
 
Benutzerbild von mleyen
mleyen

Registriert seit: 10. Aug 2007
609 Beiträge
 
FreePascal / Lazarus
 
#32

Re: Muss einen Kompass programmieren...

  Alt 22. Nov 2007, 08: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?)
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 07:14 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz