Advertisement
stepos

Untitled

Aug 10th, 2017
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 1.03 KB | None | 0 0
  1. #pixel counter
  2. #red = [255,0, 0]
  3. #green = [0, 255, 0]
  4. #blue = [0, 0, 255]
  5. #black = [0, 0, 0]
  6. #white = [255, 255, 255]
  7. #yellow = [255, 255, 0]
  8.  
  9. #Define RED
  10. #R value must be greater 100
  11. #G and B values must be less than R/4
  12.  
  13. sample = [
  14. [[65, 67, 23], [234, 176, 0], [143, 0, 0]],
  15. [[255, 30, 51], [156, 41, 38], [3, 243, 176]],
  16. [[255, 255, 255], [0, 0, 0], [133, 28, 13]],
  17. [[26, 43, 255], [48, 2, 2], [57, 89, 202]]
  18. ]
  19. i = 0
  20. j = 0
  21. k = 0
  22. line = 0
  23.  
  24.  
  25. redcheck = false
  26. greencheck = false
  27. bluecheck = false
  28. redpixelcount = 0
  29. pixelcount = 1
  30.  
  31.  
  32. while (i < sample.length)
  33.  
  34.   while (j < sample[i].length)
  35.  
  36.     puts "PIXEL # " + pixelcount.to_s
  37.  
  38.     red = sample[i][j][0]
  39.     green = sample[i][j][1]
  40.     blue = sample[i][j][2]
  41.     r4 = red/4
  42.  
  43.       if (red >= 100 && green <= r4 && blue <= r4 )
  44.           puts "THIS IS RED"
  45.           redpixelcount += 1
  46.       end
  47.  
  48.     pixelcount += 1
  49.     j += 1
  50.  
  51.   end
  52.  
  53.   j = 0
  54.   i += 1
  55. end
  56.  
  57. puts "There are: " + (pixelcount-1).to_s + " pixels"
  58. puts redpixelcount.to_s + " are RED"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement