Sha256: 219f5472857a9160745429286dba0ba15a647fe2cb01f94083bcad0a27f822e2

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

require 'ws_light/set/color_set'

module WSLight
  module Set
    # Creates a strawberry set, some green, lots of pinkish red with a few greenish dots
    class StrawberrySet < ColorSet
      LENGTH_RED = 0.9
      COLOR_NUT = Color.new(220, 255, 15)

      def frame
        @set ||= create_frame
      end

      def create_frame
        set = []

        length_red = (LENGTH_RED * @length).to_i

        color_strawberry = Color.new(255, 7, 15)
        color_leaves = Color.new(15, 191, 15)

        @length.times do |i|
          set << (i < length_red ? color_strawberry : color_leaves)
        end

        set = sprinkle_nuts(set)

        set.reverse! if rand(2).zero?

        type == :double ? set + set.reverse : set
      end

      def sprinkle_nuts(set)
        length_red = (LENGTH_RED * @length).to_i
        distance = 0
        while distance < length_red - 21
          distance += rand(5..20)
          set[distance] = COLOR_NUT
        end

        set
      end

      def pixel(number)
        frame[number]
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ws_light-0.4.2 lib/ws_light/set/strawberry_set.rb