class Pxlsrt::Spiral

Spiral iteration.

Public Class Methods

new(x, y) click to toggle source
# File lib/pxlsrt/spiral.rb, line 5
def initialize(x, y)
        @x = x
        @y = y
        @direction = "up"
        @step = 1
        @at = 0
        @count = 0
        @cycles = -1
end

Public Instance Methods

count() click to toggle source

Return amount iterated.

# File lib/pxlsrt/spiral.rb, line 31
def count
        return @count
end
cycles() click to toggle source

Return cycles gone through completely.

# File lib/pxlsrt/spiral.rb, line 36
def cycles
        return @cycles
end
direction() click to toggle source

Return current direction.

# File lib/pxlsrt/spiral.rb, line 26
def direction
        return @direction
end
next() click to toggle source

Goes to next position. Returns position.

# File lib/pxlsrt/spiral.rb, line 46
def next
        case @direction
        when "left"
                @x -= 1
                @at += 1
                if @at == @step
                        @direction = "down"
                        @at = 0
                        @step += 1
                end
        when "down"
                @y += 1
                @at += 1
                if @at == @step
                        @direction = "right"
                        @at = 0
                end
        when "right"
                @x += 1
                @at += 1
                if @at == @step
                        @direction = "up"
                        @at = 0
                        @step += 1
                end
        when "up"
                @cycles += 1 if @at == 0
                @y -= 1
                @at += 1
                if @at == @step
                        @direction = "left"
                        @at = 0
                end
        end
        @count += 1
        return pos
end
pos() click to toggle source

Return current position.

# File lib/pxlsrt/spiral.rb, line 41
def pos
        return {:x => @x, :y => @y}
end
x() click to toggle source

Return current x value.

# File lib/pxlsrt/spiral.rb, line 16
def x
        return @x
end
y() click to toggle source

Return current y value.

# File lib/pxlsrt/spiral.rb, line 21
def y
        return @y
end