Rosetta Examples development

We have a great development chat happening on the Rosetta Examples release announcement thread – so I’m moving all that discussion here so that it can continue.

The idea is to make the other thread announcements-only so that it only updates periodically.

thanks, what i see here in PDE is

should i Remove and install again?


OK remove & install (0.7) works and gives (0.8)

1 Like

The guy’s name is

  • Sieve of Eratosthenes
3 Likes

Yes, ha, thanks so much – caught that just the day before you did.

1 Like

I think that the Contributions Manager doesn’t re-load its sources immediately – and for that reason it can take a while for it to pick up a change, even if you restart PDE. I’m not sure, though. But yes, forcing a manual install will always work.

1 Like

I have added the Bitmap/Bézier curves/Cubic task here.
I followed your suggestion and along the strict task I also posted a visualizer code and a link to OpenProcessing to run it on line.
When posting a task code on the Rosetta page, one could get lost, because you really have to edit someone else page right on the top. Somewhat strange but that"s how to do it. Also the help/start page is not immediately visible. Unfortunately Rosetta"s home page is not editable, so I edited some other pages adding the link.

.

3 Likes

Thank you, @noel !

I’ll commit those sketches to the github repo and include the credit to your username. Let me know if you would prefer a full name or something else…

1 Like

Actually, I would like to keep rosetta’s habit of using no signing at all, to maintain the possibility of changing/improving by others. Afterall it is just basic code.

2 Likes

I have a solution for the dragon fractal, based on contextfreeart, that you might find interesting? Jeremy Ashkenas created context free art DSL for ruby-processing that I have taken forward for JRubyArt:-

require 'cf3'
 
INV_SQRT = 1 / Math.sqrt(2)
 
def setup_the_dragon
  @dragon = ContextFree.define do
    shape :start do
      dragon alpha: 1
    end
 
    shape :dragon do
      square hue: 0, brightness: 0, saturation: 1, alpha: 0.02
      split do
        dragon size: INV_SQRT, rotation: -45, x: 0.25, y: 0.25
        rewind
        dragon size: INV_SQRT, rotation: 135, x: 0.25, y: 0.25
        rewind
      end
    end
  end
end
 
def settings
  size 800, 500
end
 
def setup
  sketch_title 'Heighway Dragon'
  setup_the_dragon
  draw_it
end
 
def draw_it
  background 255
  @dragon.render :start, size: width * 0.8, stop_size: 2,
                         start_x: width / 3, start_y: height / 3.5
end

2 Likes

Could you please describe what, in your opinion, are the advantages in using JRubyArt?

1 Like

JRubyArt is probably best for people familiar with ruby, who want to explore generative art. However there must be people like myself who had learned java, tried processing and then discovered ruby-processing (precursor to JRubyArt) that choose to learn ruby as an interesting alternative to java (it got me hooked). Ruby is a language that from the outset has been designed to make programmers happy. Ruby is also good for creating DSL.

2 Likes

Here is the p5 sketch for Dragon Curve as simple as possible by using solely translation and rotation.

5 Likes

Nice! I converted your sketch for JRubyArt:-

attr_reader :len, :gen

def setup
  sketch_title 'Heighway Dragon'
  background(0, 0, 255)
  translate(170, 170)
  stroke(255)
  @len = 3
  @gen = 14
  turn_left(len, gen)
end

def turn_right(len, gen)
  return draw_line(len) if gen.zero?

  turn_left(len, gen - 1)
  rotate(90.radians)
  turn_right(len, gen - 1)
end

def draw_line(len)
  line(0, 0, 0, -len)
  translate(0, -len)
end

def turn_left(len, gen)
  return draw_line(len) if gen.zero?

  turn_left(len, gen - 1)
  rotate(-90.radians)
  turn_right(len, gen - 1)
end

def settings
  size(700, 600)
end

3 Likes

Ruby is much better represented on the Rosetta site than as P5
There is another curve not present in both languages.
Here is a p5 “Koch Curve” (rotate/translate) sketch.
What would be a Ruby (not rotate/translate) version.

I already have an animated example which uses this library which is stored locally. The library should be stored in a folder library/library_name and with filename library_name.rb (only recently fixed).

I’ve tried to find an online Ruby compiler but none of them accepts uploading a lib file. So I can’t visualize the outcome.

I have ported it to Processing Python :slight_smile:

"""
Dragon Curve https://www.rosettacode.org/wiki/Dragon_curve#Processing
 2020-02 Noel
 2020-03 Alexandre Villares (Python Mode)
Task: Create and display a dragon curve fractal.
https://en.wikipedia.org/wiki/Dragon_curve
(You may either display the curve directly or write it to an image file.)
For some brief notes the algorithms used and how they might suit various languages,
see the Rosetta Code task page.
"""

l = 3
ints = 13

def setup():
  size(700, 600)
  background(0, 0, 255)
  translate(150, 100)
  stroke(255)
  turn_left(l, ints)
  turn_right(l, ints)

def turn_right(l, ints):
    if ints == 0:
        line(0, 0, 0, -l)
        translate(0, -l)
    else:
        turn_left(l, ints - 1)
        rotate(radians(90))
        turn_right(l, ints - 1)
  
def turn_left(l, ints):
    if ints == 0:
        line(0, 0, 0, -l)
        translate(0, -l)
    else:
        turn_left(l, ints - 1)
        rotate(radians(-90))
        turn_right(l, ints - 1)
3 Likes

@jeremydouglass you are a true wizard aren’t you! You have fixed all my messed up edits and categories and sub-categories and all things at https://rosettacode.org thank you so much! :smiley:

Nonsense – your sketches were all beautiful clean code, and that’s what counts. Happy to help hash out the arcane mediawiki issues.

1 Like

@jeremydouglass Yeah thanks for fixing mediawiki with JRubyArt at https://rosettacode.org. I’ve just posted my Color Wheel submission, somewhat based on Processing version, however I’m very proud of JRubyArt grid functionality:-

def settings
  size(300, 300)
end

def setup
  sketch_title 'Color Wheel'
  background(0)
  radius = width / 2.0
  center = width / 2
  grid(width, height) do |x, y|
    rx = x - center
    ry = y - center
    sat = Math.hypot(rx, ry) / radius
    if sat <= 1.0
      hue = ((Math.atan2(ry, rx) / PI) + 1) / 2.0
      color_mode(HSB)
      col = color((hue * 255).to_i, (sat * 255).to_i, 255)
      set(x, y, col)
    end
  end
end

2 Likes