Lazarus

Programming => Graphics and Multimedia => Graphics => Topic started by: lainz on December 02, 2017, 12:39:10 am

Title: Turtle Graphics
Post by: lainz on December 02, 2017, 12:39:10 am
Turtle Graphics with BGRABitmap and BGRAControls:
https://github.com/lainz/turtlegraphics

Video of the application:
https://www.youtube.com/watch?v=-ZW0bihDjUY&vq=hd720

When I discovered turtle graphics I got amazed! I discovered turtle graphics in a demo that comes with Python IDLE, in the help menu. There you can find a lot of amazing examples to get inspired, or even port these to Pascal!
Title: Re: Turtle Graphics
Post by: lrcvsx on December 04, 2017, 08:37:51 pm
Hi: lainz


Look at YT the Xkrouhn channel, all videos are made with Freebasic Turtle.

Freebasic turle, I started it about 3 years ago, my latest version is the Turtle9.

Specifically watch the video: Freebasic Turtle.

Your example seems like an imitation of my program 3 years ago.

I wish you like the examples.

regards
Title: Re: Turtle Graphics
Post by: lainz on December 04, 2017, 08:55:43 pm
Awesome channel, I found that video, is almost the same I did =)

But you did it in 2013!

I just increased the angle more slowly.

Here is the Canvas version:
https://lainz.github.io/webapps/turtlegraphics/

And another using Fibonacci:
https://lainz.github.io/webapps/turtlegraphicsfibonacci/

Impressive videos in your channel.

Edit: I found another exactly with the same code! 2015
https://www.youtube.com/watch?v=44kYhWmhJyI
Title: Re: Turtle Graphics
Post by: lrcvsx on December 04, 2017, 09:32:03 pm
Hi

Ja, ja, ja...

One casuality!

Note: 4 years

Regards
Title: Re: Turtle Graphics
Post by: lainz on December 05, 2017, 01:10:14 am
Hi

Ja, ja, ja...

One casuality!

Note: 4 years

Regards

Also notice every one that did this is in a different programming language, I never hear of Freebasic until today! Neither used FMS Logo from that video of 2015 I commented.

Edit: FMS Logo website features this kind of code in his main page, attached picture.

I think this code is older than we think.

Edit 2: A 1998 website!
https://web.archive.org/web/20171205012345/https://courses.cs.washington.edu/courses/cse341/98sp/assignments/assignment1.html

Is called a squiral

