Autor Beitrag
freak89
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 29



BeitragVerfasst: So 06.03.05 23:40 
Hi, Wieso kann ich mit diesem Quelltext keine diagonalen zeichnen? und wie muss er denn richtig heißen?
ausblenden 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:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
       with  image1.canvas do begin
  if (chr(Key) = chr(vk_left))
then begin image1.canvas.lineto(penpos.x-1,penpos.y)  end  ;
if (chr(Key) = chr(vk_right))
then begin image1.canvas.lineto(penpos.x+1,penpos.y)  end ;
if (chr(Key) = chr(vk_up))
then begin image1.canvas.lineto(penpos.x,penpos.y-1)  end ;
if (chr(Key) = chr(vk_down))
then begin image1.canvas.lineto(penpos.x,penpos.y+1)  end;
  if (chr(Key) = chr(vk_left))and (chr(Key) = chr(vk_up))
then begin image1.canvas.lineto(penpos.x-1,penpos.y-1)  end  ;
if (chr(Key) = chr(vk_left))and (chr(Key) = chr(vk_down))
then begin image1.canvas.lineto(penpos.x-1,penpos.y+1)  end ;
if (chr(Key) = chr(vk_right))and (chr(Key) = chr(vk_up))
then begin image1.canvas.lineto(penpos.x+1,penpos.y-1)  end ;
if (chr(Key) = chr(vk_right))and (chr(Key) = chr(vk_down))
then begin image1.canvas.lineto(penpos.x+1,penpos.y+1)  end;
   {if key = chr(vk_left) then}

end;
  end;
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: So 06.03.05 23:42 
schon mal was von CASE gehört ? damit sparst du dir die 1000 ifs. und das CHR ist auch unnötig...

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
freak89 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 29



BeitragVerfasst: So 06.03.05 23:47 
retnyg hat folgendes geschrieben:
schon mal was von CASE gehört ?

nein, nicht wirklich, kannst du mir es erklären?
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: So 06.03.05 23:49 
dein code liesse sich so zusammenfassen:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
var x,y:integer;
begin
  x:= image1.canvas.penpos.x;
  y:= image1.canvas.penpos.y; 
  case key of 
       vk_down: inc(y);
       vk_up: dec(y);
       vk_left: inc(x);
       vk_right: dec(x);
  end;
  image1.canvas.moveto(x,y);
  image1.canvas.pixels[x,y]:=clred;
end;

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
freak89 Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 29



BeitragVerfasst: Mo 07.03.05 00:17 
also so: ? das funktioniert nicht
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  x:= image1.canvas.penpos.x;
  y:= image1.canvas.penpos.y;
  case key of
       vk_down: inc(y);
       vk_up: dec(y);
       vk_left: inc(x);
       vk_right: dec(x);
  end;
  image1.canvas.moveto(x,y);
  image1.canvas.pixels[x,y]:=clred;
end;
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Mo 07.03.05 01:52 
sonderbar, kann mir auch nicht erklären wieso pixels nix zeichnet... also halt so:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var x,y:integer;
begin
  with image1.canvas do begin
    x:= penpos.x;
    y:= penpos.y;
    case key of
       vk_down: inc(y);
       vk_up:   dec(y);
       vk_left: dec(x);
       vk_right:inc(x);
    end;
    lineto(x,y);
    pixels[x,y]:=clred;
  end;
end;

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...
retnyg
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2754

SNES, GB, GBA, CPC, A500, 486/66, P4/3.0HT: NintendOS, AmigaOS, DoS
Delphi 5, Delphi 7
BeitragVerfasst: Mo 07.03.05 02:10 
aha, das mit pixels ging drum nicht weil das vom entsprechenden canvas unterstützt werden muss, was bei image nicht der fall ist. so geht es aber:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
procedure TForm1.Edit1KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
var x,y:integer;
begin
  with form1.canvas do begin
  x:= penpos.x;
  y:= penpos.y;
  case key of
       vk_down: inc(y);
       vk_up: dec(y);
       vk_left: dec(x);
       vk_right: inc(x);
  end;
//  lineTo(x,y);
  moveto(x,y);
  pixels[x,y]:=clred;
  end;
end;

_________________
es gibt leute, die sind genetisch nicht zum programmieren geschaffen.
in der regel haben diese leute die regel...