Recent

Author Topic: Turtle Graphics  (Read 7189 times)

lainz

  • Hero Member
  • *****
  • Posts: 3957
  • Leandro Diaz
Re: Turtle Graphics
« Reply #15 on: January 19, 2021, 01:31:21 am »
Sure, keep hacking  :)
https://lainz.github.io/ - My Website :)
https://lazpaint.github.io/ -  Download LazPaint

Fred vS

  • Hero Member
  • *****
  • Posts: 2082
    • StrumPract is the musicians best friend
Re: Turtle Graphics
« Reply #16 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 ?

« Last Edit: January 19, 2021, 02:25:12 am by Fred vS »
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

alaa123456789

  • Full Member
  • ***
  • Posts: 146
Re: Turtle Graphics
« Reply #17 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

lainz

  • Hero Member
  • *****
  • Posts: 3957
  • Leandro Diaz
Re: Turtle Graphics
« Reply #18 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?
https://lainz.github.io/ - My Website :)
https://lazpaint.github.io/ -  Download LazPaint

Fred vS

  • Hero Member
  • *****
  • Posts: 2082
    • StrumPract is the musicians best friend
Re: Turtle Graphics
« Reply #19 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

     

« Last Edit: January 19, 2021, 03:56:10 pm by Fred vS »
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

alaa123456789

  • Full Member
  • ***
  • Posts: 146
Re: Turtle Graphics
« Reply #20 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 

lainz

  • Hero Member
  • *****
  • Posts: 3957
  • Leandro Diaz
Re: Turtle Graphics
« Reply #21 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 =)
https://lainz.github.io/ - My Website :)
https://lazpaint.github.io/ -  Download LazPaint

lainz

  • Hero Member
  • *****
  • Posts: 3957
  • Leandro Diaz
Re: Turtle Graphics
« Reply #22 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..
« Last Edit: January 19, 2021, 10:16:39 pm by lainz »
https://lainz.github.io/ - My Website :)
https://lazpaint.github.io/ -  Download LazPaint

alaa123456789

  • Full Member
  • ***
  • Posts: 146
Re: Turtle Graphics
« Reply #23 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?

lainz

  • Hero Member
  • *****
  • Posts: 3957
  • Leandro Diaz
Re: Turtle Graphics
« Reply #24 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 =)
https://lainz.github.io/ - My Website :)
https://lazpaint.github.io/ -  Download LazPaint

Fred vS

  • Hero Member
  • *****
  • Posts: 2082
    • StrumPract is the musicians best friend
Re: Turtle Graphics
« Reply #25 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.
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

lainz

  • Hero Member
  • *****
  • Posts: 3957
  • Leandro Diaz
Re: Turtle Graphics
« Reply #26 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/

https://lainz.github.io/ - My Website :)
https://lazpaint.github.io/ -  Download LazPaint

Fred vS

  • Hero Member
  • *****
  • Posts: 2082
    • StrumPract is the musicians best friend
Re: Turtle Graphics
« Reply #27 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.
I use Lazarus 2.0.6 32/64 and FPC 3.2.0 32/64 on Debian 10.2 64 bit, Windows 10, Windows 7 32/64, Windows XP 32,  FreeBSD 64 and Mac OS X Snow Leopard 32.
Widgetset: fpGUI, MSEgui, Win32, GTK2, Qt, Carbon.

https://github.com/fredvs
https://gitlab.com/fredvs

alaa123456789

  • Full Member
  • ***
  • Posts: 146
Re: Turtle Graphics
« Reply #28 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 

lainz

  • Hero Member
  • *****
  • Posts: 3957
  • Leandro Diaz
Re: Turtle Graphics
« Reply #29 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.
https://lainz.github.io/ - My Website :)
https://lazpaint.github.io/ -  Download LazPaint

 

TinyPortal © 2005-2018