Edit 3: 1983
https://web.archive.org/web/20170927224843/https://www.atarimagazines.com/compute/issue32/063_1_HIGH_RESOLUTION_TURTLE_GRAPHICS.php
Title: Re: Turtle Graphics
Post by: dubst3pp4 on December 05, 2017, 07:39:54 am
Hi lainz, great idea and a great JavaScript version! Back in the 90s as a kid I started to learn programming in school with turtle graphics, I think it must have been the Logo programming language (https://en.wikipedia.org/wiki/Logo_(programming_language)).

It is still a great concept to get kids (and adults, too) into programming, as you can see immediately the effect of your code and ideas.

Best regards,
Marc
Title: Re: Turtle Graphics
Post by: marcov on December 05, 2017, 12:04:00 pm
Afaik turbo pascal 3 came with a turtle graph unit, but it was later deprecated in favor of a more modern Graph, the one that FPC provides.

The old one is known as "graph3"
Title: Re: Turtle Graphics
Post by: Thaddy on December 05, 2017, 12:07:17 pm
Afaik turbo pascal 3 came with a turtle graph unit, but it was later deprecated in favor of a more modern Graph, the one that FPC provides.

The old one is known as "graph3"

TP3 is available for free here: http://edn.embarcadero.com/article/20792 You will need an account for the download and login first.
There is a good chance the turtle graph  works, maybe just in TP mode on i8086 (dosbox), but maybe needs trunk for that.
I did not check. I have only TP 1.0 and TP 5.5 from the museum.
Title: Re: Turtle Graphics
Post by: lrcvsx on December 05, 2017, 02:52:54 pm
Hi, lainz:

Many years ago, I used with TP3 and later with TP7.

Then I started with GW, QB, MSWLOGO, FMSLOGO and finally with FB.

Some examples are in YT, Xkrouhn

I like to program simply for hobby.
Title: Re: Turtle Graphics
Post by: lainz on December 05, 2017, 03:59:25 pm
Hi, lainz:

Many years ago, I used with TP3 and later with TP7.

Then I started with GW, QB, MSWLOGO, FMSLOGO and finally with FB.

Some examples are in YT, Xkrouhn

I like to program simply for hobby.

I started programming as a hobby also (now I'm working and also studiying for a career), first with Lua script, then Pascal, JavaScript (Browser & Node.js), PHP, C#, Java...

Hi lainz, great idea and a great JavaScript version! Back in the 90s as a kid I started to learn programming in school with turtle graphics, I think it must have been the Logo programming language (https://en.wikipedia.org/wiki/Logo_(programming_language)).

It is still a great concept to get kids (and adults, too) into programming, as you can see immediately the effect of your code and ideas.

Best regards,
Marc

Thanks, and yes is very intuitive.

Afaik turbo pascal 3 came with a turtle graph unit, but it was later deprecated in favor of a more modern Graph, the one that FPC provides.

The old one is known as "graph3"
Afaik turbo pascal 3 came with a turtle graph unit, but it was later deprecated in favor of a more modern Graph, the one that FPC provides.

The old one is known as "graph3"

TP3 is available for free here: http://edn.embarcadero.com/article/20792 You will need an account for the download and login first.
There is a good chance the turtle graph  works, maybe just in TP mode on i8086 (dosbox), but maybe needs trunk for that.
I did not check. I have only TP 1.0 and TP 5.5 from the museum.

There are a lot of libraries out there, I know my example lacks of many of the functions from all these libraries.
Title: Re: Turtle Graphics
Post by: alaa123456789 on January 18, 2021, 08:29:24 pm
hi all ,
turtle is very and interesting subject , as it was with us in younger stage , so i found very useful component in delphi , but we need help of you to convert to Lazarus package
please all help
http://arbeitsplattform.bildung.hessen.de/fach/informatik/delphi/rekgraf/rekgraf2.htm.html (http://arbeitsplattform.bildung.hessen.de/fach/informatik/delphi/rekgraf/rekgraf2.htm.html)
Title: Re: Turtle Graphics
Post by: lainz on January 18, 2021, 11:43:33 pm
If you look at my code, you can see that move and rotate are implemented, color is just another property in bgrabitmap drawing, so it already works, try using that.
Title: Re: Turtle Graphics
Post by: Fred vS on January 18, 2021, 11:56:12 pm
If you look at my code, you can see that move and rotate are implemented, color is just another property in bgrabitmap drawing, so it already works, try using that.

https://github.com/lainz/turtlegraphics

WOW, very impressive, fast and out-of-the-box.

Congrats.
Title: Re: Turtle Graphics
Post by: lainz on January 19, 2021, 12:13:10 am
If you look at my code, you can see that move and rotate are implemented, color is just another property in bgrabitmap drawing, so it already works, try using that.

https://github.com/lainz/turtlegraphics

WOW, very impressive, fast and out-of-the-box.

Congrats.

Thanks to @circular, he did the code, I grabbed it from somewhere in this big forum  :)
Title: Re: Turtle Graphics
Post by: Fred vS on January 19, 2021, 12:50:33 am
If you look at my code, you can see that move and rotate are implemented, color is just another property in bgrabitmap drawing, so it already works, try using that.

https://github.com/lainz/turtlegraphics

WOW, very impressive, fast and out-of-the-box.

Congrats.

Thanks to @circular, he did the code, I grabbed it from somewhere in this big forum  :)

Thanks to both.

Huh, do you think I could use it for the Strumpract-Image-Dancer?
I just try it making dance and it is bluffing (and with color changing 2xWow).
Title: Re: Turtle Graphics
Post by: lainz on January 19, 2021, 01:31:21 am
Sure, keep hacking  :)
Title: Re: Turtle Graphics
Post by: Fred vS on January 19, 2021, 01:38:15 am
Sure, keep hacking  :)

OK, done!
The angle value is perfect to make it dance.

What is your advice to avoid flickering changing color?
I search for a way to changing smoothly the colors because jumping from red to blue for example gives a flickering effect.
Maybe step by step from one color to the other ?

Title: Re: Turtle Graphics
Post by: alaa123456789 on January 19, 2021, 07:51:44 am
If you look at my code, you can see that move and rotate are implemented, color is just another property in bgrabitmap drawing, so it already works, try using that.
i have looked at your sample , it is very nice , but little complicated for beginners , if possible someone who is expert who make a component called turtle so we just give it the orders (move.rotate .....etc) same as in other programming languages .it would be great

thanks to all
Title: Re: Turtle Graphics
Post by: lainz on January 19, 2021, 03:42:27 pm
Sure, keep hacking  :)

OK, done!
The angle value is perfect to make it dance.

What is your advice to avoid flickering changing color?
I search for a way to changing smoothly the colors because jumping from red to blue for example gives a flickering effect.
Maybe step by step from one color to the other ?

Yes, store 2 colors and you can make a blend with a percentage I think, just can't remember how.  :-[

Do the blending percentage over time.

