Autor Beitrag
Lazarusboy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: So 13.03.11 18:30 
Hallo Leute,
Ich bitte um eure Hilfe
Ich muss ein Projekt entwickeln, wo der Mond um die Erde kreist, und sobald er nicht mehr zu sehen ist(also den Bildrand verlassen hat), soll die Sonne zum Vorschein kommen und das gleiche machen wie der mond.
Nur leider funktioniert es nicht sehr gut:
Hier der Quelltext

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
If (IMond.Top>0and (IMond.Left<400)then
begin
Form1.Color:=clWindowtext;
IMond.Left:=IMond.Left+1 ;
Imond.Top:=Imond.Top-1;
end
else begin
IMond.Left:=IMond.Left+1 ;
Imond.Top:=Imond.Top+2;
end;
If (Imond.Left>800and (ISonne.Left<599and (ISonne.Top>0then
begin
Form1.Color:=clForm;
Imond.Visible:=False ;
ISonne.Visible:=True;
ISonne.Left:=ISonne.Left+1  ;
ISonne.Top:=ISonne.Top-1;
end
else begin
ISonne.Left:=ISonne.Left+1;
ISonne.Top:=ISonne.Top+2;
end;
If  ISonne.Left>800 then
begin
ISonne.Visible:=False  ;
ISonne.Left:=0;
ISonne.Top:=400  ;
IMond.Left:=0;
Imond.Top:=400;
Imond.Visible:=True;
end
else begin
end;
end;



Danke für eure Mithilfe

Moderiert von user profile iconKha: Delphi-Tags hinzugefügt
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19314
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 13.03.11 18:58 
user profile iconLazarusboy hat folgendes geschrieben Zum zitierten Posting springen:
Nur leider funktioniert es nicht sehr gut:
Was heißt das?

Was mir beim Drüberschauen auffällt ist, dass du keinerlei trigonometrische Funktionen (Sinus, Cosinus, ...) benutzt. Wie willst du da eine Kreisbewegung hinbekommen? :gruebel:
Lazarusboy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: So 13.03.11 19:05 
Also , sobald das Programm startet, fängt der Mond an 1 nach oben und nach links zu zu wandern, jedoch stoppt er sobald er am oberen Rand angekommen ist(er sollte dann eigentlich wieder die Kurve nach unten wander. Das gleiche dann auch mit der Sonne

Wäre nett , wenn du mir das mit den trigonometrischen Funktionen erklären könntest, denn damit habe ich noch nicht gearbeitet.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19314
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 13.03.11 19:18 
user profile iconLazarusboy hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
If (IMond.Top>0and (IMond.Left<400)then
begin
  Form1.Color:=clWindowtext;
  IMond.Left:=IMond.Left+1 ;
  Imond.Top:=Imond.Top-1;
end
else begin
  IMond.Left:=IMond.Left+1 ;
  Imond.Top:=Imond.Top+2;
end;
Das sollte funktionieren. Da bei dir aber beide Bedingungen erfüllt sein müssen, funktioniert es nur, wenn der Mond beim Start 400 Pixel vom oberen Rand entfernt ist.

Zudem läuft die Sonne gleich beim Start mit los. Wie wäre es, wenn du dir den aktuellen Status besser in Feldern unter private merkst? Dann kannst du es besser steuern.

Ja, wenn du Sinus und Cosinus noch nicht kennst, dann musst du das wohl erst lernen. Wikipedia sollte dabei helfen, deshalb ja auch der Link.
Lazarusboy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: So 13.03.11 20:32 
Also mit dem Mond, das funktioniert nun
Aber jetzt startet meine Sonne nicht einmal
Sonder der Mond läuft die ganze Zeit ab...
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19314
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 13.03.11 20:38 
Wie hast du es denn jetzt?
Lazarusboy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: So 13.03.11 20:41 
So hier:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
procedure TForm1.Timer1Timer(Sender: TObject);
begin
If (IMond.Top>0and (IMond.Left<300)then
begin
Form1.Color:=clWindowtext;
IMond.Left:=IMond.Left+1 ;
Imond.Top:=Imond.Top-1;
end
else begin
IMond.Left:=IMond.Left+1 ;
Imond.Top:=Imond.Top+1;
 If (Imond.Left>700and (ISonne.Left<300and (ISonne.Top>0then
begin
ISonne.Visible:=True;
Form1.Color:=clForm;
Imond.Visible:=False;
ISonne.Visible:=True;
ISonne.Left:=ISonne.Left+1;
ISonne.Top:=ISonne.Top-1;
end
else begin
ISonne.Left:=ISonne.Left+1;
ISonne.Top:=ISonne.Top+1;
end;
If  ISonne.Left>700 then
begin
ISonne.Visible:=False  ;
ISonne.Left:=0;
ISonne.Top:=400  ;
IMond.Left:=0;
Imond.Top:=400;
Imond.Visible:=True;
end
else begin
end;
end;
end;


Zuletzt bearbeitet von Lazarusboy am So 13.03.11 20:45, insgesamt 2-mal bearbeitet
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: So 13.03.11 20:43 
btw, die [delphi][/delphi]-Tags funktionieren auch bei Lazarus-Quelltexten. ;)

lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
Lazarusboy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: So 13.03.11 21:00 
okay, danke
Wollte trotzdem noch gerne wissen, welche Fehler ich hier in dem obigen Quelltext gemacht habe, damit
meine sonne sich auch bewegt

---Moderiert von user profile iconNarses: Beiträge zusammengefasst---

Okay habs nun hinbekommen...

Hab noch eine frage, wie kann ich den mond und die Sonne in einem kreis bewegen lassen?
elundril
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3747
Erhaltene Danke: 123

Windows Vista, Ubuntu
Delphi 7 PE "Codename: Aurora", Eclipse Ganymede
BeitragVerfasst: So 13.03.11 21:54 
user profile iconLazarusboy hat folgendes geschrieben Zum zitierten Posting springen:
Okay habs nun hinbekommen...

Hab noch eine frage, wie kann ich den mond und die Sonne in einem kreis bewegen lassen?


user profile iconjaenicke hat folgendes geschrieben Zum zitierten Posting springen:
Was mir beim Drüberschauen auffällt ist, dass du keinerlei trigonometrische Funktionen (Sinus, Cosinus, ...) benutzt. Wie willst du da eine Kreisbewegung hinbekommen? :gruebel:


beantwortet das deine frage?

lg elundril

_________________
This Signature-Space is intentionally left blank.
Bei Beschwerden, bitte den Beschwerdebutton (gekennzeichnet mit PN) verwenden.
Lazarusboy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: So 13.03.11 22:02 
eher weniger, da ich keine Ahnung habe welches Befehl ich verwenden muss, damit der Mond und die Sonne in einem Kreisförmigen Radius sich bewegen.
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19314
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: So 13.03.11 22:20 
Das ist kein programmiertechnisches Problem, sondern ein mathematisches...

Die Delphifunktionen heißen einfach Sin und Cos und nutzen das Bogenmaß. Zur Umwandlung in Grad gibt es RadToDeg bzw. DegToRad.

Du berechnest die Position dann aus Radius und aktuellem Winkel.

Für diesen Beitrag haben gedankt: Lazarusboy
Lazarusboy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: So 20.03.11 15:06 
okay ich habe nun verscucht , dass der Mond eine kreisförmige Umlaufbahn einnimt, leider funktionert das nicht so wie ich es gedacht habe(Der Mond macht seine kreisbahn bei jedem Versuch in eine andere Richtung) , könnt ihr mich vielleicht nocheinmal hellfen
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
procedure TForm1.Timer1Timer(Sender: TObject);
 var x,y:integer;
begin
If (IMond.Top>0and (IMond.Left<=290)then
begin
if z>=360 then z:=0;
inc(z,1);
Form1.Color:=clWindowtext;
x := Round(Cos(DegToRad(z))*10);
y := Round(Sin(DegtoRad(z))*10);
IMond.Left:=IMond.Left+x;
IMond.Top:=IMond.Top+y;
end
else
begin
If (IMond.Left>290and (Imond.left<700then begin
Form1.Color:=clWindowtext;
x := Round(Cos(DegToRad(-z))*10);
y := Round(Sin(DegtoRad(z))*10);
IMond.Left:=IMond.Left+x;
IMond.Top:=IMond.Top+y;
end
else begin
 If (ISonne.Left<310and (ISonne.Top>0then
begin
ISonne.Visible:=True;
Form1.Color:=clForm;
Imond.Visible:=False;
ISonne.Visible:=True;
ISonne.Left:=ISonne.Left+1;
ISonne.Top:=ISonne.Top-1;
end
else begin
ISonne.Left:=ISonne.Left+1;
ISonne.Top:=ISonne.Top+1;
end;
If  ISonne.Left>700 then
begin
ISonne.Visible:=False  ;
ISonne.Left:=48;
ISonne.Top:=440  ;
IMond.Left:=0;
Imond.Top:=400;
Imond.Visible:=True;
end
else begin
end;
end;
end;
end;
Lazarusboy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: Di 22.03.11 00:15 
Hallo Leute, bitte um Hilfe
Sobald der Mond seine Runde gedreht hat, erscheint die Sonne ganz links und macht nichts...
Eigentlich sollte die Sonne auch ihre Runde drehen...
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
begin
ISonne.Left:=40;
If Imond.Left<700 then
begin
Form1.Color:=clWindowtext;
if l>=360 then  l:=0;
 inc(l,1);
x := round(Cos(DegTorad(l))*10);
y := round(Sin(DegToRad(l))*10);
IMond.Left:=IMond.Left+x;
IMond.Top:=IMond.Top-12+2*y;
end
else
begin
 If (ISonne.Left<700)  then
begin
IMond.Visible:=False;
Isonne.Visible:=true;
ISonne.Left:=48;
ISonne.Top:=440;
Form1.Color:=clForm;
if l>=360 then  l:=0;
 inc(l,1);
x := round(Cos(DegTorad(l))*10);
y := round(Sin(DegToRad(l))*10);
IMond.Left:=IMond.Left+x;
IMond.Top:=IMond.Top-12+2*y;
end
else begin
ISonne.Visible:=False  ;
IMond.Left:=0;
Imond.Top:=400;
Imond.Visible:=True;
end;
end;
end;
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19314
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 22.03.11 06:58 
user profile iconLazarusboy hat folgendes geschrieben Zum zitierten Posting springen:
Eigentlich sollte die Sonne auch ihre Runde drehen...
Dann poste doch dazu auch den Quelltext. In dem aktuell geposteten weist du nur eine feste Position zu. :nixweiss:
user profile iconLazarusboy hat folgendes geschrieben Zum zitierten Posting springen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
begin
ISonne.Left:=40;
If Imond.Left<700 then
begin
[...]
end
else
begin
 If (ISonne.Left<700)  then
begin
IMond.Visible:=False;
Isonne.Visible:=true;
ISonne.Left:=48;
ISonne.Top:=440;

Form1.Color:=clForm;
[...]

Für diesen Beitrag haben gedankt: Lazarusboy
Lazarusboy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: Di 22.03.11 09:30 
mmeinst du es so?

object Image1: TImage des is ist die erde
Left = 304
Height = 95
Top = 288
Width = 96
Picture.Data = {

}
end
object ISonne: TImage Sonne
Left = 8
Height = 50
Top = 376
Width = 50
Picture.Data = {

Visible = False
end
object IMond: TImage Mond
Left = -16
Height = 112
Top = 384
Width = 120
Picture.Data = {

end
object Timer1: TTimer
Interval = 1
OnTimer = Timer1Timer
left = 592
top = 16
end
jaenicke
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 19314
Erhaltene Danke: 1747

W11 x64 (Chrome, Edge)
Delphi 11 Pro, Oxygene, C# (VS 2022), JS/HTML, Java (NB), PHP, Lazarus
BeitragVerfasst: Di 22.03.11 09:34 
Was haben die DFM-Definitionen damit zu tun? Du weist schlicht keinen dynamisch berechneten Wert für die Position der Sonne zu, also wie soll sich diese denn ändern? :gruebel:

Für diesen Beitrag haben gedankt: Lazarusboy
Lazarusboy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: Di 22.03.11 09:42 
Ich weiß nicht genau, welchen Quelltext du möchtest...
Lazarusboy Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 28



BeitragVerfasst: Di 22.03.11 09:55 
aber egal habs gerade sekber hinbekommen
Danke