Skip to content
This repository has been archived by the owner on May 6, 2024. It is now read-only.

HE7086/Fourier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Fun Fourier Drawing Programm

Note

This is oringinally a program for the Functional Programming Competition and is under refactor
see details about the competition here: Link
see original source here: Link

Inspiration

  • 3Blue1Brwon's amazing video told us that Fourier Series can draw anything
  • In the form of Integral, the series will approach the oringinal image as the number of terms rise

  • The Mathematical Pinciple behind the image is so amazing that I decide to present this simple fun programm that draws anything

Data Format

  • prepare your data in the following json format, where each object of series represents a term of fourier series
{
    "series": [
        {
            "number" : 0,
            "real" : 1,
            "imag" : 2 
        }
    ]
}
  • number represents exactly n in the form, which should be a Integer, and controls how fast the vector spins
  • real and imag represent the complex constant Cn in the form, control the starting position and length of the vector
  • Then put them in one directory without other files. Each file will be transformed to a closed curve. In order to draw a image with multiple curves, you'll need the same amount of json files.

Example

haskell

  • this image of haskell logo is generated using data from the data directory

Usage

Build the Binary
  • clone the repository and run cabal-build
  • make sure to run cabal update once if it is newly installed
git clone https://github.com/HE7086/Fourier.git
cd Fourier
cabal build
  • you can find the binary inside dist folder
CLI Flags
short long description
-g --gif generate gif files
-p --png generate png files
-c --combined combine the images afterwards
-o PATH --output PATH specify output path
-i PATH --input PATH specify input path/file
-v --version print version message
-h --help print help message
  • by default help messages will be printed
Example
  • generate gifs from all the files in a directory
cabal run -- Fourier --gif --input ./data --output ./out --combined
  • generate one png from a file
cabal run -- Fourier --png --input ./data/1.json --output ./out
  • run with threaded mode (significantly increase performance on multicore cpus)
cabal run -- Fourier --png --input ./data/1.json --output ./out +RTS -N

Customization

  • In the file src/Settings.hs are several option that can be customized easily
    • width, height : the height and width of the generated image
    • white, black : the standard pixel color
    • pixelArt : the function that dertermines color and by default draws black
    • pointCount : the number of points to be painted
    • gifStep : how many pixels will be rendered each frame
      • warning : terrible runtime if set too small
    • filename : the name of outputed image
    • scaleFactor : how much the final image will be scaled
  • These customization options will be merged into cli flags in the future

TODO list

  • optimize performance
  • adjustable line thickness
  • adjustable fore-/background color
  • coordinates converter: convert coordinates to forms

About

Simple Fun Fourier Drawing Program

Resources

License

Stars

Watchers

Forks

Packages

No packages published