|
Marbellous
Marbellous, a WebApp to generate paper marbling patterns.
|
#include <emscripten.h>#include <cstdlib>#include <cstdio>#include <cmath>#include <random>#include "WGLContext.hpp"#include "WGLSceneRenderer.hpp"#include "WGLRakeRenderer.hpp"#include "Scene.hpp"#include "Options.hpp"
Classes | |
| struct | DropData |
| All relevant data for a single drop grouped as a struct. More... | |
Macros | |
| #define | checkSetup(RET) |
| Check wether the backend is initialized or not. More... | |
| #define | checkState(STATE, RET) |
Check wether the backend is currently in the state given by STATE. More... | |
Functions | |
| void | _initWGLContext (const char *canvasID, size_t x) |
| Used to initialize the WGL context. More... | |
| int EMSCRIPTEN_KEEPALIVE | addDrop (float, float, float, unsigned) |
| int EMSCRIPTEN_KEEPALIVE | finishDrop (int) |
| template<typename C , typename R > | |
| void | sprinkle (int amt, C &coord, R &radius) |
| Generate drops of random size and position. More... | |
| void EMSCRIPTEN_KEEPALIVE | initBackend (const char canvasID[], size_t dropRes, size_t rakeRes) |
| Init function. Should be called first. More... | |
| int EMSCRIPTEN_KEEPALIVE | addPalette (size_t num_colors) |
| Add a new palette. More... | |
| int EMSCRIPTEN_KEEPALIVE | setActivePalette (int const id) |
| Set an active palette. More... | |
| int EMSCRIPTEN_KEEPALIVE | setColorAt (size_t const colorNumber, unsigned int const color) |
Set the number at position colorNumber of the active palette. More... | |
| int EMSCRIPTEN_KEEPALIVE | setColorRatioAt (size_t const colorNumber, unsigned const ratio) |
| Set the the ratio of a color in the active palette. More... | |
| void EMSCRIPTEN_KEEPALIVE | setBGColor (unsigned int const color) |
| Set the background color. More... | |
| void EMSCRIPTEN_KEEPALIVE | setFilter (bool filter) |
| Set the filter option. More... | |
| int EMSCRIPTEN_KEEPALIVE | addDrop (float const x, float const y, float r, unsigned int const color) |
| Add a new color drop. More... | |
| void EMSCRIPTEN_KEEPALIVE | addDrops (int count, DropData drops[]) |
| Add multiple drops at once. More... | |
| void EMSCRIPTEN_KEEPALIVE | redraw () |
| Redraw the current data model based on the backend state. More... | |
| void EMSCRIPTEN_KEEPALIVE | resize (size_t dropSize, size_t rakeSize) |
| Resize the canvas. More... | |
| int EMSCRIPTEN_KEEPALIVE | resizeDrops (float const newRadius) |
| int EMSCRIPTEN_KEEPALIVE | finishDrops () |
| Finish all drops applying their displacement on all old drops. More... | |
| char *EMSCRIPTEN_KEEPALIVE | getImage () |
| Return the current canvas content as image. More... | |
| void EMSCRIPTEN_KEEPALIVE | sprinkleLocal (int amt, float r_min, float r_max, float x, float y, float sig) |
| Create drops around the cursor postion. More... | |
| void EMSCRIPTEN_KEEPALIVE | sprinkleGlobal (int amt, float r_min, float r_max) |
| Create drops at random positions on the canvas. More... | |
| void EMSCRIPTEN_KEEPALIVE | clearCanvas () |
| Clear canvas content and data model. More... | |
| void EMSCRIPTEN_KEEPALIVE | rake (float x, float y, float period, float amplitude, float phase, bool nails[1000]) |
| void EMSCRIPTEN_KEEPALIVE | startRaking () |
| Set rake state. More... | |
| void EMSCRIPTEN_KEEPALIVE | startDropping () |
| Set drop state. More... | |
| void EMSCRIPTEN_KEEPALIVE | undoLastRake () |
| Undo the last rake. More... | |
| int EMSCRIPTEN_KEEPALIVE | main () |
| < Currently does nothing. Initialization is the frontend's job. More... | |
Variables | |
| bool | setupDone = false |
| Stores wether backend is initialized or not. More... | |
| WGLSceneRenderer * | sceneRenderer |
| global WGLSceneRenderer More... | |
| Scene * | scene |
| global scene More... | |
| WGLRakeRenderer * | rakeRenderer |
| global WGLRakeRenderer More... | |
| #define checkSetup | ( | RET | ) |
Check wether the backend is initialized or not.
| RET | return value of the function in case that the backend is not initialized. |
| #define checkState | ( | STATE, | |
| RET | |||
| ) |
Check wether the backend is currently in the state given by STATE.
| STATE | State to compare with. True for drop state, false for rake state |
| RET | Return value of the function in case of unmatched state. |
| void _initWGLContext | ( | const char * | canvasID, |
| size_t | x | ||
| ) |
Used to initialize the WGL context.
< Friend function to use for initialization.
Friend function of WGLContext
| canvasID | CSS identifier of the HTML5 canvas to use. |
| x | Resolution of the canvas will be set to x times x. |

| int EMSCRIPTEN_KEEPALIVE addDrop | ( | float const | x, |
| float const | y, | ||
| float | r, | ||
| unsigned int const | color | ||
| ) |
Add a new color drop.
Intended workflow for animation is to add a drop, keep its ID and resize it step wise. After the animation is done and the drop will not further grow call finishDrops().
| x | x coordinate for the drop. |
| y | y coordinate for the drop. |
| r | Radius of the drop. |
| color | Color of th drop. This is a position inside a palette. Changing the active palette will result in a different color later on. |
| color | draw a circle at point (x,y) (should be normed to [-1,1]^2) with radius r in the given color |

