Recent

Author Topic: Complete newbie to Free Pascal Graphics, needing a bit of help!  (Read 11455 times)

OutToPascal

  • New member
  • *
  • Posts: 7
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

  • Hero Member
  • *****
  • Posts: 4144
Re: Complete newbie to Free Pascal Graphics, needing a bit of help!
« Reply #1 on: August 08, 2016, 09:05:16 pm »
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

  • New member
  • *
  • Posts: 7
Re: Complete newbie to Free Pascal Graphics, needing a bit of help!
« Reply #2 on: August 08, 2016, 09:41:50 pm »
You 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

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Complete newbie to Free Pascal Graphics, needing a bit of help!
« Reply #3 on: August 08, 2016, 10:08:59 pm »
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.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

sky_khan

  • Guest
Re: Complete newbie to Free Pascal Graphics, needing a bit of help!
« Reply #4 on: August 08, 2016, 11:41:10 pm »
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

  • Administrator
  • Hero Member
  • *
  • Posts: 11453
  • FPC developer.
Re: Complete newbie to Free Pascal Graphics, needing a bit of help!
« Reply #5 on: August 09, 2016, 08:50:27 am »
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

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: Complete newbie to Free Pascal Graphics, needing a bit of help!
« Reply #6 on: August 09, 2016, 10:36:33 am »
@OutOfPascal: what is the error message you are getting?
Conscience is the debugger of the mind

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: Complete newbie to Free Pascal Graphics, needing a bit of help!
« Reply #7 on: August 09, 2016, 12:20:56 pm »
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

  • New member
  • *
  • Posts: 7
Re: Complete newbie to Free Pascal Graphics, needing a bit of help!
« Reply #8 on: August 09, 2016, 07:19:10 pm »
@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.
« Last Edit: August 09, 2016, 07:22:20 pm by OutToPascal »

Handoko

  • Hero Member
  • *****
  • Posts: 5154
  • My goal: build my own game engine using Lazarus
Re: Complete newbie to Free Pascal Graphics, needing a bit of help!
« Reply #9 on: August 09, 2016, 07:36:41 pm »
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

  • Hero Member
  • *****
  • Posts: 2301
Re: Complete newbie to Free Pascal Graphics, needing a bit of help!
« Reply #10 on: August 09, 2016, 08:15:11 pm »
Try 1: declare

Code: Pascal  [Select][+][-]
  1.  
  2. Const
  3.  colPassionRed: TFPColor = (Red: 65535; Green: 0; Blue: 0; Alpha: 65535);
  4.  

Use:
   
Code: Pascal  [Select][+][-]
  1. Var
  2.  passionRed: TFPColor;
  3. begin
  4.   //.......
  5.   passionRed:= colPassionRed;
  6.   //.........
  7. end;
  8.  

Try 2:

replace with a predefined color:

Code: Pascal  [Select][+][-]
  1. Var
  2.    passionRed: TFPColor;
  3. begin
  4.   //............
  5.    passionRed:= colBlue; // [predefined color]
  6.   //...............
  7. end;
  8.  

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 
« Last Edit: August 09, 2016, 09:26:55 pm by jmpessoa »
Lamw: Lazarus Android Module Wizard
https://github.com/jmpessoa/lazandroidmodulewizard

OutToPascal

  • New member
  • *
  • Posts: 7
Re: Complete newbie to Free Pascal Graphics, needing a bit of help!
« Reply #11 on: August 18, 2016, 02:44:46 pm »
Try 1: declare

Same error message.

Try 2:

replace with a predefined color:

Code: Pascal  [Select][+][-]
  1. Var
  2.    passionRed: TFPColor;
  3. begin
  4.   //............
  5.    passionRed:= colBlue; // [predefined color]
  6.   //...............
  7. end;
  8.  

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.
« Last Edit: August 18, 2016, 03:30:34 pm by OutToPascal »

OutToPascal

  • New member
  • *
  • Posts: 7
Re: Complete newbie to Free Pascal Graphics, needing a bit of help!
« Reply #12 on: August 31, 2016, 04:10:20 pm »
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

  • Hero Member
  • *****
  • Posts: 4144
Re: Complete newbie to Free Pascal Graphics, needing a bit of help!
« Reply #13 on: August 31, 2016, 05:34:34 pm »
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 published
  • the compiler directive {$R *.lfm} being included in the form unit
  • lots 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.
« Last Edit: August 31, 2016, 05:59:08 pm by howardpc »

OutToPascal

  • New member
  • *
  • Posts: 7
Re: Complete newbie to Free Pascal Graphics, needing a bit of help!
« Reply #14 on: September 02, 2016, 12:42:41 am »
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.

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.

 

TinyPortal © 2005-2018