www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.announce - turtle v0.0.6

reply Guillaume Piolat <first.last gmail.com> writes:
https://code.dlang.org/packages/turtle

"The turtle package provides a friendly, software-rendered, and 
hi-DPI drawing solution, for when all you want is a Canvas API. 
It depends on SDL for windowing."

(In reality in this early version it's only fit for really simple 
data visualization programs. Expect the API to change a lot and 
support to be inexistent.)

Example:

```d
import turtle;

int main(string[] args)
{
     runGame(new CanvasExample);
     return 0;
}

class CanvasExample : TurtleGame
{
     override void load()
     {

     }

     override void update(double dt)
     {
         if (keyboard.isDown("escape")) exitGame;
     }

     override void draw()
     {
         foreach(layer; 0..8)
             with(canvas)
             {
                 save();

                 translate(windowWidth / 2, windowHeight / 2);
                 float zoom = windowHeight/4 * (1.0 - layer / 7.0) 
^^ (1.0 + 0.2 * cos(elapsedTime));
                 scale(zoom, zoom);
                 rotate(layer + elapsedTime * (0.5 + layer * 0.1));

                 auto gradient = createCircularGradient(0, 0, 3);

                 int r = 255 - layer * 32;
                 int g = 64 + layer * 16;
                 int b = 128;
                 gradient.addColorStop(0, color(r, g, b, 255));
                 gradient.addColorStop(1, color(r/2, g/3, b/2, 
255));

                 fillStyle = gradient;

                 beginPath();
                     moveTo(-1, -1);
                     lineTo( 0, -3);
                     lineTo(+1, -1);
                     lineTo(+3,  0);
                     lineTo(+1, +1);
                     lineTo( 0, +3);
                     lineTo(-1, +1);
                     lineTo(-3,  0);
                 closePath();
                 fill();

                 restore();
             }
     }
}
```

It builds upon dplug:graphcis, itself a dg2d fork, which is a 
high-speed simple rasterizer without stroke().
May 19 2021
parent =?UTF-8?B?0JLQuNGC0LDQu9C40Lkg0KTQsNC0?= =?UTF-8?B?0LXQtdCy?= writes:
On Wednesday, 19 May 2021 at 16:41:54 UTC, Guillaume Piolat wrote:
 https://code.dlang.org/packages/turtle

 "The turtle package provides a friendly, software-rendered, and 
 hi-DPI drawing solution, for when all you want is a Canvas API. 
 It depends on SDL for windowing."

 [...]
dplug:canvas, dplug:graphcis is interesting.
                 fillStyle = gradient;
                 beginPath();
                     moveTo(-1, -1);
                     lineTo( 0, -3);
                     lineTo(+1, -1);
                     lineTo(+3,  0);
                     lineTo(+1, +1);
                     lineTo( 0, +3);
                     lineTo(-1, +1);
                     lineTo(-3,  0);
                 closePath();
                 fill();
Looks readable.
May 20 2021