<commit_before>require_relative 'lib/color/color_converter'
require_relative 'lib/color/color_comparator'
require_relative 'lib/quadtree'
require_relative 'lib/node'
require 'rmagick'

include Magick

quadtree = Quadtree.new
img = ImageList.new('tiny.png')

i = 0
while i < img.rows
  scanline = img.export_pixels(0, i, img.columns, 1, 'RGB')
  row = []
  scanline.each_slice(3).with_index do |pixel, j|
    rgb = { r: (pixel[0] / 65_535.0) * 255,
            g: (pixel[1] / 65_535.0) * 255,
            b: (pixel[2] / 65_535.0) * 255 }
    lab = ColorConverter.rgb_to_lab(rgb)
    row.push(Node.new(lab))
  end
  quadtree.nodes.push(row)
  i += 1
end

quadtree.generate
p quadtree.root

file = File.open('quadtree.txt', 'w')
file.write(quadtree.nodes)<commit_msg>Use times loop<commit_after>require_relative 'lib/color/color_converter'
require_relative 'lib/color/color_comparator'
require_relative 'lib/quadtree'
require_relative 'lib/node'
require 'rmagick'

include Magick

quadtree = Quadtree.new
img = ImageList.new('tiny.png')

img.rows.times do |i|
  scanline = img.export_pixels(0, i, img.columns, 1, 'RGB')
  row = []
  scanline.each_slice(3).with_index do |pixel, j|
    rgb = { r: (pixel[0] / 65_535.0) * 255,
            g: (pixel[1] / 65_535.0) * 255,
            b: (pixel[2] / 65_535.0) * 255 }
    lab = ColorConverter.rgb_to_lab(rgb)
    row.push(Node.new(lab))
  end
  quadtree.nodes.push(row)
end

quadtree.generate
p quadtree.root

file = File.open('quadtree.txt', 'w')
file.write(quadtree.nodes)
{'fraction_non_alphanumeric': 0.14831905075807514, 'fraction_numerical': 0.04482531311799604, 'mean_word_length': 3.7586206896551726, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3027878', 'n_tokens_mistral': 637, 'n_tokens_neox': 587, 'n_words': 117}