If you look at my code, you can see that move and rotate are implemented, color is just another property in bgrabitmap drawing, so it already works, try using that.
i have looked at your sample , it is very nice , but little complicated for beginners , if possible someone who is expert who make a component called turtle so we just give it the orders (move.rotate .....etc) same as in other programming languages .it would be great

thanks to all

You mean a scripting tool?

Or, just a TComponent that can be used with an OnPaint event?
Title: Re: Turtle Graphics
Post by: Fred vS on January 19, 2021, 03:54:38 pm
Sure, keep hacking  :)

OK, done!
The angle value is perfect to make it dance.

What is your advice to avoid flickering changing color?
I search for a way to changing smoothly the colors because jumping from red to blue for example gives a flickering effect.
Maybe step by step from one color to the other ?

Yes, store 2 colors and you can make a blend with a percentage I think, just can't remember how.  :-[

Do the blending percentage over time.


OK, thanks.

What I do for the moment is to vary the value of G, something like this:

Code: Pascal  [Select][+][-]
  1. set_color(Bitmap, 255, round(128*multiplier), 64, 255);

Of course if only gives a palette between yellow-orange and red.
There is no flickering.
It would be nice to switch to the colors of the rainbow.

But this is only detail, your code is "really" impressive (and totally hypnotic).

Thanks a lot.

Fre;D

     

Title: Re: Turtle Graphics
Post by: alaa123456789 on January 19, 2021, 03:58:51 pm
i attached one component but it is in delphi, it use timage , and i attached link for the German page
yes it is much easier , you just give rotate,move,draw and it will be drawn on the image,please have a look on the attachment.

thanks 
Title: Re: Turtle Graphics
Post by: lainz on January 19, 2021, 04:11:56 pm
i attached one component but it is in delphi, it use timage , and i attached link for the German page
yes it is much easier , you just give rotate,move,draw and it will be drawn on the image,please have a look on the attachment.

thanks

Here is the automatic conversion with Lazarus convert from delphi menu, can you try it?

If you can make a small demo on how to use it =)
Title: Re: Turtle Graphics
Post by: lainz on January 19, 2021, 04:17:33 pm
Sure, keep hacking  :)

OK, done!
The angle value is perfect to make it dance.

What is your advice to avoid flickering changing color?
I search for a way to changing smoothly the colors because jumping from red to blue for example gives a flickering effect.
Maybe step by step from one color to the other ?

Yes, store 2 colors and you can make a blend with a percentage I think, just can't remember how.  :-[

Do the blending percentage over time.


OK, thanks.

What I do for the moment is to vary the value of G, something like this:

Code: Pascal  [Select][+][-]
  1. set_color(Bitmap, 255, round(128*multiplier), 64, 255);

Of course if only gives a palette between yellow-orange and red.
There is no flickering.
It would be nice to switch to the colors of the rainbow.

But this is only detail, your code is "really" impressive (and totally hypnotic).

Thanks a lot.

Fre;D

     

Circular said we can use MergeBGRA

I think it can be used like this

Code: Pascal  [Select][+][-]
  1. var
  2.   p1, p2: TBGRAPixel;
  3. begin
  4.   p2.Alpha := 100; // 99, 98, 97... when time passes by
  5.   MergeBGRA(p1, p2);  


Quote from: circular
For a percentage you can for example assign 30 and 70 for the weights (30 + 70
= 100)

So using the alternative version of the function..
Title: Re: Turtle Graphics
Post by: alaa123456789 on January 19, 2021, 05:33:55 pm
i know conversion, could you put this and make new package so we can use it in any application?
Title: Re: Turtle Graphics
Post by: lainz on January 19, 2021, 09:41:30 pm
i know conversion, could you put this and make new package so we can use it in any application?

Please create a demo on how to use it-

To create a package go to lazarus Packages > New package. Save it somewhere. Go to the package folder and copy and paste the uturtle.pas, then in the package viewer in lazarus use add files, and add uturtle.pas.

Then you can share it =)
Title: Re: Turtle Graphics
Post by: Fred vS on January 19, 2021, 10:38:09 pm

  p1, p2: TBGRAPixel;
begin
  p2.Alpha := 100; // 99, 98, 97... when time passes by
  MergeBGRA(p1, p2);

Quote from: circular
For a percentage you can for example assign 30 and 70 for the weights (30 + 70
= 100)

So using the alternative version of the function..

Hello.

OK, thanks, I will study this.

I did some custom test, the result is great in animation.
Title: Re: Turtle Graphics
Post by: lainz on January 20, 2021, 12:55:56 am
Cool, I think I did the same, using 2 colors, one at the center  :)
https://lainz.github.io/webapps/squiraltour/

