Class: VoxelammingGem::Turtle
- Inherits:
-
Object
- Object
- VoxelammingGem::Turtle
- Includes:
- Math
- Defined in:
- lib/voxelamming_gem.rb
Overview
Turtle graphics
Instance Method Summary collapse
- #backward(length) ⇒ Object
- #down(degree) ⇒ Object
- #forward(length) ⇒ Object
-
#initialize(build_box) ⇒ Turtle
constructor
A new instance of Turtle.
- #left(degree) ⇒ Object
- #pen_down ⇒ Object
- #pen_up ⇒ Object
- #reset ⇒ Object
- #right(degree) ⇒ Object
- #set_color(r, g, b, alpha = 1) ⇒ Object
- #set_pos(x, y, z) ⇒ Object
- #up(degree) ⇒ Object
Constructor Details
#initialize(build_box) ⇒ Turtle
Returns a new instance of Turtle.
357 358 359 360 361 362 363 364 365 366 367 |
# File 'lib/voxelamming_gem.rb', line 357 def initialize(build_box) @build_box = build_box @x = 0 @y = 0 @z = 0 @polar_theta = 90 @polar_phi = 0 @drawable = true @color = [0, 0, 0, 1] @size = 1 end |
Instance Method Details
#backward(length) ⇒ Object
384 385 386 |
# File 'lib/voxelamming_gem.rb', line 384 def backward(length) forward(-length) end |
#down(degree) ⇒ Object
392 393 394 |
# File 'lib/voxelamming_gem.rb', line 392 def down(degree) @polar_theta += degree end |
#forward(length) ⇒ Object
369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'lib/voxelamming_gem.rb', line 369 def forward(length) z = @z + length * sin(radians(@polar_theta)) * cos(radians(@polar_phi)) x = @x + length * sin(radians(@polar_theta)) * sin(radians(@polar_phi)) y = @y + length * cos(radians(@polar_theta)) x, y, z = x.round(3), y.round(3), z.round(3) if @drawable @build_box.draw_line(@x, @y, @z, x, y, z, r: @color[0], g: @color[1], b: @color[2]) end @x = x @y = y @z = z end |
#left(degree) ⇒ Object
400 401 402 |
# File 'lib/voxelamming_gem.rb', line 400 def left(degree) @polar_phi += degree end |
#pen_down ⇒ Object
408 409 410 |
# File 'lib/voxelamming_gem.rb', line 408 def pen_down @drawable = true end |
#pen_up ⇒ Object
412 413 414 |
# File 'lib/voxelamming_gem.rb', line 412 def pen_up @drawable = false end |
#reset ⇒ Object
422 423 424 425 426 427 428 429 430 431 |
# File 'lib/voxelamming_gem.rb', line 422 def reset @x = 0 @y = 0 @z = 0 @polar_theta = 90 @polar_phi = 0 @drawable = true @color = [0, 0, 0, 1] @size = 1 end |
#right(degree) ⇒ Object
396 397 398 |
# File 'lib/voxelamming_gem.rb', line 396 def right(degree) @polar_phi -= degree end |
#set_color(r, g, b, alpha = 1) ⇒ Object
404 405 406 |
# File 'lib/voxelamming_gem.rb', line 404 def set_color(r, g, b, alpha = 1) @color = [r, g, b, alpha] end |
#set_pos(x, y, z) ⇒ Object
416 417 418 419 420 |
# File 'lib/voxelamming_gem.rb', line 416 def set_pos(x, y, z) @x = x @y = y @z = z end |
#up(degree) ⇒ Object
388 389 390 |
# File 'lib/voxelamming_gem.rb', line 388 def up(degree) @polar_theta -= degree end |