Autor Beitrag
hansdergott
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 55

XP Mediacenter Edition; XP Home
Delphi
BeitragVerfasst: Sa 09.08.08 22:18 
hallo zusammen

kann mir jemand sagen wie ich bei der TComponente Timage die form ändern kann
statt rechteckig hätte ich es gerne rund

vielen dank schon mal


Moderiert von user profile iconNarses: Topic aus Multimedia / Grafik verschoben am Sa 09.08.2008 um 23:18
pigfacejoe
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 332
Erhaltene Danke: 1

Win 10, Ubuntu
Delphi,Javascript, PHP, Java, Python
BeitragVerfasst: Sa 09.08.08 23:01 
Also das geht (soweit ich weiß) nicht. Wofür willste denn die Komponenten an sich rund haben?
hansdergott Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 55

XP Mediacenter Edition; XP Home
Delphi
BeitragVerfasst: Sa 09.08.08 23:06 
Titel: re
ich wollte in einem kreis zufällige pixel
erscheinen lassen

bin grad am überlegen wie man eine partikelsimulation am
besten angeht und dabei ist mir diese frage mit dem rundem
image gekommen

gruß hans
Jerk
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 251

Vista Ultimate, Ubuntu
Turbo Delphi 2006
BeitragVerfasst: So 10.08.08 00:45 
Kannst ja die Particle auch ins Rechteck schleudern und nur jene Anzeigen die höchstens die Entfernung r zu einem Punkt XY haben...

also sowas:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
MX      := 100;   // Mittelpunkt des Kreises
MY      := 100;   // Mittelpunkt des Kreises
PartAnz := 10000;
Radius  := 100;

randomize;

 for I := 1 to PartAnz do
 begin
  PX := MX - Radius + random(2*Radius+1);  
  PY := MY - Radius + random(2*Radius+1);  
  Image1.Canvas.pen.color:=clblack; 
  if sqr(PX-MX)+sqr(PY-MY)<= sqr(Radius) then  // Wenn PXPY innerhalb des Radius  dann Zeiche
   Image1.Canvas.Rectangle(PX-1,PY-1,PX+1,PY+1)
  else
   begin
    Image1.Canvas.pen.color:=clred;
    Image1.Canvas.Rectangle(PX-1,PY-1,PX+1,PY+1)
   end;
 end;

Gibt sicherlich noch elegantere Lösungen.





*edit nochmal updated und verbessert
*edit2 nein das ist nicht von Wikipedia abgeguckt :p
*edit3 genauigkeit verbessert.
Einloggen, um Attachments anzusehen!
turboPASCAL
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 193
Erhaltene Danke: 1

Win XP / Vischda
D6 PE / D2005 PE
BeitragVerfasst: So 10.08.08 07:39 
Hmmm...

Ein TImage ist eigentlich nicht zum darin herummalen da. Das TImage ist eher zur statischen
darstellung von Bildern gedacht.
Das hat mehrere Gründe auf die ich jetzt nicht weiter ein gehe.

Eine bessere Alternative ist die Verwendung einer PaintBox als Platzhalter in Zusammenhag mit
einem Bitmap.

Kein Plan ? Hier ein Beispiel:

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:
implementation

{$R *.dfm}

procedure TForm1.FormCreate(Sender: TObject);
begin
  randomize;

  bmp := TBitmap.Create;
  bmp.Width  := PaintBox1.Width;
  bmp.Height := PaintBox1.Height;
  bmp.PixelFormat := pf32Bit;

  bmp.Canvas.Brush.Color := Self.Color;
  bmp.Canvas.FillRect(bmp.Canvas.ClipRect);

  Timer1.Interval := 25;
  Timer1.Enabled := TRUE;
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  bmp.Free;
end;

procedure TForm1.PaintBox1Paint(Sender: TObject);
begin
  if Sender is TPaintBox then
    TPaintBox(Sender).Canvas.Draw(0, 0, bmp);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Timer1.Enabled := FALSE;
  Close;
end;

var
  MX      : integer = 100;   // Mittelpunkt des Kreises
  MY      : integer = 100;   // Mittelpunkt des Kreises
  PartAnz : integer = 10000;
  Radius  : integer = 100;

procedure TForm1.Timer1Timer(Sender: TObject);
var
  ZX, ZY: integer;
  PX : integer;
  PY : integer;
  i: integer;
  r: TRect;
  col: TColor;
begin
  bmp.Canvas.Brush.Color := Self.Color;
  bmp.Canvas.FillRect(bmp.Canvas.ClipRect);

  ZX := PaintBox1.Width div 2 - Radius;
  ZY := PaintBox1.Height div 2 - Radius;

  for i := 1 to PartAnz do
  begin
    PX := MX - Radius + random(2*Radius+1);
    PY := MY - Radius + random(2*Radius+1);
    col := random(256);
    bmp.Canvas.pen.color := RGB(col, col, col);
    if sqr(PX-MX)+sqr(PY-MY)<= sqr(Radius)
      then bmp.Canvas.Rectangle(ZX + PX-1,ZY + PY-1, ZX + PX+1,ZY + PY+1);
  end;

  // "besseres Paintbox1.Invalidate"
  r := Paintbox1.ClientRect;
  Windows.InvalidateRect(Self.Handle, @r, FALSE);
end;

end.
Einloggen, um Attachments anzusehen!
_________________
Nein, ich bin nicht der turboPASCAL aus der DP, ich seh nur so aus... :P
hansdergott Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 55

XP Mediacenter Edition; XP Home
Delphi
BeitragVerfasst: So 10.08.08 11:58 
Titel: danke
danke für eure antworten :!:

eure beispiele waren sehr hilfreich

grüß hans
Jerk
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 251

Vista Ultimate, Ubuntu
Turbo Delphi 2006
BeitragVerfasst: So 10.08.08 12:39 
@ TurboPascal
Genau solche Optimierungen finde ich interessant, gibt es evtl ne Sammlung von Common mistakes o.ä. ?
turboPASCAL
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 193
Erhaltene Danke: 1

Win XP / Vischda
D6 PE / D2005 PE
BeitragVerfasst: So 10.08.08 13:58 
@Jerk, sicher gibt es die irgend wo. Ich kenne jetzt im Moment keine bzw. wo man das nachlesen kann.
Im Grunde ist es erlerntes Wissen. Wobei das programieren in nonVCL ("Windows - API - Urschleim" ;) ) eine gute Erfahrung ist.

_________________
Nein, ich bin nicht der turboPASCAL aus der DP, ich seh nur so aus... :P