-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
Immediate Mode in Doodle Canvas #168
Open
VOSID8
wants to merge
44
commits into
creativescala:main
Choose a base branch
from
VOSID8:canvasRaster
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
noelwelsh
reviewed
Jun 25, 2024
canvas/src/main/scala/doodle/canvas/algebra/CanvasDrawing.scala
Outdated
Show resolved
Hide resolved
noelwelsh
reviewed
Jun 26, 2024
examples/js/src/main/scala/doodle/examples/canvas/ConcentricCircles.scala
Outdated
Show resolved
Hide resolved
noelwelsh
reviewed
Jun 27, 2024
examples/js/src/main/scala/doodle/examples/canvas/Experiment.scala
Outdated
Show resolved
Hide resolved
This makes it work with Scala 3.3. again
Previous implementation didn't do anything. This implementation correctly adds an extension method.
No reason it should only be available for JS
Change made by scalafix
Fix outstanding issues on Raster implementation
noelwelsh
reviewed
Jul 12, 2024
noelwelsh
reviewed
Jul 12, 2024
VOSID8
changed the title
Working on Canvas backend, implementing raster
Immediate Mode in Canvas Doodle
Aug 18, 2024
VOSID8
changed the title
Immediate Mode in Canvas Doodle
Immediate Mode in Doodle Canvas
Aug 20, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Theory
Retained Mode: The Doodle library supports retained mode, operating on a declarative principle. In this mode, the application constructs images using graphics primitives like shapes and lines, which are then stored as a model in memory. Users interact with this model to add, remove, or modify elements, while the library handles the redrawing. Retained mode maintains a hierarchy where each element’s position is relative to others. In Doodle, relationships between elements are managed through the Shape algebra, allowing operations like
on
,beside
, and similar commands to organize elements.The Need for Immediate Mode: While retained mode provides a robust solution for constructing and managing complex images, some tasks require more flexibility and direct control. Retained mode can be restrictive for dynamic image manipulation, generative art, and real-time graphics, where the scene model may become cumbersome or resource-intensive. To address these needs, immediate mode has been introduced in Doodle Canvas, enabling developers to bypass the stored scene model and directly issue drawing commands.
Immediate Mode: Doodle now includes an immediate mode, offering a procedural approach to graphics rendering. In immediate mode, the application directly issues image manipulation commands for each frame or operation, without retaining a model in memory. This approach is particularly effective for tasks requiring real-time rendering, interactive graphics, or dynamic transformations. The
Immediate
object serves as the core interface for this mode, providing methods for drawing and manipulating images directly, giving developers more control and flexibility in image processing.Integrating Immediate Mode with Retained Mode: With the introduction of immediate mode, Doodle now combines the strengths of both paradigms. A new algebra
Raster
allows users to embed immediate mode drawing within the retained mode structure. This feature lets users create aPicture
that can be positioned relative to otherPictures
using operations likeabove
oron
. The contents of this Picture are generated either through Retained mode or dynamically through a user-defined function that has access to aImmediate
. Drawing operations within this function are relative to the origin of thePicture
, offering procedural flexibility. The resultingPicture
can then be integrated into the retained mode hierarchy, enabling seamless interaction between both modes. This hybrid approach allows for the dynamic rendering and fine control of immediate mode while maintaining the organizational clarity of retained mode.Implementation
Existing Retained Mode
We can rewrite the above with Immediate Mode as
Both will return the same output as
Raster Algebra Implemented
User can use Raster as following to combine Immediate with Retained Mode
Which would give output as
Immediate
object implements 39 methods covering a wide range of drawing functionalities. These include creating shapes (like circles, rectangles, polygons), path operations (like arc, line, and curves), transformations, clipping, coloring and text rendering.Example
The following image is create using Immediate mode along with Retained Mode. Retained Mode is used to draw trees and put everything together in a compositional manner whereas buildings and the road is drawn using Doodle Canvas Immediate Mode. The code for this picture can be found within
CanvasImmediateMode.scala
file within this PRNote: This PR is part of Google Summer of Code'24 (Doodle Canvas)