Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turtle stamp function #84

Open
jamesdbrock opened this issue Dec 8, 2020 · 4 comments
Open

Turtle stamp function #84

jamesdbrock opened this issue Dec 8, 2020 · 4 comments

Comments

@jamesdbrock
Copy link

Hi, thanks for this library @mgsloan , it's really great!

I want a function which enables the turtle to render any diagram at its current location, with its current orientation.

I would call this function stamp, like the idea of using a rubber ink stamp on paper.

I think the stamp function should have this type signature?

stamp 
  :: (Renderable (Path V2 n) b, TypeableFloat n, OrderedField n, Monad m) 
  => QDiagram b V2 n Any 
  -> TurtleT n m ()

I'm going to try to write this stamp function. Do you know if anyone else has ever written it? Do you have any advice for writing it?

Reference:
http://hackage.haskell.org/package/diagrams-contrib-1.4.4/docs/Diagrams-TwoD-Path-Turtle.html

Possibly related: #5

@byorgey
Copy link
Member

byorgey commented Dec 8, 2020

Hi @jamesdbrock , that sounds like a cool idea!

So the way the Turtle library works is by accumulating a state which describes the paths that the turtle has drawn, their styles, etc. Then at the end you can render a Turtle state into a Diagram. (Take a look at Diagrams.TwoD.Path.Turtle.Internal.) In order to implement stamp you would have to add something to the Turtle state, which could just be a list of Diagrams. Every time stamp is called you add an (appropriately translated and rotated) diagram to the list. Then when doing the final render of a Turtle state into a Diagram you can just use mconcat to add in all those diagrams. There's probably some tricky issues to figure out in terms of what gets drawn on top of what, but I think this should be doable.

@jamesdbrock
Copy link
Author

you would have to add something to the Turtle state

Ah, yes, I see that now, thanks for pointing that out.

@jamesdbrock
Copy link
Author

Maybe we could change the type of paths to be

data TurtleState n = TurtleState
  { ...
  , paths        :: [Either (TurtlePath n) (Located (QDiagram b V2 n Any ))]
  }

@byorgey
Copy link
Member

byorgey commented Dec 9, 2020

Yes, that makes sense. Although there's no need to use Located QDiagram---just QDiagram will suffice since diagrams are already inherently located.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants