Created
October 12, 2018 15:30
-
-
Save monkstone/9d1dba8efd8de0839eecf1b54066a421 to your computer and use it in GitHub Desktop.
Terrain Sketch on Raspberry PI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@MoiRouhs someone was complaining about poor performance of
terrain.pdesketch on processing forum so I hacked about a bit on your sketch (doesn't work too bad).