Complete newbie to Free Pascal Graphics, needing a bit of help! lazarus / 39-Graphics ---------------------------------------------------------------------- OutToPascal · 2016-08-08 18:14 I am an old-time user of Turbo Pascal, including the Turtle Graphics.  (Yes, I also drew on cave walls when I was a kid.) However, there are no Turtle Graphics for Free Pascal, and I've been trying to research how to do a couple of simple drawings of a circle or a bar for a bar graph. I've found a couple of examples which were supposed to be helpful, http://wiki.freepascal.org/fcl-image , drawing a circle, but when I am copying this directly to a new program I'm getting errors with the passionRed : TFPColor = (Red:65535;Green:0;Blue:0;Alpha:65535) line, which is still just trying to get a color chosen without even attempting to draw anything.  Somewhere I saw that the TFPColor was defined in a type statement as:  TFPColor = record Red: Word; Green: Word; Blue: Word; Alpha: Word; end; and have that in the very simplistic Free Pascal program I'm writing to attempt to draw something, although it was not in the program at the wiki page and doesn't seem to matter if it is there or not.  I've put in the uses portion of the program the classes, sysutils, FPImage, FPCanvas, FPImgCanv, FPWritePNG and the program compiled with those fine. So I'm wondering what I'm doing wrong and missing, and even more basic is there a better way to be doing this than the wiki page I found? Thank you for helping. ---------------------------------------------------------------------- howardpc · 2016-08-08 19:05 You posted your question in a Lazarus subforum, so I assume you're using Lazarus in a GUI environment, not looking for an emulation of turtle graphics in a console. If so, you want to use the Canvas class and its various methods and properties, rather than the lower level FPCanvas and friends. The attached project may help to get you started. Unzip and double- click on the .lpi file. ---------------------------------------------------------------------- OutToPascal · 2016-08-08 19:41 Quote from: howardpc on August 08, 2016, 09:05:16 pmYou posted your question in a Lazarus subforum, so I assume you're using Lazarus in a GUI environment I have been wondering about that, as I'm actually just using the Free Pascal program to compile my programs.  However, I didn't see a specific Free Pascal forum, it took me to this overall forum, then I chose the graphics subsection. Is there a better place to post the question? And thanks for the help. ---------------------------------------------------------------------- Thaddy · 2016-08-08 20:08 No.This is the official forum so the best place to look for Freepascal and Lazarus. About turtle graphics: try to find the Delphi sourcecode for TfxTurtle. I used that a long time ago. AFAIK that should be - from memory - easy to translate into a Lazarus component. Was pretty basic, but I couldn't find it real quick. ---------------------------------------------------------------------- sky_khan · 2016-08-08 21:41 Please! I still remember when i first saw Turbo Pascal 1.0 on CP/M! I recommend jumping on the GUI train already. I mean you really should use Lazarus IDE. It will be much more comfortable when you become somewhat familiar with it because it has many utilities for code completion, navigation, debugging etc. You can use it for writing/compiling pure freepascal programs too. Selecting "Project->New Project->Simple Program" from Lazarus menu will give you a start for that. Clicking green arrow(ish) play button or pressing F9 will compile and run your project. If you would want to write GUI programs yourself, you will have to learn "Object Oriented" and "Event Driven" programming concepts first though. ---------------------------------------------------------------------- marcov · 2016-08-09 06:50 Afaik turtle graphics was already deprecated in the later TP's ? They packaged a fixed graph3 unit for turtle, but the normal graph was not turtle based? ---------------------------------------------------------------------- circular · 2016-08-09 08:36 @OutOfPascal: what is the error message you are getting? ---------------------------------------------------------------------- molly · 2016-08-09 10:20 I haven't had time to check it out myself (yet), but perhaps this gvlogo project might be able to help you out ? (Seems there is even a bgrabitmap backend). ---------------------------------------------------------------------- OutToPascal · 2016-08-09 17:19 Quote from: circular on August 09, 2016, 10:36:33 am@OutOfPascal: what is the error message you are getting? It is very strange, as I've tried to copy exactly as the http://wiki.freepascal.org/fcl-image program showed.  But it is definitely the line: passionRed : TFPColor = (Red: 65535; Green: 0; Blue: 0; Alpha: 65535); The error message is:  Fatal: Syntax error, ")" expected but ";" found By the position indicated, it is the ";" right after the Red: 65535. So it is almost as if it only expected one number. I also don't understand why the "Red" and "Green" etc. are included in the TFPColor, as I thought it was by the position and didn't need to be identified. ---------------------------------------------------------------------- Handoko · 2016-08-09 17:36 Hello OutToPascal. If you found fcl-image is the thing you want as the alternative of Turtle Graphics, then I recommend you to try BGRABitmap. http://wiki.freepascal.org/BGRABitmap BGRABitmap can be considered as a better version of fcl-image, it is well maintained, with more features and it has easy to follow step-by- step tutorials: http://wiki.freepascal.org/BGRABitmap_tutorial Have fun! ---------------------------------------------------------------------- jmpessoa · 2016-08-09 18:15 Try 1: declare 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  Const colPassionRed: TFPColor = (Red: 65535; Green: 0; Blue: 0; Alpha: 65535);  Use:   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 Var passionRed: TFPColor; begin  //.......  passionRed:= colPassionRed;  //.........end;  Try 2: replace with a predefined color: 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 Var   passionRed: TFPColor;begin  //............   passionRed:= colBlue; // [predefined color]  //...............end;  Others predefined color: Quote  colBlack   colBlue   colGreen   colCyan   colRed    colMagenta   colYellow   colWhite    colGray    colLtGray   colDkGray   colDkBlue      colDkGreen      colDkCyan      colDkRed        colDkMagenta    colDkYellow    colMaroon      colLtGreen      colOlive        colNavy        colPurple      colTeal        colSilver      colLime        colFuchsia   colAqua ---------------------------------------------------------------------- OutToPascal · 2016-08-18 12:44 Quote from: jmpessoa on August 09, 2016, 08:15:11 pmTry 1: declare Same error message. Quote from: jmpessoa on August 09, 2016, 08:15:11 pmTry 2: replace with a predefined color: 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 Var   passionRed: TFPColor;begin  //............   passionRed:= colBlue; // [predefined color]  //...............end;  This worked, at least it got through the compiling phase!! However, unfortunately I can't see the circle that is supposed to be drawn by the program at http://wiki.freepascal.org/fcl-image . But, good news!!  With the drawtest.png file that was saved, the circle does indeed show up!! Now I just need to get it to show up on the screen either as it is drawn or after it is completely drawn and saved as the .png file. ---------------------------------------------------------------------- OutToPascal · 2016-08-31 14:10 OK, there hasn't been much actual progress, but I did see this: https://www.youtube.com/watch?v=MahHxXEkFF0 In that video, he set up a series of balls, which were then programmed to bounce inside the work area.  The red balls would be fine for what I was wanting to do, except for the one detail that I don't see how to set the size of the ball within the program.  In the tutorial, it is set up with the Object Inspector while working with the Lazarus program.  I think I can see in the source code:  procedure TForm1.FormCreate(Sender: TObject) I'm thinking this defines the shape, size, and initial location of the balls, but I don't see any code where that is.  It is not in the Pascal source code file.  It is just: "Balls[1] := Shape1;" and I can't find where "Shape1" is defined and/or specified. The other alternative is to keep working with the FreePascal, where I can set the size of the ball, and figure out how to display the saved "test.png" file, but I haven't figured that out either. ---------------------------------------------------------------------- howardpc · 2016-08-31 15:34 If you put your cursor on Shape1 in the code and press Alt-Up the Lazarus IDE jumps to the declaration of Shape1. You'll see that Shape1..Shape5 are all TShape controls which were droppped onto Form1 (from the Additional tab of the component palette). Their initial properties (shape, size, initial location etc.) have been set in the Object Inspector. These initial values are all stored in unit1.lfm at design-time, and once you compile your program, the executable loads their values from a compiled resource which has been linked into the running executable. This is what 'publishing' properties is all about. It means the initial property values are saved within the executable itself (they are now 'persistent'), and so available to be read at run-time when program initialisation takes place. This is an automatic process that the RAD IDE manages for you. It relies on the control you want initialised being placed in a published section of its containing TForm class (although there is no published visibility specifier explicit above the declaration of TShape1, the first section of any TPersistent descendant  - such as TForm - is published by default)the properties to be automatically initialised themselves being publishedthe compiler directive {$R *.lfm} being included in the form unitlots of normally unseen code that manages all the writing (and later reading) of property data values to keep the stored run-time information in perfect sync with all changes you make via the object inspector (or in code). Except that this code does not need to remain unseen. FPC and Lazarus being open source projects, you can view the full code that does all this if you are so inclined. ---------------------------------------------------------------------- OutToPascal · 2016-09-01 22:42 Quote from: howardpc on August 31, 2016, 05:34:34 pmTheir initial properties (shape, size, initial location etc.) have been set in the Object Inspector. These initial values are all stored in unit1.lfm at design-time, and once you compile your program, the executable loads their values from a compiled resource which has been linked into the running executable. This is what 'publishing' properties is all about. It means the initial property values are saved within the executable itself (they are now 'persistent'), and so available to be read at run-time when program initialisation takes place. Thanks for the information, I'd been wondering about the "published" command. The rest I'm going to have to be researching more, as it all still seems pretty technical to me trying to learn it.