Coder Social home page Coder Social logo

chaosbox's People

Contributors

5outh avatar akrmn avatar yvee1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

chaosbox's Issues

Example program in README outdated?

Hello,

I noticed that the example program located in example/Main.hs works perfectly, but the one in the README gives type errors. I think the problem lies in the difference between c <- readIORefWith (maybe p (lerp 0.05 p)) mousePositionRef (working) and c <- forIORef mousePositionRef $ maybe p (lerp 0.05 p) (from readme, not working).

(PS. I used your chaosbox library before and it worked well, but there were always some things missing, especially a window where you can have user input and see an animation, which made me use JavaScript or Processing or something instead. Seeing this update and noticing you've implemented exactly that makes me excited to try doing some genart in Haskell again!)

Thanks for your work and making this open-source!

Shorthand option -h is used both for help and height

Hello,

I noticed running stack exec sketch-exe -- -h gives The option '-h' expects an argument.
This is because -h is shorthand for --height, but at the same time also for --help. This is possible perhaps, by using -h without argument for --help and with an argument for --height. In any case, the implementation does not allow that currently.

Rendering output to SVG

Hello again!

I have been playing around a little with SVGs, and I was wondering if functionality could be added for rendering an image from chaosbox to SVG. If I have a sketch mySketch :: Render () then I can render this to an SVG like this:

main :: IO ()
main = 
  withSVGSurface "out.svg" 500 500 $ \surface -> do
    renderWith surface mySketch
    surfaceFinish surface

(this took me some time to figure out since it's a bit different from rendering to PNG)

Anyways, rendering a sketch of type Generate () is not possible this way. As far as I can tell, the only way to do this would be to adapt the runChaosBoxDirectly function to use an SVG surface instead of a PNG one, and then also write a corresponding saveImageWith function for SVGs (since surfaceFinish needs to be used instead of surfaceWriteToPNG).

This is not ideal and would take some time to figure out, therefore I think it would be nice to add functionality for rendering different image types to the library. Alternatively, a way to easier extend the library to add something like this would also be a solution, but I wouldn't know how that could be done.

Something like the haskell-chart library has would be a good solution I think. So adding an option FileFormat to Opts with the default being PNG, and then doing a case distinction when rendering to an image.

What do you think? I wouldn't mind helping implement this via a pull request.

PS. Rendering an existing SVG onto a cairo surface for use in a sketch was also something I was interested in and have been toying with briefly. I had significant trouble getting it to work since something like svgcairo uses cairo instead of gi-cairo, and adapting this to work with gi-cairo didn't succeed because I got compile errors saying there were errors in the C header files in glib. When I was about to give up I found hs-librsvg which had many fewer dependencies and got that to work pretty easily with gi-cario. Just FYI in case you want to add functionality for rendering images to chaosbox.

Somewhat confusing naming in ChaosBox.Random

I noticed the function normal generates a normal random variable. Then, wanting a uniform random variable I looked at the uniform function. However, this is not what I expected it to be. Contrary to the normal function it samples from a collection instead of being a uniformly distributed random variable. Furthermore the function I was searching for seems to be missing in the module as far as I can see. Some possible ways to fix this issue that I could think of are listed below:

rename uniform to sample, and let uniform a b = sampleRVar (Random.uniform a b):
+ sample fits well with sampleN
+ uniform is now a random variable like normal, gamma, bernoulli
- sample is an existing function in Data.Random
- would make changing weighted to weightedSample more logical

uniformR a b = sampleRVar (Random.uniform a b) or getUniformR:
+ Fits with getRandomR from Control.Monad.Random.Class
- looks like it's a different kind of function than normal, gamma etc.

random a b = sampleRVar (Random.uniform a b):
+ does not require any name changes of existing functions
- very ambiguous

Obviously, it's entirely up to you to decide how you want to make your API.

HSV hue range inconsistency

Hi,

I noticed that the functions setSourceHSV and setSourceHSVA use different ranges for the hue argument. setSourceHSV expects hue to be between 0 and 1, while setSourceHSVA interprets hue as a value between 0 and 360.

Following the convention of the Data.Colour package, so letting hue be between 0 and 360, would make most sense I think and is also most intuitive.

Example doesn't run on ubuntu

I've got a fresh checkout of chaosbox which I've run stack build on.

I get the following:

$ stack exec chaosbox-example
chaosbox-example: SDLCallFailed {sdlExceptionCaller = "SDL.Video.updateWindowSurface", sdlFunction = "SDL_UpdateWindowSurface", sdlExceptionError = "Window surface is invalid, please call SDL_GetWindowSurface() to get a new surface"}

ldd output:

ldd .stack-work/install/x86_64-linux-tinfo6/554fc345da7e2388412f8a6ac62c9ab68f20c5699196add852e84b1354d0b302/8.6.5/bin/chaosbox-example
	linux-vdso.so.1 (0x00007ffd31759000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f97acf7e000)
	libSDL2-2.0.so.0 => /lib/x86_64-linux-gnu/libSDL2-2.0.so.0 (0x00007f97ace29000)
	libcairo-gobject.so.2 => /lib/x86_64-linux-gnu/libcairo-gobject.so.2 (0x00007f97ace1d000)
	libgobject-2.0.so.0 => /lib/x86_64-linux-gnu/libgobject-2.0.so.0 (0x00007f97acdbd000)
	libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f97acc94000)
	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f97acc78000)
	libcairo.so.2 => /lib/x86_64-linux-gnu/libcairo.so.2 (0x00007f97acb53000)
	librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f97acb48000)
	libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007f97acb43000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f97acb3d000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f97acb1a000)
	libgmp.so.10 => /lib/x86_64-linux-gnu/libgmp.so.10 (0x00007f97aca96000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f97ac8a2000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f97ad0ed000)
	libasound.so.2 => /lib/x86_64-linux-gnu/libasound.so.2 (0x00007f97ac7a7000)
	libpulse.so.0 => /lib/x86_64-linux-gnu/libpulse.so.0 (0x00007f97ac752000)
	libX11.so.6 => /lib/x86_64-linux-gnu/libX11.so.6 (0x00007f97ac615000)
	libXext.so.6 => /lib/x86_64-linux-gnu/libXext.so.6 (0x00007f97ac600000)
	libXcursor.so.1 => /lib/x86_64-linux-gnu/libXcursor.so.1 (0x00007f97ac5f3000)
	libXinerama.so.1 => /lib/x86_64-linux-gnu/libXinerama.so.1 (0x00007f97ac5ec000)
	libXi.so.6 => /lib/x86_64-linux-gnu/libXi.so.6 (0x00007f97ac5da000)
	libXrandr.so.2 => /lib/x86_64-linux-gnu/libXrandr.so.2 (0x00007f97ac5cd000)
	libXss.so.1 => /lib/x86_64-linux-gnu/libXss.so.1 (0x00007f97ac5c8000)
	libXxf86vm.so.1 => /lib/x86_64-linux-gnu/libXxf86vm.so.1 (0x00007f97ac5c1000)
	libwayland-egl.so.1 => /lib/x86_64-linux-gnu/libwayland-egl.so.1 (0x00007f97ac5bc000)
	libwayland-client.so.0 => /lib/x86_64-linux-gnu/libwayland-client.so.0 (0x00007f97ac5a9000)
	libwayland-cursor.so.0 => /lib/x86_64-linux-gnu/libwayland-cursor.so.0 (0x00007f97ac59e000)
	libxkbcommon.so.0 => /lib/x86_64-linux-gnu/libxkbcommon.so.0 (0x00007f97ac55c000)
	libffi.so.7 => /lib/x86_64-linux-gnu/libffi.so.7 (0x00007f97ac550000)
	libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f97ac4dd000)
	libpixman-1.so.0 => /lib/x86_64-linux-gnu/libpixman-1.so.0 (0x00007f97ac434000)
	libfontconfig.so.1 => /lib/x86_64-linux-gnu/libfontconfig.so.1 (0x00007f97ac3ed000)
	libfreetype.so.6 => /lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007f97ac32e000)
	libpng16.so.16 => /lib/x86_64-linux-gnu/libpng16.so.16 (0x00007f97ac2f6000)
	libxcb-shm.so.0 => /lib/x86_64-linux-gnu/libxcb-shm.so.0 (0x00007f97ac2f1000)
	libxcb.so.1 => /lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f97ac2c7000)
	libxcb-render.so.0 => /lib/x86_64-linux-gnu/libxcb-render.so.0 (0x00007f97ac2b6000)
	libXrender.so.1 => /lib/x86_64-linux-gnu/libXrender.so.1 (0x00007f97ac0ac000)
	libpulsecommon-13.99.so => /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-13.99.so (0x00007f97ac02a000)
	libdbus-1.so.3 => /lib/x86_64-linux-gnu/libdbus-1.so.3 (0x00007f97abfd9000)
	libXfixes.so.3 => /lib/x86_64-linux-gnu/libXfixes.so.3 (0x00007f97abfd1000)
	libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f97abfa1000)
	libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007f97abf98000)
	libXau.so.6 => /lib/x86_64-linux-gnu/libXau.so.6 (0x00007f97abf92000)
	libXdmcp.so.6 => /lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f97abf8a000)
	libsystemd.so.0 => /lib/x86_64-linux-gnu/libsystemd.so.0 (0x00007f97abedb000)
	libwrap.so.0 => /lib/x86_64-linux-gnu/libwrap.so.0 (0x00007f97abecd000)
	libsndfile.so.1 => /lib/x86_64-linux-gnu/libsndfile.so.1 (0x00007f97abe4f000)
	libasyncns.so.0 => /lib/x86_64-linux-gnu/libasyncns.so.0 (0x00007f97abc49000)
	libapparmor.so.1 => /lib/x86_64-linux-gnu/libapparmor.so.1 (0x00007f97abc34000)
	libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007f97abc1a000)
	liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007f97abbef000)
	liblz4.so.1 => /lib/x86_64-linux-gnu/liblz4.so.1 (0x00007f97abbce000)
	libgcrypt.so.20 => /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007f97abab0000)
	libnsl.so.1 => /lib/x86_64-linux-gnu/libnsl.so.1 (0x00007f97aba93000)
	libFLAC.so.8 => /lib/x86_64-linux-gnu/libFLAC.so.8 (0x00007f97aba55000)
	libogg.so.0 => /lib/x86_64-linux-gnu/libogg.so.0 (0x00007f97aba48000)
	libvorbis.so.0 => /lib/x86_64-linux-gnu/libvorbis.so.0 (0x00007f97aba18000)
	libvorbisenc.so.2 => /lib/x86_64-linux-gnu/libvorbisenc.so.2 (0x00007f97ab96d000)
	libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007f97ab951000)
	libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007f97ab92e000)
uname -a
... 5.11.0-27-generic #29~20.04.1-Ubuntu SMP Wed Aug 11 15:58:17 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.