11/*
22 * @name Histogram
33 * @description Calculates the histogram of an image.
4- * A histogram is the frequency distribution of the gray levels with the number of
5- * pure black values displayed on the left and number of pure white values on the right.
6- * Note that this sketch will behave differently on Android, since most images will
4+ * A histogram is the frequency distribution of the gray levels with the number of
5+ * pure black values displayed on the left and number of pure white values on the right.
6+ * Note that this sketch will behave differently on Android, since most images will
77 * no longer be full 24-bit color.
88 */
99
@@ -21,7 +21,7 @@ function setup() {
2121 image ( img , 0 , 0 ) ;
2222
2323 // Initialize the histogram
24- for ( let i = 0 ; i < 256 ; i ++ ) {
24+ for ( let i = 0 ; i < 100 ; i ++ ) {
2525 hist . push ( 0 ) ;
2626 }
2727
@@ -40,8 +40,8 @@ function draw(){
4040 stroke ( 255 ) ;
4141 // Draw half of the histogram (skip every second value)
4242 for ( let i = 0 ; i < img . width ; i += 2 ) {
43- // Map i (from 0..img.width) to a location in the histogram (0..255 )
44- let which = int ( map ( i , 0 , img . width , 0 , 255 ) ) ;
43+ // Map i (from 0..img.width) to a location in the histogram (0..100 )
44+ let which = int ( map ( i , 0 , img . width , 0 , 100 ) ) ;
4545 // Convert the histogram value to a location between
4646 // the bottom and the top of the picture
4747 let y = int ( map ( hist [ which ] , 0 , histMax , img . height , 0 ) ) ;
0 commit comments