0
votes

Having discovered Processing, and in the middle of trying to learn ruby, I naturally installed ruby-processing for Processing 2.2 (not 3 which requires JRubyArt as the alternative to ruby-processing as I understand).

I am hoping to kill two birds with one stone and create Processing sketches whilst learning more ruby.

However it would be really useful to translate example Processing sketches into ruby so I can then play with them. At the moment I am doing it manually. Does anyone know of a script to do this?

1

1 Answers

1
votes

Short answer: no.

This kind of translation is not trivial. Generally, you can't really translate the syntax of one language into the syntax of a different language. You don't go line-by-line and simply change the code one line at a time. That makes what you're asking pretty difficult, so you probably won't find many tools that do stuff like that.

Instead, to translate a program from one language to another, you have to think about the semantics, not the syntax. You have to ask yourself "what does this program do?" and then you simply write a program that does the same thing in the target language. It's not a one-to-one syntax mapping.

In fact, if you're trying to learn, that's a pretty great exercise. The examples that come with Processing are pretty small, so it should be relatively straightforward. Here is what I would do if I were you:

  • Take an existing example Processing sketch.
  • Write down in English (not pseudocode) what the program does. Be as specific as possible. Break things down into a list of small steps, and break those steps down into even smaller sub-steps whenever possible. You should be able to hand your list to somebody who has never seen the sketch, and they should be able to tell you in their own words exactly what the sketch does.
  • Take that list and treat that as your programming assignment, and implement it in your target language. If you get stuck on one of the specific steps, post an MCVE and we'll go from there.

So, translating code involves a middle step of translating it into English first, which is why tools like what you're asking for are much more difficult than you might first think.