Title: Re: Turtle Graphics
Post by: Fred vS on January 20, 2021, 01:38:54 am
Cool, I think I did the same, using 2 colors, one at the center  :)
https://lainz.github.io/webapps/squiraltour/

DPM!

WOW.
Title: Re: Turtle Graphics
Post by: alaa123456789 on January 20, 2021, 05:02:18 pm
i know conversion, could you put this and make new package so we can use it in any application?

Please create a demo on how to use it-

To create a package go to lazarus Packages > New package. Save it somewhere. Go to the package folder and copy and paste the uturtle.pas, then in the package viewer in lazarus use add files, and add uturtle.pas.

Then you can share it =)
i did already ,but when i put it on new application it doesn't work and the background is black , also not resizing

please modify the attachment and re-share it so everyone can get benefit of it

thanks 
Title: Re: Turtle Graphics
Post by: lainz on January 21, 2021, 05:50:43 pm
i did already ,but when i put it on new application it doesn't work and the background is black , also not resizing

please modify the attachment and re-share it so everyone can get benefit of it

thanks

Hi, I've refactored my code so is more easy to use.

This is the unit
https://github.com/lainz/turtlegraphics/blob/master/bgraturtle.pas

How to use?

1) Install BGRABitmap and BGRAControls.
2) Drop a BGRAVirtualScreen.
3) Add BGRATurtle.pas in Uses.
4) Add OnRedraw event for BGRAVirtualScreen1.
5) Use the turtle methods in the OnRedraw event.

Methods?

Bitmap.MoveTurtle(distance: single);
Bitmap.RotateTurtle(angle: single);
Bitmap.TranslateTurtle(x: single; y: single);
Bitmap.ResetTurtle;
Bitmap.ColorTurtle(red, green, blue: byte; alpha: byte = 255);

Full demo:
https://github.com/lainz/turtlegraphics/blob/master/umain.pas

If you want to other people use my demo feel free to share it, it already works, so they need to only replace the code in the OnRedraw event. It has animation support, but you can disable it as well removing the timer code.
Title: Re: Turtle Graphics
Post by: winni on January 22, 2021, 11:59:36 pm
Hilbert Curve with BGRAturtle!

I did a deep search in my HD and found it again:

The UCSD Pascal Demo from  1979 for the Apple II using Turtlegraphics to show the Hilbert Curve.

I adapted the code to BGRAturtle but left as much as possible of the old code untouched.

The project and a SC is attached.

Title: Re: Turtle Graphics
Post by: lainz on January 23, 2021, 02:15:08 am
Thanks  :)
Title: Re: Turtle Graphics
Post by: lucamar on January 23, 2021, 04:33:11 am
Black text on yellow background ... ouch! ouch! :D
Title: Re: Turtle Graphics
Post by: circular on January 23, 2021, 11:47:22 am
Nice, the code is almost the same as the original.  8)

@lucamar
Maybe this needs some magenta as well  :P
Title: Re: Turtle Graphics
Post by: winni on January 23, 2021, 12:59:39 pm
Black text on yellow background ... ouch! ouch! :D

Hi Lucamar!

Seems the germans love that:

Opel Manta (RIP)
BVB Dortmund
Deutsche Post DHL
....

Winni
Title: Re: Turtle Graphics
Post by: winni on January 23, 2021, 05:30:33 pm
@lainz (and all who are interested)

Hi!

If found the manual for the library (now:unit ) TurtleGraphics for UCSD Pascal aka Apple Pascal for the Apple II.

10 PDF  Pages in the attachment.

Winni
Title: Re: Turtle Graphics
Post by: lainz on January 28, 2021, 03:32:37 am
Thanks winni.
In the demo I've seen the moveTo method. Maybe I add that to the list. Any other thing missing?
Title: Re: Turtle Graphics
Post by: winni on January 29, 2021, 12:33:19 am
Hi Lainz!

Boah! It is 35 years that I used last time the TurtleGraphics ....

Analog to moveto (x,y) there was

Code: Pascal  [Select][+][-]
  1. turnto (AbsolutAngle)

And asking the Turtle about the current values:

Code: Pascal  [Select][+][-]
  1. X := TurtleX;
  2. Y := TurtleY;
  3. Angle := TurtleAng;
  4.  

And in later versions (I Think ...) there came

Code: Pascal  [Select][+][-]
  1. TurtleHide;
  2. TurteShow;

And there was also

Code: Pascal  [Select][+][-]
  1. Pencolor (Color);
  2.  

Nobody used that.
On the one hand they had strange definitios (Black, Black1, Black2, ....).
And second in those days nobody had a color Monitor because this was really  expensive .
And the color resolution was 48x40 Pixel. Just a stamp .....

Winni






TinyPortal © 2005-2018