Giter Club home page Giter Club logo

abap-turtle-graphics's Introduction

logo

abap package version

Announcement blog

Enterprise-grade turtle graphics library for abap intended for business-oriented children or bored adults.

The graphics are generated in the svg format.

Installation

Import the repository to your system using abapGit.

Usage example

Turtle

REPORT zabapturtle.

DATA(turtle) = NEW zcl_turtle( height = 800 width = 800 ).

turtle->set_pen( VALUE #( stroke_width = 2 ) ).

turtle->goto( x = 200 y = 200 ).
DATA(i) = 0.
DATA(n) = 15.
WHILE i < n.
  turtle->polygon( num_sides = 10 side_length = 50 ).
  turtle->right( 360 / n ).

  i += 1.
ENDWHILE.

turtle->show( ).

You can also save the image using turtle->download().

image

see zcl_turtle_examples for more

Supported instructions

zcl_turtle

movement:

  • forward, back
  • left,right (rotate by x degrees)
  • pen up/down (only considered when moving, not when outputting svg directly)

styling:

  • background color
  • stroke width
  • stroke color
  • fill color

zcl_turtle_svg

Generate svg primitives:

  • line
  • circle
  • polyline
  • polygon
  • text

Note that this only returns the svg string. Add these shapes to a turtle using turtle->append_svg.

Color schemes: A random color is used for each line. You can use turtle->set_color_scheme( ) to change the colors.

L-systems (or TurtleScript, if you will)

Wiki link

Define an initial state, a number of iterations and a set of replacement rules. These will be applied in each iteration. Finally, the symbols are translated into instructions and executed.

Supported operations:

  • movement
  • rotation
  • stack push/pop

See zcl_turtle_lsystem=>instruction_kind.

DATA(turtle) = zcl_turtle=>new( height = 800 width = 600 ).
turtle->goto( x = 200 y = 200 ).

DATA(parameters) = VALUE zcl_turtle_lsystem=>params(
  initial_state = `F`
  instructions = VALUE #(
    ( symbol = 'F' kind = zcl_turtle_lsystem=>instruction_kind-forward amount = 10 )
    ( symbol = '+' kind = zcl_turtle_lsystem=>instruction_kind-right amount = 90 )
    ( symbol = '-' kind = zcl_turtle_lsystem=>instruction_kind-left amount = 90 ) )
  num_iterations = 3
  rewrite_rules = VALUE #(
    ( from = `F` to = `F+F-F-F+F` )
    )
).

DATA(lsystem) = zcl_turtle_lsystem=>new(
  turtle = turtle
  parameters = parameters ).

lsystem->execute( ).
lsystem->show( ).

image

The stack can be used to generate plants or trees:

DATA(turtle) = zcl_turtle=>new( height = 800 width = 600 ).
turtle->goto( x = 300 y = 600 ).
turtle->set_angle( -90 ).

DATA(parameters) = VALUE zcl_turtle_lsystem=>params(
  initial_state = `F`
  instructions = VALUE #(
    ( symbol = `F` kind = zcl_turtle_lsystem=>instruction_kind-forward amount = 10 )
    ( symbol = `+` kind = zcl_turtle_lsystem=>instruction_kind-right amount = 25 )
    ( symbol = `-` kind = zcl_turtle_lsystem=>instruction_kind-left amount = 25 )
    ( symbol = `[` kind = zcl_turtle_lsystem=>instruction_kind-stack_push )
    ( symbol = `]` kind = zcl_turtle_lsystem=>instruction_kind-stack_pop )
  )
  num_iterations = 5
  rewrite_rules = VALUE #(
    ( from = `F` to = `F[+F]F[-F][F]` )
    )
).

DATA(lsystem) = zcl_turtle_lsystem=>new(
  turtle = turtle
  parameters = parameters ).

lsystem->execute( ).
lsystem->show( ).

image

abap-turtle-graphics's People

Contributors

frehu avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.