3 ms·
I am a programming newbie. We just started learning CS topics through Python. Everything was fine up until we hit "Objects and Graphics". That has to be the mos
by VectorSpace 12y ago
I am a programming newbie. We just started learning CS topics through Python. Everything was fine up until we hit "Objects and Graphics". That has to be the most inefficient and inelegant way of doing anything at all. At this point I am not even sure if I ever want to touch graphics in Python. What are some languages where dealing with graphics and objects is closer to working with purely mathematical objects rather than doing insanely tedious engineering style plug-n-chug work? Sorry, if it offends some. Didn't mean that. Thanks.
- sklogic 12y agoWolfram Mathematica has a really nice model, and it's not that expensive for students.
- ryanlntn 12y agoCheck out Elm: http://elm-lang.org/ http://elm-lang.org/
- _almosnow 12y agoCould you give an example of working with graphics as purely mathematical objects?
- sklogic 12y agoFunctional reactive animation is one such example. A constructive solid geometry used in many CADs is also pretty pure.
- VectorSpace 12y agoThat is the part of the point I was making. I have no idea what that would look like. Maybe something like simple proofs from Number Theory or Abstract Algebra? I read up a little on Lisp family of languages on Wiki and they look vaguely close to being 100% purely mathematical, syntax-wise. I wonder what it's like doing graphics/objects(?) work in Lisp.
- praccu 12y agoIt's interesting that graphics and objects are so connected, in your posts. I'll say that in general, EVERYTHING in Python is objects, and they're an extremely general programming paradigm. It sounds like Haskell might be a language you'd like, if you're into abstract algebra (although I don't think Haskell's graphics support is super great).
- rjayatilleka 12y agoBluntly put, Haskell's graphics support sucks. There are different libraries with different levels of support, but none are complete or high level. There are also Haskell like alternatives like Elm and PureScript, but they're experimental. And finally there are some Haskell to JavaScript compilers, but I'm not sure what DOM manipulation is like with them (and they're all experimental). I'm building a Haskell desktop app over winter break (DMX and light show controls), but after a fair bit of research, I came to the conclusion that its best to do the GUI in JavaScript and speak with a Haskell server over a WebSocket.
- codygman 12y agoFor 2D, I don't see how Gloss[0] isn't complete or high level (what are you comparing it to?). There's a cool example of drawing a clock[1] as well as others[2]. The package is on hackage[3] and has a website[4], but the github seemed more approachable/clear to me. There's also an awesome tutorial on making tic tac toe[5] by ocharles of the 24 days of hackage fame. 0: https://github.com/benl23x5/gloss https://github.com/benl23x5/gloss 1: https://github.com/benl23x5/gloss/blob/master/gloss-examples/picture/Clock/Main.hs https://github.com/benl23x5/gloss/blob/master/gloss-examples... 2: https://github.com/benl23x5/gloss/blob/master/gloss-examples https://github.com/benl23x5/gloss/blob/master/gloss-examples 3: http://hackage.haskell.org/package/gloss http://hackage.haskell.org/package/gloss 4: http://gloss.ouroborus.net/ http://gloss.ouroborus.net/ 5: https://ocharles.org.uk/blog/posts/2013-12-10-24-days-of-hackage-gloss.html https://ocharles.org.uk/blog/posts/2013-12-10-24-days-of-hac...
- deleted 12y ago[deleted]
- swah 12y agoThat's odd - normally Python libraries tend to be simple to interact. I wanted to stitch a few photos on friday and used Python w/ the Pillow library, and was once again impressed for easy and pleasurable the experience was (using mostly C and Go nowadays).
- jboy 12y agoWhat sort of "graphics" are you looking for? I generally use Numpy NDarrays and Scipy's NDimage functions for graphics & image processing in Python. Aside from the NDarray data-structure itself, there's almost no O-O; everything in Numpy is either a method of this one workhorse data-type, or module-level functions that operate upon this data-type. NDarrays are great because they can represent all of: - images (using 2-D arrays for binary or greyscale images, and 3-D arrays for colour images); - the vectors & matrices used in 3-D computer graphics; - the masks used in spatial image filtering; - the "structuring elements" used in morphological image processing. Once you get used to the syntax, NDarray indexing & slicing are very efficient in both keystrokes & CPU cycles to get/set the values of pixels or arbitrary rectangular regions. NDarray methods & the related Numpy functions offer element-wise operations (like pixel-wise Boolean logical ops, or "square every element in the matrix" / "square-root every element in the matrix" as part of the Euclidean distance calculation) and operations that can run over any dimension of the image (including the colour dimension, which is useful for calculations like the N-dimensional sum in dot-products or Euclidean distance). And the for-loops are in C, so they're blindingly fast. NDimage functions provide filters and morphological processing capabilities. Plus, Numpy integrates nicely with Matplotlib so you can display images and plot histograms.
- panic 12y agoProcessing (https://processing.org https://processing.org) is an excellent language and development environment for playing with graphics.
- ihm 12y agoYou should definitely check out Brent Yorgey's diagrams package (see examples here http://projects.haskell.org/diagrams/gallery.html http://projects.haskell.org/diagrams/gallery.html) which is a declarative drawing library. Graphics are described in an essentially "mathematical" way, and as you can see, many of the examples come from mathematics.
- waps 12y agoHere's a hint. Write a Windows 3.1 program in C (don't worry, it runs fine in windows 8). In those programs the event loop is extremely visible, and you'll understand how everything works even in modern languages. Effectively, even things like Android and IOS still use the same basic principle, and if you dig deep enough this is exactly the structure you'll see. Plus cooperatively multitasked servers wipe the floor with almost any other kind. It's good to know how they are structured at a very low level and be able to write code to cooperate with them.
- peterfirefly 12y agoThe actual drawing API can also vary a lot. Cairo is quite nice and very different from Win3.1. It is more like GDI+ but nicer (and probably slower). The GUI/event handling can also be done in different ways: functional reactive programming is very different from Win3.1/X/Old-Skool Macs.