Class: Voxelamming::Turtle
Overview
Turtle graphics
Instance Method Summary collapse
- #backward(length) ⇒ Object
- #down(degree) ⇒ Object
- #forward(length) ⇒ Object
-
#initialize(voxelamming_instance) ⇒ 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(voxelamming_instance) ⇒ Turtle
Returns a new instance of Turtle.
546 547 548 549 550 551 552 553 554 555 556 |
# File 'lib/voxelamming.rb', line 546 def initialize(voxelamming_instance) @vox = voxelamming_instance @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
573 574 575 |
# File 'lib/voxelamming.rb', line 573 def backward(length) forward(-length) end |
#down(degree) ⇒ Object
581 582 583 |
# File 'lib/voxelamming.rb', line 581 def down(degree) @polar_theta += degree end |
#forward(length) ⇒ Object
558 559 560 561 562 563 564 565 566 567 568 569 570 571 |
# File 'lib/voxelamming.rb', line 558 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 @vox.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
589 590 591 |
# File 'lib/voxelamming.rb', line 589 def left(degree) @polar_phi += degree end |
#pen_down ⇒ Object
597 598 599 |
# File 'lib/voxelamming.rb', line 597 def pen_down @drawable = true end |
#pen_up ⇒ Object
601 602 603 |
# File 'lib/voxelamming.rb', line 601 def pen_up @drawable = false end |
#reset ⇒ Object
611 612 613 614 615 616 617 618 619 620 |
# File 'lib/voxelamming.rb', line 611 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
585 586 587 |
# File 'lib/voxelamming.rb', line 585 def right(degree) @polar_phi -= degree end |
#set_color(r, g, b, alpha = 1) ⇒ Object
593 594 595 |
# File 'lib/voxelamming.rb', line 593 def set_color(r, g, b, alpha = 1) @color = [r, g, b, alpha] end |
#set_pos(x, y, z) ⇒ Object
605 606 607 608 609 |
# File 'lib/voxelamming.rb', line 605 def set_pos(x, y, z) @x = x @y = y @z = z end |
#up(degree) ⇒ Object
577 578 579 |
# File 'lib/voxelamming.rb', line 577 def up(degree) @polar_theta -= degree end |