Welcome to a cutting-edge Haskell project that explores the potential of functional programming in the realm of image processing. This project evolves through three distinct stages, each adding new complexity and capability to create a versatile system for defining and manipulating 2D image regions using functional programming techniques.
"In the world of functional programming, every image is a function waiting to be transformed and rendered."
The journey begins with a foundational approach to represent 2D regions and transformations in a purely functional way. This stage introduces the concept of regions as functions, starting with simple geometric shapes and basic transformation operations:
type Point = (Float, Float)
type Pointed a = Point -> a
type Region = Pointed Bool
type Transformation = Point -> Point
-
Basic Functional Region Representation
- Regions are defined as functions that take a point and return a boolean value indicating if it belongs to the region.
- Simple geometric shapes like circles and rectangles are defined.
-
Primitive Transformations
- Translation: Moving regions in the 2D plane.
- Scaling: Changing the size of regions.
- Composition: Combining multiple transformations into a single operation.
In this stage, the project evolves to include more advanced abstractions, specifically using an Abstract Syntax Tree (AST) to represent regions and transformations. This allows for complex compositions and efficient transformation management.
data RegionAST
= FromPoints [Point]
| Rectangle Float Float
| Circle Float
| Complement RegionAST
| Union RegionAST RegionAST
| Intersection RegionAST RegionAST
| Transform TransformationAST RegionAST
deriving (Show, Eq)
-
AST-Based Region Representation
- Regions are now represented by more complex data structures (AST), enabling more flexible region definitions and manipulations.
- Supports operations like complementing a region, combining regions (union), and applying transformations.
-
Complex Transformations
- Transformations are now abstracted as part of the AST, allowing for better composition and optimization.
- Operations such as scaling, rotation, and translation are more easily composed into a unified transformation structure.
The final stage introduces generic folding mechanisms and type classes, enabling more powerful and reusable operations on regions and transformations. This stage focuses on generalizing region and transformation handling to allow more complex and type-safe operations.
newtype RegionAST
= R (RegionShape RegionAST)
deriving (Eq)
newtype TransformationAST
= T (TransformationShape TransformationAST)
deriving (Eq)
-
Generic Folding
- Introduces higher-order functions and custom type classes to manipulate regions and transformations generically.
- Pattern matching is enhanced, and region transformations are composable through fold operations.
-
Enhanced Type Safety
- Strong type-checking ensures safety across complex transformations and region operations.
- Functor instances and custom type class implementations allow for flexible, reusable abstractions.
- Generate and manipulate 2D geometric shapes.
- Apply transformations to create complex images and animations.
- Produce procedural art using functional abstractions.
- Dynamic boundary and collision detection systems.
- Procedural generation of environments and levels.
- Real-time image transformations and rendering.
- Data region mapping for scientific data visualisation.
- Transform coordinate systems for different data sets.
- Visualise patterns and structures in large data sets.
- Demonstrate geometric concepts interactively.
- Provide visualisations for transformation operations.
- Create tools for learning functional programming and image processing.
- GHC (Glasgow Haskell Compiler) >= 9.2.0
- Basic understanding of functional programming
- Familiarity with geometric concepts
Important
GHC can be installed using the following package managers:
- Ubuntu/Debian:
apt-get install ghc
- Red Hat/Fedora:
dnf install ghc
- macOS:
brew install ghc
- Windows:
choco install ghc
For detailed installation instructions, refer to the GHC installation guide.
git clone [email protected]:florian-ariasu/functional-images-dsl.git
git clone https://github.com/florian-ariasu/functional-images-dsl.git
cd functional-images-dsl
cd src
cd 1st-stage
ghci
:l TestShallow.hs
main
Contributions are welcome! Here's how you can help:
- Feature implementation
- Documentation improvements
- Test case additions
- Bug reports and fixes
This project is licensed under the MIT Licence. See the LICENCE file for further details.