Processing on Rosetta Code -- weekly topics?

I recently noticed that Rosetta Code – the tasks-in-many-languages coding site – has a language for Processing, but only ~26 Processing tasks examples submitted, out of 916 tasks.

It might be nice to occasionally post a Rosetta task to the forum and see if any community members wants to take a crack at putting together (or giving feedback on and improving) a concise demo sketch.

What do people think of a series of (say, weekly or monthly) posts of Rosetta code challenges?

For example, there is no Processing entry for the Fibonacci sequence. And there are ~800 others.

On the one hand, most tasks already have a Java entry, so for basic programming (outside problems like the Mandelbrot set, or Animation tasks) it isn’t always clear what the added value is of having a Processing entry would be for some tasks – especially ones where the Java already runs with a tweak or two. However, many of the Rosetta languages are quite close to each other, and I still think an expanded set of Rosetta Processing sketches might be a great resource, especially if the sketches were complete (not functions, but cut-paste runnable) – as this would both benefit Processing users and potentially benefit other coders who could easily explore concepts with Processing PDE. Plus, Processing creates the opportunity for adding a visual component to many task outputs, which most other languages lack.

EDIT: For the resulting PDE example set, see this Gallery page:

6 Likes

Revisiting this a year later, there are now ~40 Processing examples on Rosetta Code. The list of Rosetta topics not implemented in Processing is:

https://rosettacode.org/wiki/Reports:Tasks_not_implemented_in_Processing

Of the tasks that are already implemented, some are basic ports of the existing Java example – like “Repeat a String.” However, some have significant differences – for example, in the “Rename a File” task, sketch-local files in Processing are accessed through sketchPath() or dataPath().

https://rosettacode.org/wiki/Rename_a_file#Processing

Another interesting difference is “Color of a Screen Pixel” – the Java example uses the Robot library, but in Processing this is usually scoped to the sketch window, and requires understanding what the “color” data type is.

https://rosettacode.org/wiki/Color_of_a_screen_pixel#Processing

Even many of the simple examples require non-trivial adaptation compared to Java. For example, the “Arithmetic/Integer” task to + - * / begins with “get two integers from the user” – which the Java example does with a command line interface, but Processing would probably provide keyboard interaction for.

Some of the un-done examples are right up Processing’s alley – for example, animation

…Conway’s game of life and the Sierpinski triangle:

and games of varying complexity:

3 Likes

Interesting, never heard of this website before. Seeing Processing is Java based, can’t we copy-paste their answers and slightly edit it? :joy:

1 Like

Sure, in some cases, absolutely – although it is sometimes more interesting than that. Also, the goal is not for it to barely work, but for it to be helpful and idiomatic in Processing.

So, for example, check out anagrams – Java and Processing

// Java 1.5+
import java.net.*;
import java.io.*;
import java.util.*;
 
public class WordsOfEqChars {
    public static void main(String[] args) throws IOException {
        URL url = new URL("http://www.puzzlers.org/pub/wordlists/unixdict.txt");
        InputStreamReader isr = new InputStreamReader(url.openStream());
        BufferedReader reader = new BufferedReader(isr);
 
        Map<String, Collection<String>> anagrams = new HashMap<String, Collection<String>>();
        String word;
        int count = 0;
        while ((word = reader.readLine()) != null) {
            char[] chars = word.toCharArray();
            Arrays.sort(chars);
            String key = new String(chars);
            if (!anagrams.containsKey(key))
                anagrams.put(key, new ArrayList<String>());
            anagrams.get(key).add(word);
            count = Math.max(count, anagrams.get(key).size());
        }
 
        reader.close();
 
        for (Collection<String> ana : anagrams.values())
            if (ana.size() >= count)
                System.out.println(ana);
    }   
}
// Processing
import java.util.Map;
 
void setup() {
  String[] words = loadStrings("http://wiki.puzzlers.org/pub/wordlists/unixdict.txt");
  topAnagrams(words);
}
 
void topAnagrams (String[] words){
  HashMap<String, StringList> anagrams = new HashMap<String, StringList>();
  int maxcount = 0;
  for (String word : words) {
    char[] chars = word.toCharArray();
    chars = sort(chars);
    String key = new String(chars);
    if (!anagrams.containsKey(key)) {
      anagrams.put(key, new StringList());
    }
    anagrams.get(key).append(word);
    maxcount = max(maxcount, anagrams.get(key).size());
  }
  for (StringList ana : anagrams.values()) {
    if (ana.size() >= maxcount) {
      println(ana);
    }
  }
}

Same algorithm – the Processing answer is based on the Java answer. But lots of differences:

