You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<p>Two dimensional tables have both rows and columns. You have probably seen many tables like this if you have used a
5
+
<p>Two dimensional tables have both rows and columns. You have probably seen many tables like this if you have used a
6
6
spreadsheet program. Another object that is organized in rows and columns is a digital image. In this section we will
7
7
explore how iteration allows us to manipulate these images.</p>
8
-
<p>A <term>digital image</term> is a finite collection of small, discrete picture elements called <term>pixels</term>. These pixels are organized in a two-dimensional grid. Each pixel represents the smallest amount of picture information that is
8
+
<p>A <term>digital image</term> is a finite collection of small, discrete picture elements called <term>pixels</term>. These pixels are organized in a two-dimensional grid. Each pixel represents the smallest amount of picture information that is
9
9
available. Sometimes these pixels appear as small <q>dots</q>.
10
-
</p>
11
-
<p>Each image (grid of pixels) has its own width and its own height. The width is the number of columns and the height is the number of rows. We can name the pixels in the grid by using the column number and row number. However, it is very important to remember
10
+
</p>
11
+
<p>Each image (grid of pixels) has its own width and its own height. The width is the number of columns and the height is the number of rows. We can name the pixels in the grid by using the column number and row number. However, it is very important to remember
12
12
that computer scientists like to start counting with 0! This means that if there are 20 rows, they will be named 0,1,2, and so on through 19. This will be very useful later when we iterate using range.</p>
13
-
<p>In the figure below, the pixel of interest is found at column <term>c</term> and row <term>r</term>.
<p>When you run the program you can see that the image has a width of 400 pixels and a height of 244 pixels. Also, the
419
433
pixel at column 45, row 55, has RGB values of 165, 161, and 158. Try a few other pixel locations by changing the <c>getPixel</c> arguments and rerunning the program.</p>
These are the values for the pixel at row 30, column 100. Get the values for row 100 and column 30 with p = img.getPixel(100, 30).
434
-
</p></feedback>
449
+
</p>
450
+
</feedback>
435
451
</choice>
436
452
<choicecorrect="yes">
437
453
<statement>
438
454
<p>183 179 170</p>
439
455
</statement>
440
-
<feedback><p>
456
+
<feedback>
457
+
<p>
441
458
Yes, the RGB values are 183 179 170 at row 100 and column 30.
442
-
</p></feedback>
459
+
</p>
460
+
</feedback>
443
461
</choice>
444
462
<choice>
445
463
<statement>
446
464
<p>165 161 158</p>
447
465
</statement>
448
-
<feedback><p>
466
+
<feedback>
467
+
<p>
449
468
These are the values from the original example (row 45, column 55). Get the values for row 100 and column 30 with p = img.getPixel(30, 100).
450
-
</p></feedback>
469
+
</p>
470
+
</feedback>
451
471
</choice>
452
472
<choice>
453
473
<statement>
454
474
<p>201 104 115</p>
455
475
</statement>
456
-
<feedback><p>
476
+
<feedback>
477
+
<p>
457
478
These are simply made-up values that may or may not appear in the image. Get the values for row 100 and column 30 with p = img.getPixel(30, 100).
458
-
</p></feedback>
479
+
</p>
480
+
</feedback>
459
481
</choice>
460
482
</choices>
461
483
</exercise>
@@ -622,33 +644,41 @@ d.
622
644
<statement>
623
645
<p>Output a</p>
624
646
</statement>
625
-
<feedback><p>
647
+
<feedback>
648
+
<p>
626
649
i will start with a value of 0 and then j will iterate from 0 to 1. Next, i will be 1 and j will iterate from 0 to 1. Finally, i will be 2 and j will iterate from 0 to 1.
627
-
</p></feedback>
650
+
</p>
651
+
</feedback>
628
652
</choice>
629
653
<choice>
630
654
<statement>
631
655
<p>Output b</p>
632
656
</statement>
633
-
<feedback><p>
657
+
<feedback>
658
+
<p>
634
659
The inner for-loop controls the second digit (j). The inner for-loop must complete before the outer for-loop advances.
635
-
</p></feedback>
660
+
</p>
661
+
</feedback>
636
662
</choice>
637
663
<choice>
638
664
<statement>
639
665
<p>Output c</p>
640
666
</statement>
641
-
<feedback><p>
667
+
<feedback>
668
+
<p>
642
669
The inner for-loop controls the second digit (j). Notice that the inner for-loop is over the list [0, 1].
643
-
</p></feedback>
670
+
</p>
671
+
</feedback>
644
672
</choice>
645
673
<choice>
646
674
<statement>
647
675
<p>Output d</p>
648
676
</statement>
649
-
<feedback><p>
677
+
<feedback>
678
+
<p>
650
679
The outer for-loop runs 3 times (0, 1, 2) and the inner for-loop runs twice for each time the outer for-loop runs, so this code prints exactly 6 lines.
651
-
</p></feedback>
680
+
</p>
681
+
</feedback>
652
682
</choice>
653
683
</choices>
654
684
</exercise>
@@ -676,33 +706,41 @@ newblue = 0
676
706
<statement>
677
707
<p>It would look like a red-washed version of the bell image</p>
678
708
</statement>
679
-
<feedback><p>
709
+
<feedback>
710
+
<p>
680
711
Because we are removing the green and the blue values, but keeping the variation of the red the same, you will get the same image, but it will look like it has been bathed in red.
681
-
</p></feedback>
712
+
</p>
713
+
</feedback>
682
714
</choice>
683
715
<choice>
684
716
<statement>
685
717
<p>It would be a solid red rectangle the same size as the original image</p>
686
718
</statement>
687
-
<feedback><p>
719
+
<feedback>
720
+
<p>
688
721
Because the red value varies from pixel to pixel, this will not look like a solid red rectangle. For it to look like a solid red rectangle each pixel would have to have exactly the same red value.
689
-
</p></feedback>
722
+
</p>
723
+
</feedback>
690
724
</choice>
691
725
<choice>
692
726
<statement>
693
727
<p>It would look the same as the original image</p>
694
728
</statement>
695
-
<feedback><p>
729
+
<feedback>
730
+
<p>
696
731
If you remove the blue and green values from the pixels, the image will look different, even though there does not appear to be any blue or green in the original image (remember that other colors are made of combinations of red, green and blue).
697
-
</p></feedback>
732
+
</p>
733
+
</feedback>
698
734
</choice>
699
735
<choice>
700
736
<statement>
701
737
<p>It would look the same as the negative image in the example code</p>
702
738
</statement>
703
-
<feedback><p>
739
+
<feedback>
740
+
<p>
704
741
Because we have changed the value of the pixels from what they were in the original ActiveCode box code, the image will not be the same.
0 commit comments