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

Add 2D Graphics library #39

Merged
merged 8 commits into from
Oct 12, 2024
Merged

Add 2D Graphics library #39

merged 8 commits into from
Oct 12, 2024

Conversation

paulcadman
Copy link
Collaborator

@paulcadman paulcadman commented Sep 24, 2024

The goal of this PR is to provide a 2D Graphics library layer on top of raylib's API that's more uniform with respect to coordinates in a window and provides scaling and translation transformations on rectangles and circles and aggregations thereof.

The coordinate system for objects in the 2D Graphics library has its origin in the centre of the window instead of the top-left of the screen. And the y-axis values increase with increasing height.

See the Window and Orbital demos for examples of usage.

This PR also adds the cfold and collect ECS system functions that can be used to fold over / collect matching components respectively. The collect function is used in the Orbital demo.

@paulcadman paulcadman marked this pull request as ready for review October 12, 2024 20:12
@paulcadman paulcadman merged commit 165c01a into main Oct 12, 2024
2 checks passed
@paulcadman paulcadman deleted the 2d-graphics branch October 12, 2024 20:20
instance : Inhabited Picture where
default := .blank

instance : Append Picture where
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paulcadman Picture is probably also a Monoid

Given how Image is described by Conal in
Denotational Design: From Meanings To Programs • Conal Elliott • YOW! 2015
https://www.youtube.com/watch?v=rlyqoYoUumc

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@awalterschulze you're right, but I couldn't find a separate Monoid class in Lean4 prelude.

The Append class is equivalent to Haskell Semigroup. And Inhabited + Append is equivalent to Haskell Monoid.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And thanks for the YouTube link - I had forgotten that Image was the example in Conal's talk. Perhaps we should use his encoding instead.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, I didn't know Lean was missing a Monoid class, TIL about Append + Inhabited = Monoid. I think this clears some things up about Inhabited for me, hmmm :O

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll have to rewatch the Conal talk again to remember anything tangible besides the monoid part. The rest was more a way a thinking about code, which has been really useful.
We don't have to fully go down this path though. I think what you have setup is already really cool.

Copy link
Collaborator

@awalterschulze awalterschulze Oct 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think he did something else where he didn't evaluate the transformations until he new the size of the picture he needed to draw, so that way he never loses any picture quality from scaling up and down

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

Successfully merging this pull request may close these issues.

2 participants