Autor Beitrag
LinzerASK
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 135

WIN XP
Delphi 4, Delphi 2005
BeitragVerfasst: Mi 15.03.06 19:17 
hallo!

ich möchte gerne eine Art Sonne programmieren, d.h. in der mitte der form beginnt sich im uhrzeigersinn ein kreis aufzuzeichnen,....

wie kann ich da vorgehen!?

in die mitte der form komme ich ja mit

ausblenden Quelltext
1:
form1.Canvas.MoveTo(clientwidth div 2,clientheight div 2);					


aber wie gehe ich da dann vor:

erstmals einen timer auftragen odeR?
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: Mi 15.03.06 19:31 
Für was brauchst du ein Timer?

Fürs zeichnen brauchst du noch LineTo ;).
LinzerASK Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 135

WIN XP
Delphi 4, Delphi 2005
BeitragVerfasst: Mi 15.03.06 19:32 
jaja schon klar...


lineto zum zeichnen

nur moveto...das ich in die mitte der form komme
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: Mi 15.03.06 19:34 
Und wo liegt jetzte das problem?
LinzerASK Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 135

WIN XP
Delphi 4, Delphi 2005
BeitragVerfasst: Mi 15.03.06 19:41 
das sich die linien so aufzeichnen wie eine sonne....

ich habe schon zbsp eine art scheibenwischer programmiert aber sonne !! ich stehe an
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: Mi 15.03.06 20:21 
malst du nen Kreis (dafür gibt es auch ein Canvass-Befhel, glaube Circle) und dnach gehst du mit Hilfe des Pythagorad um die Sonne, mit entsprechendem Abstand und zeichnest von dort (MoveTo) mit eine Linie mit LineTo. Damnach wählst du mit dem Pythagorad den Nächsten Punkt.
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Mi 15.03.06 20:21 
Ah..., so vielleicht?
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
Const
  iRadius = 50;

Var
  dEnd,dStep, d : Double;
  x,y : Integer;

Begin
 x := 100;
 y := 100;
 dStep = 2*Pi/360;
 d := 0;
 dEnd := 2*Pi-dstep/2;
 while d<dEnd do begin
   Canvas.Moveto (x,y);
   Cancas.LineTo (x + Trunc (0.5 + sin(d)*Radius),  y + Trunc (0.5 + cos (d)*Radius) );
   d := d + dStep;
 End;
End;

_________________
Na denn, dann. Bis dann, denn.
Heiko
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 3169
Erhaltene Danke: 11



BeitragVerfasst: Mi 15.03.06 20:22 
user profile iconalzaimar hat folgendes geschrieben:
Ah..., so vielleicht?


Möglichkeiten gibt es viele. Es ist nur eine Frage des Aufwandes ;).
LinzerASK Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 135

WIN XP
Delphi 4, Delphi 2005
BeitragVerfasst: Mi 15.03.06 20:32 
ja ich weis nicht...


also irgendwie denke ich mir ist es ja nicht so schwer...nur ich weis halt nicht wie ich anfangen soll


ich arbeite mit einem timer...


es sollten die "strahlen" immer mit einer gleichen länge weggehen,...also nicht bis ans ende der form..
alzaimar
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2889
Erhaltene Danke: 13

W2000, XP
D6E, BDS2006A, DevExpress
BeitragVerfasst: Mi 15.03.06 20:39 
user profile iconHeiko hat folgendes geschrieben:
user profile iconalzaimar hat folgendes geschrieben:
Ah..., so vielleicht?


Möglichkeiten gibt es viele. Es ist nur eine Frage des Aufwandes ;).

Das implizierte das 'vielleicht'

@LinzerASK: Probier doch mal meinen Code.

_________________
Na denn, dann. Bis dann, denn.
LinzerASK Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 135

WIN XP
Delphi 4, Delphi 2005
BeitragVerfasst: Mi 15.03.06 20:44 
da sind einige sachen die ich noch nicht kann...

ich kann dir mal ne exe schicken was ich schon geprogt habe
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Mi 15.03.06 20:53 
such mal nach Turtle und machs damit, indem du dich immer um 1° nach rechts drehst und wieder zurückläufst, hier eine Turtle Implementation von mir:
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:
  TTurtle = class
    Canvas: TCanvas;
    currx, curry: double;
    currangle: double;
    procedure f_init(apos: Tpoint; aCanvas: TCanvas);
    procedure f_forward(l: double; draw: boolean = true);
    procedure f_left(angle: double);
    procedure f_right(angle: double);
  end;

procedure TTurtle.f_init(apos: TPoint; aCanvas: TCanvas);
begin
  currx := apos.x;
  curry := apos.Y;
  currangle := 180;
  Canvas := aCanvas;
  Canvas.MoveTo(round(currX), round(currY));
end;

procedure TTurtle.f_forward(l: double; draw: boolean = true);
var
  v, u, bangle: double;
begin
  bangle := degtorad(currangle);
  v := sin(bangle) * l;
  u := cos(bangle) * l;
  currx := currX + v;
  currY := currY + u;
  if draw then
    Canvas.LineTo(round(currx), round(curry)) else
      Canvas.MoveTo(round(CurrX), round(Curry));
end;

procedure TTurtle.f_left(angle: double);
begin
  if (angle < 0) or (angle > 360) then exit;
  currangle := currangle + angle;
  if angle > 360 then currangle := currangle - 360;
end;

procedure TTurtle.f_right(angle: double);
begin
  if (angle < 0) or (angle > 360) then exit;
  currangle := currangle - angle;
  if angle < 0 then currangle := currangle + 360;
end;


ausblenden globale variable
1:
2:
var
  aTurtle: TTurtle;


ausblenden oncreate
1:
2:
3:
  image1.Picture.Bitmap := nil;
  aTurtle := TTurtle.Create;
  aTurtle.f_init(point(image1.width div 2, image1.height div 2), image1.canvas);


ausblenden ondestroy
1:
  aTurtle.Free;;					


ausblenden ontimer
1:
2:
3:
  aTurtle.f_forward(50);  //50 in beiden zeilen durch die länge der strahlen ersetzen
  aTurtle.f_forward(-50, false);
  aTurtle.f_right(5);  // in die klammer der abstand der strahlen in grad
LinzerASK Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 135

WIN XP
Delphi 4, Delphi 2005
BeitragVerfasst: Do 16.03.06 08:54 
ja also das problem ist das, ich arbeite nur mit timern und move bzw. line to...


ich schicke dir mal einen 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:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Panel1: TPanel;
    Timer1: TTimer;
    Button1: TButton;
    Timer2: TTimer;
    Button2: TButton;
    ScrollBar1: TScrollBar;
    Panel2: TPanel;
    Panel3: TPanel;
    MainMenu1: TMainMenu;
    Men1: TMenuItem;
    Ende1: TMenuItem;
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure ScrollBar1Change(Sender: TObject);
    procedure Ende1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;
  endzeile:integer;
implementation

{$R *.DFM}

procedure TForm1.FormCreate(Sender: TObject);
begin
canvas.pen.mode:=pmNotXor;
endzeile:=panel1.height;
form1.canvas.Pen.color:=$FFFF; //Farbe gelb
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
canvas.moveto(0,panel1.height);
canvas.lineto(form1.clientwidth,endzeile);
if endzeile<clientheight-5 then
                               endzeile:=endzeile+5
                           else
                               begin
                               timer1.enabled:=false;
                               //form1.canvas.Pen.color:=$FFFFFF;
                               timer2.enabled:=true;
                               end;


end;

procedure TForm1.Button1Click(Sender: TObject);
begin
timer1.enabled:=true;
end;

procedure TForm1.Timer2Timer(Sender: TObject);
begin
canvas.moveto(0,panel1.height);
canvas.lineto(form1.clientwidth,endzeile);

if endzeile>=panel1.height+5 then
                               endzeile:=endzeile-5
                           else
                               begin
                               timer2.enabled:=false;
                               form1.canvas.Pen.color:=random(65000);
                               timer1.enabled:=true;
                               end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
closE;
end;

procedure TForm1.ScrollBar1Change(Sender: TObject);
begin
timer1.Interval:=scrollbar1.position;
timer2.interval:=scrollbar1.position;
end;

procedure TForm1.Ende1Click(Sender: TObject);
begin
closE;
end;

end.



so möchte ich auch die "sonne" prgrammieren

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt
LinzerASK Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 135

WIN XP
Delphi 4, Delphi 2005
BeitragVerfasst: Do 16.03.06 13:42 
kann man mir denn nicht helfen
seepy
Hält's aus hier
Beiträge: 10

Debian 4.0r4

BeitragVerfasst: Do 16.03.06 14:17 
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 x_y(winkel : Real; var x,y : Real);
begin
  x := Cos(winkel) * (Form1.Width div 4) + (Form1.height div 2);
  y := Sin(winkel) * (Form1.height div 4) + (Form1.width div 2);
end;

procedure Zeichne_Zeiger(winkel,x,y :Real;mpx,mpy,zsize :Integer;col : TColor);
begin

  if winkel <= 0 then exit else
    begin
      Form1.Canvas.MoveTo(mpx,mpy);    // in die mitte des Forms
      x_y(winkel,x,y);
      Form1.Canvas.Pen.Color := col;   // Farbe z.B clyellow usw.
      Form1.Canvas.Pen.Width := zsize;  // Breite des Pen
      Form1.Canvas.LineTo(Trunc(x),Trunc(y)); // Trunc = abschneiden der nachkommastelle, da nur "ganze" pixel
      Zeichne_Zeiger((winkel - (pi/6)),x,y,mpx,mpy,2,clyellow); //  (pi/6) als anzahl der strahlen (hier : 12) ; 
                                                                // 2pi/12 = pi/6; 2pi = umfang des
    end;                                                        // einheitskreises falls du noch keine trigonometrie kennst 
                                                                //vgl. oben sinus,cosinus usw.

