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

Repeat transformation #45

Closed
FayCarsons opened this issue Oct 14, 2023 · 5 comments
Closed

Repeat transformation #45

FayCarsons opened this issue Oct 14, 2023 · 5 comments
Labels
help wanted Extra attention is needed

Comments

@FayCarsons
Copy link
Collaborator

The original Joy python library has a "higher order transformation" called repeat that applies a set of transformations iteratively to a provided initial shape.

Now that we have some transformations, rotate, translate, scale(I think? Not sure if it's been merged), this seems like it would be a fun feature to have.

I have a clear idea of how to implement this declaratively with List.fold_right and would love to get started on it ASAP :)

@nangahamandine
Copy link
Contributor

@FayCarsons this is quite nice! I like how you have the most amazing ideas and are so enthusiastic, it's motivating... :)
Would love to see how this plays out!

@nikochiko
Copy link
Collaborator

nikochiko commented Oct 15, 2023

@FayCarsons i feel we need a few more changes before it would make sense to start working on this:

  • I think we should have a shape type for "a list of shapes"
  • Representing combinations of transformations themselves

A type for group of shapes

Reason behind a separate type instead of using list shape is that I want to be able to make a new shape from existing shapes, and then apply transformations on them as a whole like any other shape -- rather than having to handle that type specially.

e.g. let's say we have a donut

let donut = shape_sum (circle 50) (circle 100 |> color "black")

I want to be able to scale that donut the same way I scale other shapes

let () = show [donut |> scale 0.5]

Representing series of transformations

This is so that we can combine transformations and represent slightly more advanced transformations such as "scale this shape by 0.5 then rotate by 45 degrees".

We can probably recommend using currying and something like composition for this, and utilise the function signature of a transformation (which is shape -> shape).

Something like:

(* compose right-to-left -- function on right is applied first *)
let compose_rtl f g x = g (f x)

let () =
  let halve_and_rotate = compose_rtl (scale 0.5) (rotate 30) in
  let rectangles = List.init 6 (fun _ -> rectangle 50 50) in
  show (List.map halve_and_rotate rectangles)

We should create examples for such use cases if this API looks good enough.

@Sudha247 what do you think?

@nikochiko nikochiko added the help wanted Extra attention is needed label Oct 15, 2023
@Sudha247
Copy link
Owner

Indeed, shape group and compose transformation are useful features to have. @FayCarsons are you interested in making PRs for those? I'd recommend making them as separate PRs. It's easier to review and merge that way.

@FayCarsons
Copy link
Collaborator Author

I can absolutely take these on! May need to ask more questions than usual but they both seem doable to me.

In the case of the sort of compound shape type, is there any reason we couldn't just extend the shape type to also include shape list and add cases in match blocks to handle that? Like refactoring translate, for example, to map over a shape list if passed that instead of a single shape.

@Sudha247
Copy link
Owner

Fixed by #71.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants