Skip to content

Terrain 3D#4

Merged
monkstone merged 6 commits intoruby-processing:masterfrom
MoiRouhs:master
Oct 3, 2018
Merged

Terrain 3D#4
monkstone merged 6 commits intoruby-processing:masterfrom
MoiRouhs:master

Conversation

@MoiRouhs
Copy link
Contributor

@MoiRouhs MoiRouhs commented Oct 3, 2018

Submitting a PR is the simplest way to contribute a sketch, or to submit a modification to an existing sketch. It is suggested that you add your new sketch to the contributed folder in the first instance. Should you require data, that should be in the data sub-folder or a library place that in the libraries sub-folder. Any ruby files that are not the sketch should be placed in libraries sub-folder otherwise the interfere with the autorun feature. It pays to run at least run rubocop on your sketches, and pay attention to code format suggestions, reek can also be helpful (these are useful tools to use, however it is not expected that you follow all their suggestions).

@monkstone
Copy link
Member

monkstone commented Oct 3, 2018

@MoiRouhs thanks for that, I have a few issues with code:-

  1. Use spaces not tabs
  2. Use prefer each to for loops
  3. Prefer map1d to p5map
  4. Put spaces in arithmetic
  5. For JRubyArt prefer non-class wrapped form

Running rubocop on submitted code will alert you to some more.
I'm not 100% sure why you are using a hash to store terrain height so I left it in here's my suggestion (I realise that it might be difficult for someone whose first language is other than English to follow rubocop):-

# Terreno
# Transcrito a JRubyArt por Carlos Rocha
# Tomado de The Coding Train https://www.youtube.com/watch?v=IKB1hWWedMk

def settings
  size 800, 800, P3D
end

def setup
  sketch_title 'Terreno'
  @w = 1400
  @h = 1100
  @scl = 30
  @col = @w / @scl
  @filas = @h / @scl
  @terreno = {}
  @mover = 0
end

def draw
  background 0
  @mover -= 0.1
  yoff = @mover
  (0..@filas).each do |y|
    xoff = 0
    (0..@col).each do |x|
      @terreno["#{x}.#{y}"] = map1d(noise(xoff, yoff), 0..1, -65..65)
      xoff += 0.2
    end
    yoff += 0.2
  end
  stroke 255
  no_fill
  stroke 235, 69, 129
  translate width / 2, height / 2
  rotate_x PI / 3
  translate(-@w / 2, -@h / 2)
  (0...@filas).each do |y|
    begin_shape(TRIANGLE_STRIP)
    (0..@col).each do |x|
      vertex(x * @scl, y * @scl, @terreno["#{x}.#{y}"])
      vertex(x * @scl, (y + 1) * @scl, @terreno["#{x}.#{y + 1}"])
      # vertex(x * @scl, y.succ * @scl, @terreno["#{x}.#{y.succ}"]) # even cooler
    end
    end_shape(CLOSE)
  end
end

@monkstone monkstone merged commit 3ec2841 into ruby-processing:master Oct 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants