Showing off what my 7 year old did with Lazarus! lazarus / 8-Other ---------------------------------------------------------------------- Tony Stone · 2021-10-19 00:42 I know... this is silly and pointless for most here.  BUT, i feel the need to share it anyway!  She is proud of it, understood and figured out some of the code... and she is loving this stuff so far!  Lazarus is going to be part of our at home school routine. She wants to make it do colors next. (Mods, no hard feelings if you remove this post as not being useful to community.  I get it) ---------------------------------------------------------------------- trev · 2021-10-19 00:44 Great! Reminds me of the Etch-A-Sketch I had when a kid many moons ago. ---------------------------------------------------------------------- 440bx · 2021-10-19 00:57 Quote from: Tony Stone on October 19, 2021, 02:42:09 amShe is proud of it And I hope you're proud of her.  I'd say that's impressive considering it's from a 7 year old. ---------------------------------------------------------------------- VTwin · 2021-10-19 01:21 Nice! ---------------------------------------------------------------------- Tony Stone · 2021-10-19 01:28 Quote from: 440bx on October 19, 2021, 02:57:31 amQuote from: Tony Stone on October 19, 2021, 02:42:09 amShe is proud of it And I hope you're proud of her.  I'd say that's impressive considering it's from a 7 year old. Yes, I AM VERY proud of her.  Her excitement too was awesome!  Some day she may be an amazing programmers who got her start with Lazarus!  To be clear, she didn't write the code all on her own.  We both read about functions, learned and tried together.  Its a very fun project so far.  I am hoping my younger daughter will get excited about this stuff as well.  Her very first program I can confidently say beats any of the Hello World first programs!  And thanks to all of the Lazarus/FPC developers for your hard work on this project! ---------------------------------------------------------------------- engkin · 2021-10-19 06:05 Quote from: Tony Stone on October 19, 2021, 02:42:09 ami feel the need to share it anyway! I am glad you did. She is obviously smart. Quote from: trev on October 19, 2021, 02:44:56 amGreat! Reminds me of the Etch-A-Sketch I had when a kid many moons ago. +1 ---------------------------------------------------------------------- Thaddy · 2021-10-19 07:20 Quote from: Tony Stone on October 19, 2021, 02:42:09 am(Mods, no hard feelings if you remove this post as not being useful to community.  I get it) The mods will not even consider removing it.... Reminds me the other way around: my mother, at age 72 then wrote her own contacts/address book in-Delphi - Object Pascal. (sadly she recently died at age 90). That is just to show age does not matter. What does matter is the programming language. Top Job!!! ---------------------------------------------------------------------- MarkMLl · 2021-10-19 07:34 Well done that young lady! (And well done parents as well.) MarkMLl ---------------------------------------------------------------------- Bart · 2021-10-19 14:03 Move to "Third party"  Bart ---------------------------------------------------------------------- Thaddy · 2021-10-19 14:11 Quote from: Bart on October 19, 2021, 04:03:08 pmMove to "Third party"  Bart NO! ---------------------------------------------------------------------- Zvoni · 2021-10-19 14:12 Deserves an entry in https://wiki.freepascal.org/Projects_using_Lazarus_- _Educational_software ---------------------------------------------------------------------- Bart · 2021-10-19 14:20 Quote from: Thaddy on October 19, 2021, 04:11:18 pmNO! And there's the grumpy old man again... Bart ---------------------------------------------------------------------- Tony Stone · 2021-10-19 14:29 So tonight we are gonna work on making the arrow keys function a little more proper.  We were able to use the keypress event of the form to simple adjust the spinedits... which the spinedits onchange currently calls the drawing points.  But she wants it to be able to accept pressing 2 arrow keys at once to draw a diagonal line for example.  So I am currently looking for how to go about that.  So I guess that will be tonights lesson for us both.     I have a feeling though that processing 2 keys at once is gonna add a lot of complexity for her to understand.  For me too!  lol If it is too complicated we will work on selecting colors with a color picker component.  That should be simple enough to keep her interested and learning. ---------------------------------------------------------------------- Tony Stone · 2021-10-19 15:37 Quote from: Tony Stone on October 19, 2021, 04:29:12 pmSo tonight we are gonna work on making the arrow keys function a little more proper.  We were able to use the keypress event of the form to simple adjust the spinedits... which the spinedits onchange currently calls the drawing points.  But she wants it to be able to accept pressing 2 arrow keys at once to draw a diagonal line for example.  So I am currently looking for how to go about that.  So I guess that will be tonights lesson for us both.     I have a feeling though that processing 2 keys at once is gonna add a lot of complexity for her to understand.  For me too!  lol If it is too complicated we will work on selecting colors with a color picker component.  That should be simple enough to keep her interested and learning.  So i did a little reading... and i think i need to track the key down and key up events.  and I am thinking of using a timer that basically moves the drawing point.  I am thinking this may be the simplest way to go.  hmmmm.... then the timer interval can be set to adjust drawing speed i suppose.  Unless I am missing an more obvious simple solution please let me know.  Gotta keep it simple for a child.  And simple for my adult-child brain. ---------------------------------------------------------------------- howardpc · 2021-10-19 16:53 I think the simplest solution would be to use only two arrow keys (say Left and Right) in combination with two modifier keys (say Shift for Up and Ctrl for Down). This means you can read all the information from a single KeyDown call. However, if you want to try to intercept successive keystrokes, the following unit (to my surprise) works most of the time. Its accuracy does depend on the keyboard, and the typist's skill, and not having a fast keyboard repeat rate. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, Forms, LazLogger; const   ArrowKeys: set of Byte = [37, 38, 39, 40];  Diagonals: set of Byte = [0, 74, 76, 154]; type   TDiagonal = (dNone, dUpLeft, dUpRight, dDownLeft, dDownRight);   TForm1 = class(TForm)  private    arr: array[1..2] of Byte;    even: Boolean;    function AddedDiagonalKey(aKey: Word; out diagonal: TDiagonal): Boolean;  protected    procedure KeyDown(var Key: Word; Shift: TShiftState); override;  end;   function DiagonalToStr(aDiagonal: TDiagonal): String; var  Form1: TForm1; implementation function DiagonalToStr(aDiagonal: TDiagonal): String;begin  WriteStr(Result, aDiagonal);  Delete(Result, 1, 1);end; {$R *.lfm} { TForm1 } function TForm1.AddedDiagonalKey(aKey: Word; out diagonal: TDiagonal): Boolean;var  tmp: Int64;begin  if aKey > High(Byte) then    begin    Diagonal := dNone;      Exit(False);    end;  if even then arr[2] := Byte(aKey)  else arr[1] := Byte(aKey);  even := not even;  tmp := arr[1] * arr[2];  Dec(tmp, 1406);  Result := (arr[1] <> arr[2]) and (arr[1] in ArrowKeys) and (arr[2] in ArrowKeys) and            (Byte(tmp) in Diagonals);  case Result of    True: case tmp of          0:   diagonal := dUpLeft;            74:  diagonal := dDownLeft;          76:  diagonal := dUpRight;            154: diagonal := dDownRight;          end;    False: diagonal := dNone;  end;end; procedure TForm1.KeyDown(var Key: Word; Shift: TShiftState);var  diagonal: TDiagonal;begin  inherited KeyDown(Key, Shift);  case AddedDiagonalKey(Key, diagonal) of    True:  DebugLn(['diagonal key combination ',DiagonalToStr(diagonal)]);    False: DebugLn('non-diagonal key combination');  end;end; end. ---------------------------------------------------------------------- engkin · 2021-10-19 18:08 Binary might be easy here. Each digit for one arrow key. Here is how to track the keys: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs; type   { TForm1 }   TForm1 = class(TForm)    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);    procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);  private  public    TrackDownKeys:Byte;    procedure LetUsMove;  end; var  Form1: TForm1; implementationuses  LCLType; {$R *.lfm} { TForm1 } const  CFourArrowKeys:array[VK_LEFT..VK_DOWN] of byte = (%0001 {Left}, %0010 {Up}, %0100 {Right}, %1000 {Down}); procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState  );begin  if Key in [VK_LEFT..VK_DOWN] then    TrackDownKeys:=TrackDownKeys or CFourArrowKeys[Key];   LetUsMove;end; procedure TForm1.FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);begin  if Key in [VK_LEFT..VK_DOWN] then    TrackDownKeys:=TrackDownKeys and not CFourArrowKeys[Key];   LetUsMove;end; procedure TForm1.LetUsMove;begin  Caption:=TrackDownKeys.ToBinString;end; end. In this case Up and Left is %0011. As you can see it is visible. Up and Right is %0110  and so on Choosing which of the eight directions could be like: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.LetUsMove;begin  Caption:=TrackDownKeys.ToBinString;  case TrackDownKeys of  %0001:;//Left  %0010:;//Up  %0100:;//Right  %1000:;//Down  %0011:;//Left and Up  %0110:;//Right and Up  %1100:;//Right and down  %1001:;//Left and Down  end;end; If you know the direction you can turn it into delta for x and y. Maybe like: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i procedure TForm1.LetUsMove;var  dx,dy:integer;begin  Caption:=TrackDownKeys.ToBinString;  case TrackDownKeys of  %0001:begin dx:=-1; dy:= 0; end;//Left  %0010:begin dx:= 0; dy:=-1; end;//Up  %0100:begin dx:=+1; dy:= 0; end;//Right  %1000:begin dx:= 0; dy:=+1; end;//Down  %0011:begin dx:=-1; dy:=-1; end;//Left and Up  %0110:begin dx:=+1; dy:=-1; end;//Right and Up  %1100:begin dx:=+1; dy:=+1; end;//Right and down  %1001:begin dx:=-1; dy:=+1; end;//Left and Down  end;end; ---------------------------------------------------------------------- Tony Stone · 2021-10-20 00:34 Thank you guys for the suggestions on the diagonal drawing aspect.  For our purposes and skill level it was a bit much.  But her and I tonight were able to complete the project!  And as I said before, this is almost all her design!!  Her ideas... I did the coding but walked her through what it was all doing and I did it based on logic she suggested!  It was a ton of fun to do this with her.  I am attaching the project.  It actually works very well!  Maybe it can even be useful to another beginner!  Feel free to comment on the code and design.  We are tough, we can take some criticism!  Edit:  just realized you may not find form1 right away as it will be off screen likely.  Use the Window menu then Center a Lost  Window if you need to get it on the screen.