end;

procedure TForm1.Button1Click(Sender: TObject);
var mpx, mpy : Integer;
    x ,y : Real;
    circlerect : TRect;
begin
  Form1.DoubleBuffered := TRUE;
  Form1.Refresh;
  mpx := Form1.Width div 2;  // mittelpkt der form , beliebig veränderbar
  mpy := Form1.Height div 2; //
  Zeichne_Zeiger((2*pi),x,y,mpx,mpy,2,clyellow);

  circlerect := Rect(10,10,100,100);  // nur Bsp... (x1,y1,x2,y2) Koords
  Form1.Canvas.Brush.Color := clyellow;
  form1.Canvas.Ellipse(circlerect);  // kreis zeichnen


hoffe des hilft dir weiter :=)
achja wenn dus mit nem Timer machen willst lass den winkel rücklaufen (Z:17) und vergiss die abbruchbedingung net. mfg


Zuletzt bearbeitet von seepy am Do 16.03.06 14:28, insgesamt 1-mal bearbeitet
LinzerASK Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 135

WIN XP
Delphi 4, Delphi 2005
BeitragVerfasst: Do 16.03.06 14:27 
danke für die bemühung!

aber ich kann das ganze nur mit timer,lineto etc..


trunc oder ähnliches kann ich nicht....und es würde ja nichts bringen wenn ich es einfach kopieren würde...


ich will es ja schließlich und endlich kapieren
seepy
Hält's aus hier
Beiträge: 10

Debian 4.0r4

BeitragVerfasst: Do 16.03.06 14:37 
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:
var
  Form1: TForm1;
  winkel : Real;
implementation

{$R *.dfm}
procedure x_y(winkel : Real; var x,y : Real);
begin
  x := Cos(winkel) * (Form1.Width div 4) + (Form1.height div 2);
  y := Sin(winkel) * (Form1.height div 4) + (Form1.width div 2);

end;

procedure Zeichne_Zeiger(winkel,x,y :Real;mpx,mpy,zsize :Integer;col : TColor);
begin
  Form1.Canvas.MoveTo(mpx,mpy);
  x_y(winkel,x,y);
  Form1.Canvas.Pen.Color := col;
  Form1.Canvas.Pen.Width := zsize;
  Form1.Canvas.LineTo(Trunc(x),Trunc(y));

end;


procedure TForm1.Timer1Timer(Sender: TObject);
var mpx, mpy : Integer;
    x ,y : Real;
begin
  Form1.DoubleBuffered := TRUE;
  mpx := Form1.Width div 2;
  mpy := Form1.Height div 2;

  if winkel <= 0 then timer1.Enabled := FALSE else
    begin
      winkel := winkel - (pi/6);
      Zeichne_Zeiger(winkel,x,y,mpx,mpy,2,clyellow);
    end;

end;

procedure TForm1.FormCreate(Sender: TObject);
begin
   winkel := 2*pi;
end;


jetzt müsst es passen
F34r0fTh3D4rk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 5285
Erhaltene Danke: 29

Win Vista (32), Win 7 (64)
Eclipse, SciTE, Lazarus
BeitragVerfasst: Do 16.03.06 15:15 
Guck dir mein Beispiel mal an, das ist nur linto, moveto und timer, die anderen beispiele alle übrigens auch, was willst du eigentlic ?
Sinspin
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 1340
Erhaltene Danke: 120

Win 10
RIO, CE, Lazarus
BeitragVerfasst: Do 16.03.06 16:25 
wieso willst du immer einen timer? soll man sehen wie die sonne sich langsam aufbaut?
ansonsten brauch man keinen timer! der macht die ganze sache nur unnötig umständlich.

und ohne trunc oder round wirst du es nicht hinbekommen! denn du musst ja die bei der berechnung der nächsten x und y position enstandene reelle zahl wieder in eine ganze umwandeln denn zeichnen kannst du nur mit ganzen zahlen. oder hast du schonmal halbe pixel gesehen?

_________________
Wir zerstören die Natur und Wälder der Erde. Wir töten wilde Tiere für Trophäen. Wir produzieren Lebewesen als Massenware um sie nach wenigen Monaten zu töten. Warum sollte unser aller Mutter, die Natur, nicht die gleichen Rechte haben?
LinzerASK Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 135

WIN XP
Delphi 4, Delphi 2005
BeitragVerfasst: Do 16.03.06 17:55 
ich möchte eigetnlich es so haben, dass sich die sonne schritt für schritt aufbaut!!!

.. es muss ja nicht ein runderkreis werden..es kann ja alle seiten berühren...


4 timer?