Processing Java
import java.util.Map; import java.net.*; import java.io.*; import java.util.*;
loadStrings() BufferedReader(InputStreamReader(URL.openStream()))
StringList Collection<String> and ArrayList<String>
void setup() public class foo { public static void main() }
max() Math.max()
println() System.out.println()

You could copy-paste the Java example and tweak a few things and the BufferedReader and Map<String, Collection<>> would work – but even though it worked, it wouldn’t show you a Processing way to solve the problem with Processing built-ins and data structures.

Or compare Bulls & Cows games:

Java uses Scanner(System.in) with a do...while loop to catch keyboard input and process it every 4 characters. That whole setup doesn’t make any sense in Processing – key events are processed with the key handlers, and Processing is already running a loop – draw. You don’t want an user input “while” inside draw! A Processing solution could just print to the console, but for status text (like numeric input, or scores) it makes more sense to display game feedback on the sketch surface…

3 Likes

Good to know, and thanks for thoroughly explaining it. For now these coding challenges feel a bit above my level, but in the future I might be interested to tag along to bulk up my coding muscles

I think there are many tasks that are not that challenging. When I started with Processing (one and a half year ago I believe), I translated my VB6 Mandelbrot code to Processing and I posted it on the rosettacode wiki page.
Unfortunately the possibility to post images, was already blocked, so I had to give a link to my Drive.
The site is based on the honesty/dignity of programmers because anyone can edit them. But the author will be notified. Today just to encourage you, I made another upload about bitmap. See here
Just a short code following only the strict task written on the top of the page. So feel free to edit it to make it Processing worthy. I hope more P5 users will contribute.

5 Likes

Thanks so much for sharing this, @noel.

I’m looking into making all Processing contributions to Rosetta Code available through the Contributions Manager (redistributed under the Rosetta Code FDL license).

An example set (with screenshots bundled with the examples) might also be a good way to work with Processing’s visual nature and limitations on images in the Rosetta Code wiki. Several people who contribute Processing sketches actually included graphics in their output even if it isn’t strictly part of the task – see for example the https://rosettacode.org/wiki/Sieve_of_Eratosthenes#Processing which is also a visualizer – as making it visualize is simple to code in Processing, but complex in vanilla Java. It is also possible in some cases to provide two examples for a language like Processing – a simple / non-visual example that is closer to the basic task, and a less strict example that is more illuminating, fun, or in the spirit of Processing as a language.

2 Likes

I have submitted a new Rosetta Examples set to PDE Contributions manager.

It currently consists of only 10 sketches, but updates will be published live to PDE as sketches are added, and it should grow quickly!

Contributions most welcome, for details see CONTRIBUTING.md.

…or just open a new issue on the repo and fill out the form.

4 Likes

sorry, i not get why it is called
P5

Rosetta Examples for P5 v0.7 Jeremy Douglass  Common coding tasks in P5 from the Rosetta Code chrestomathy website.

as it is all JAVA examples, so P5 might be confusing


also a link to
https://rosettacode.org/wiki/Category:Processing
or even a link from each example to the example there
https://rosettacode.org/wiki/Ackermann_function#Processing

might be good


please also link from above post to CONTRIBUTING.md
found it

no, what i was looking for is the source of that “contributed examples”
so i could say in a issue
< link here > add line…

1 Like

Sure, just removed the link while moving the repo to a new name.

P5 = Processing. I believe this is because almost 20 years ago the domain was proce55ing.org.

This is why we then get names like p5.js (p5, but javascript), p5py (p5, but python), and pyp5js (a python version of a javascript version of p5) as well as Java mode libraries like oscp5 and ControlP5 and spacebrewp5 and dmxp5 etc. Currently, if you want to tweet about supporting Processing, the hashtag linked from the top of Processing.org is “#SupportP5”.

Yes is included in CONTRIBUTING.md – and at the top of the issues template if you open a new issue to do a pull request.

Yes, those are there already in every example. Great minds think alike!

https://github.com/jeremydouglass/rosetta_examples_p5/blob/master/examples/AckermannFunction/AckermannFunction.pde#L1-L6

1 Like

? like https://github.com/jeremydouglass/rosetta_examples_p5/issues/30


no, even if that P5 must be used here,
write somewhere that these are JAVA examples,

i already change to PDE / MODE p5js

That’s actually CONTRIBUTING for processing-docs – that’s the processing.org website with reference and tutorials repo.

For this project, instead check out GitHub - jeremydouglass/rosetta_examples_p5: Example set from Rosetta Code for P5 (Processing)