| int EMSCRIPTEN_KEEPALIVE addDrop | ( | float | , |
| float | , | ||
| float | , | ||
| unsigned | |||
| ) |
| void EMSCRIPTEN_KEEPALIVE addDrops | ( | int | count, |
| DropData | drops[] | ||
| ) |
Add multiple drops at once.
| count | Number of drops. |
| drops | Drop data. |

| int EMSCRIPTEN_KEEPALIVE addPalette | ( | size_t | num_colors | ) |
Add a new palette.
| num_colors | Number of colors to pre allocate. |

| void EMSCRIPTEN_KEEPALIVE clearCanvas | ( | ) |
Clear canvas content and data model.
This can not be undone!

| int EMSCRIPTEN_KEEPALIVE finishDrop | ( | int | ) |
| int EMSCRIPTEN_KEEPALIVE finishDrops | ( | ) |
Finish all drops applying their displacement on all old drops.

| char* EMSCRIPTEN_KEEPALIVE getImage | ( | ) |
Return the current canvas content as image.

| void EMSCRIPTEN_KEEPALIVE initBackend | ( | const char | canvasID[], |
| size_t | dropRes, | ||
| size_t | rakeRes | ||
| ) |
Init function. Should be called first.
| canvasID | CSS identifier of HTML5 canvas in the frontend. |
| dropRes | Resolution of the canvas for drop mode. |
| rakeRes | Resolution of the canvas for rake mode. |
dropRes and rakeRes need to be the same. 
| int EMSCRIPTEN_KEEPALIVE main | ( | ) |
< Currently does nothing. Initialization is the frontend's job.
| void EMSCRIPTEN_KEEPALIVE rake | ( | float | x, |
| float | y, | ||
| float | period, | ||
| float | amplitude, | ||
| float | phase, | ||
| bool | nails[1000] | ||
| ) |
Rake paint on the canvas. Wraps around all edges.
| x | Stroke strength in x direction. |
| y | Stroke strength in y direction. |
| period | Period length of waves given as factor for canvas size. |
| amplitude | Amplitude of waves given as factor for canvas size. |
| phase | Phase shift of waves given as factor for canvas size. |
| nails | Boolean array which describes the rake. |

| void EMSCRIPTEN_KEEPALIVE redraw | ( | ) |
Redraw the current data model based on the backend state.
Useful for color updates for example.


| void EMSCRIPTEN_KEEPALIVE resize | ( | size_t | dropSize, |
| size_t | rakeSize | ||
| ) |
Resize the canvas.
| dropSize | New resolution for drop state. |
| rakeSize | New resolution for rake state. |

| int EMSCRIPTEN_KEEPALIVE resizeDrops | ( | float const | newRadius | ) |
| newRadius | resize all drops |

| int EMSCRIPTEN_KEEPALIVE setActivePalette | ( | int const | id | ) |
Set an active palette.
| id | ID of the palette to set active. Return value of addPalette() |

| void EMSCRIPTEN_KEEPALIVE setBGColor | ( | unsigned int const | color | ) |
Set the background color.
| color | Color in HEX Code |

| int EMSCRIPTEN_KEEPALIVE setColorAt | ( | size_t const | colorNumber, |
| unsigned int const | color | ||
| ) |
Set the number at position colorNumber of the active palette.
| colorNumber | Number of color to set. |
| color | Color als HEX code. |

| int EMSCRIPTEN_KEEPALIVE setColorRatioAt | ( | size_t const | colorNumber, |
| unsigned const | ratio | ||
| ) |
Set the the ratio of a color in the active palette.
| colorNumber | Number of the color to modify. |
| ratio | New ratio for sprinkler drops. |

| void EMSCRIPTEN_KEEPALIVE setFilter | ( | bool | filter | ) |
Set the filter option.
| filter | True for post processing filter, false otherwise. |

| void sprinkle | ( | int | amt, |
| C & | coord, | ||
| R & | radius | ||
| ) |
Generate drops of random size and position.
| C | A function type for transforming random numbers to drop coordinates. |
| R | A function type for transforming random numbers to drop sizes. |
| amt | Number of drops to generate |
| coord | A function of type C. |
| radius | A function of type R. |


| void EMSCRIPTEN_KEEPALIVE sprinkleGlobal | ( | int | amt, |
| float | r_min, | ||
| float | r_max | ||
| ) |
Create drops at random positions on the canvas.
| amt | Number of drops to create. |
| r_min | Minimum size. |
| r_max | Maximum size. |

| void EMSCRIPTEN_KEEPALIVE sprinkleLocal | ( | int | amt, |
| float | r_min, | ||
| float | r_max, | ||
| float | x, | ||
| float | y, | ||
| float | sig | ||
| ) |
Create drops around the cursor postion.
\param amt Number of drops to create. \param r_min,r_max drop size range \param x,y cursor position \param sig Sigma of normal distribution for drop position

| void EMSCRIPTEN_KEEPALIVE startDropping | ( | ) |
Set drop state.
All rakes will be lost.

| void EMSCRIPTEN_KEEPALIVE startRaking | ( | ) |
Set rake state.
This results in the scene being rendered to a hidden buffer which is given to the WGLRakeRenderer

| void EMSCRIPTEN_KEEPALIVE undoLastRake | ( | ) |
Undo the last rake.
Reverting only the last step is very cheap by swapping buffer pointers. Calling it again will swap back (e.g. undo the undo).

| WGLRakeRenderer* rakeRenderer |
global WGLRakeRenderer
| Scene* scene |
global scene
| WGLSceneRenderer* sceneRenderer |
global WGLSceneRenderer
| bool setupDone = false |
Stores wether backend is initialized or not.