Skip to content

Instantly share code, notes, and snippets.

@monkstone
Created October 12, 2018 15:30
Show Gist options
  • Select an option

  • Save monkstone/9d1dba8efd8de0839eecf1b54066a421 to your computer and use it in GitHub Desktop.

Select an option

Save monkstone/9d1dba8efd8de0839eecf1b54066a421 to your computer and use it in GitHub Desktop.
Terrain Sketch on Raspberry PI
attr_reader :terrain, :rows, :columns, :mover
WIDTH = 1400
HEIGHT = 1100
SCL = 30
def settings
size 800, 800, P3D
end
def setup
# sketch_title 'Terreno' # sketch_title doesn't work with P3D on PI
@columns = WIDTH / SCL
@rows = HEIGHT / SCL
@terrain = {}
@mover = 0
end
def draw
background 0
@mover -= 0.1
yoff = mover
(0..rows).each do |y|
xoff = 0
(0..columns).each do |x|
terrain[[x, y]] = Vec3D.new(x * SCL, y * SCL, map1d(noise(xoff, yoff), 0..1.0, -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(-WIDTH / 2, -HEIGHT / 2)
(0...rows).each do |y|
begin_shape(TRIANGLE_STRIP)
(0..columns).each do |x|
terrain[[x, y]].to_vertex(renderer)
terrain[[x, y.succ]].to_vertex(renderer)
end
end_shape(CLOSE)
end
end
def renderer
@renderer ||= AppRender.new(self)
end
@monkstone
Copy link
Author

@MoiRouhs someone was complaining about poor performance of terrain.pde sketch on processing forum so I hacked about a bit on your sketch (doesn't work too bad).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment