Computer Science
Gilmour AcademyLancerTech
  • Our Curriculum and Department
  • Intro to Programming
    • 1: Parts of a Computer
    • 2: Parts of Python
    • 3: DRY Turtle
    • 4: Turtle Design App
    • Wordle with Turtles
    • 5: Interactive Turtles
    • OLD 5: Replit, GitHub, and repositories (Oh my!)
    • 6: Raspberry Pi / GoPiGo
    • 7: Kivy
  • Intro to Web Design
    • 1: Internet?
    • 2: Websites?
    • 3: Bootstrap Template
    • 4: Graphics and Branding
    • 5: Collaboration
    • 6: Advanced Editing
    • Publish Static HTML
  • AP Computer Science
    • 1: Logic & Instances
    • 2: How Java Works
    • 3: Data Types & Flow
    • 4: Strings
    • 5: Objects & References
    • 6: Inheritance & Algorithms
    • 7: Data Structures
    • 8: Sorting
    • 9: Review
    • Data Science
  • Web App Dev
    • 1: Core Concepts
    • 2: MVT Pattern
    • 3: Hello Flask
    • 4: Install Flaskinni
    • 5: Tour Flaskinni
    • 6: Visualize Your App
    • 7: Theme & Blueprint
    • 8: Standup Your DB
    • 9: Advanced Topics
    • 10: Deployment
  • 2D Game Design
    • Class Overview
    • Gamemaker Studio 2 and Github Setup
    • Game 1: Bouncing Ball
    • Turning in your games
    • Game 2: Maze
    • Game 3: Ping Pong
    • Game 4: Breakout
    • Game 5: Tank Battle
    • Game 6 Highlights
    • DO NOT DO:
    • Game 7: Final Project
    • Publish to Opera
    • FAQ
  • 3D Game Design
    • 1: Class Overview
    • 2: Installation
    • 3: Exploring the Unity UI
    • Game 1: Rolling Ball
    • Game 2: Tanks
    • Game 3: Third Person Platformer
    • Game 4: Final project
    • FAQs
    • OLD: Distance Learning Setup
    • OLD: GIT
  • 3D Modeling & Fabrication
    • Installation
    • Fusion 360 Interface and Sketch Modeling
    • Primitive Modeling
    • Patterns
    • Appearances and Rendering
    • Building Community Gallery Page 2023
    • Parametric Modeling
    • 3D Printing Concerns
    • Assemblies and Mechanical Design
    • Laser Cutting
    • Sculpt Tools
    • Milling Concerns
  • Robotics 7
    • Software Installation
    • Python basics (trinket.io)
    • Python Turtle
    • Programming for the Ev3
    • Setting up for clarity
  • Robotics 8
    • Replit
    • Python review
    • Kivy Basics
    • Calculator
  • Competitive Robotics
    • Hardware Team
      • CAD Examples
      • Elevators
    • Software Team
      • Command Pattern
      • Example Command
      • Subsystem
      • Running Your Code
      • Under the Hood
      • RoadRunner
      • Vision Processing
  • Archives
    • Adiletta Archives
      • Old Web
        • Ex: WordPress CMS
      • ItP
        • OLD: Parts of Python (old -- Mr. A)
        • OLD: 5: Raspberry Pi
        • OLD: 6: Deploying Code
        • OLD 7: Nav Algorithm
    • Vanek Archives
      • OLD Robotics 8
        • OLD: End of Class Project
      • OLD Competitive Robotics
        • Untitled
        • Webots Videos
      • OLD Robotics 7
        • Trinket Introduction
        • Lists: x/y position
        • Functions: Math program
        • Lists: Grocery List
        • Study Guide Program
        • Tic Tac Toe Game
        • Dice Roller Program
        • Visualization
        • Dice Roller + Visualization
        • OpenSCAD: Installation
        • OpenSCAD: Command Sheet and Intro
        • OpenSCAD: Difference
        • OpenSCAD: Variables
        • OpenSCAD: Union
        • OpenSCAD: For Loops
        • OpenSCAD: Final Project
      • OLD Art I - Blender Sculpting
        • Class Overview
        • Installation
        • Lesson 1 - Tools
        • Lesson 2 - Detail
        • Lesson 3 - Base Mesh: Metaballs
        • Lesson 4: Converting metaballs and adding detail
        • Lesson 5: Masking, Hiding, and Working with Multiple Objects
        • Lesson 6: Joining Objects & Basing
        • Lesson 7: Sculpture Painting
        • Student Gallery: Animal Sculpts
        • Lesson 8: 3D Compositon
        • Lesson 9: The Project - Putting it all together
        • Lesson 10: Developing the image further
        • Lesson 11: Layout the base metaball mesh.
        • Lesson 12: Final Detail
        • Lesson 13: Basing and Painting
        • Final Project Gallery
      • OLD Fab
        • OLD Building Community Project Gallery
        • Copy of Building Community Project Gallery
        • old Building Community Project Gallery
      • OLD: Turtle Design App
      • OLD Arduino Robotics 8
        • Arduino Basic Commands Cheat Sheet
        • Logging into Tinkercad
        • Arduino, Circuits, LEDs and Resistors
        • Functions and Variables
        • Serial Monitor
        • Buttons and Interrupts
        • Traffic Light Project
        • Potentiometers + Servos
        • Piezo Buzzer and Tone();
        • Sequencer Project
        • Arrays and for loops
        • Extra Loop Practice
        • Refining the Sequencer
        • Servos
        • Ultrasonic Sensors
        • Final Project
Powered by GitBook
On this page
  • Learning Targets
  • PicLab
  • Activity 1 & 2: Color Code
  • Activity 3: Exploring a Picture
  • Activity 4: Picture Arrays
  • Activity 5: Get working
  • Review
  • NumGrid Practice
  • Exercises

Was this helpful?

Export as PDF
  1. AP Computer Science

7: Data Structures

We will build our own photo editing tools as we study more complex nested loops to traverse and mutate 2D arrays.

Previous6: Inheritance & AlgorithmsNext8: Sorting

Last updated 12 months ago

Was this helpful?

Learning Targets

  • I can remove a column from a 2D array in Java.

  • I can write 2D array methods for the PicLab.

PicLab

Activity 1 & 2: Color Code

Eight Bits for 0 - 255

  1. Convert 128 to binary

  2. Covert 225 to binary

  3. Convert 11010111 from base 2 to base 10

This is a byte.

3 Bytes to RGB

Max red, green and blue (255, 255, 255) is white. No red, green and blue (0, 0, 0) is black. Sometimes we add a fourth byte to control alpha layer (transparency). rgba(255, 255, 255, 255) is opaque black.

Compress to Hex

Two digits in base 16, hexadecimal, can describe 0 - 255. Eight digits can contain rgba. #FF0000FF is opaque black.

Activity 3: Exploring a Picture

  1. What is the row index for the top left corner of the picture?

  2. What is the column index for the top left corner of the picture?

  3. The width of the picture is 640. What is the right most column index?

  4. The height of the picture is 480. What is the bottom most row index?

Activity 4: Picture Arrays

Activity 5: Get working

PictureTester.java
        //A5
        testKeepOnlyBlue();
        testKeepOnlyRed();
        testNegate();
        testGrayscale();
        testFixUnderwater();
        //A6
        testMirrorVertical();
        testMirrorVerticalRightToLeft();
        testMirrorHorizontal();
        testMirrorHorizontalBotToTop();
        testMirrorDiagonal();
        //A7
        testMirrorArms();
        testMirrorGull();
        //A8
        testCollage();
        //A9
        testEdgeDetection2();

Review

NumGrid Practice

NumGroup.java
public interface NumGroup {
    
    /**
     * Provides a total sum of its contained numbers
     * @return accumulated total
     */
    int sum();

    /**
     * Organizes its contained numbers to be sorted from least to great
     * using the selection sort algorithm
     */
    void sort();

    /**
     * Rearranges its contained numbers using the selection shuffle algorithm
     */
    void shuffle();

    /**
     * Displays the contained numbers in a returned string
     * @return formatted String display
     */
    String toString();
    
}

Exercises

  1. Imagine a circumstance where you might use an interface and an abstract class. Create and implement the interface and abstract class. Instantiate objects that extend these. Create a polymorphic container or method.

  2. Calculate the sum of an indicated column from an extremely rare occurrence of a 2D ArrayList: public static int sumColumn(int col, List<List<Integer>> grid){

  3. Remove a row from a 2D array: public static String[][] removeRow(int row, String[][] names){

  4. Calculate the sum of an entire 2D array: public static double sum(double[][] grid){

  5. Count the number of occurrences of a given number in a 2D array public static int count(int[][] grid, int target){

  6. Add a new column to a 2D array of Pixels with the average color at the end of the image public static Pixel[][] addAverageColumn(Pixel[][] picture){ // each Pixel has .getColor() which gives a single int // return an array that's one column wider, containing the average of every color in that row // you can set the color of a pixel by using .setColor() and passing the method the average of that row's .getColor() }

  7. Convert an RGB value like 220, 175, 205 to a hex value

  8. We have an array of Friends, Friends[] friends, and we want to make sure that each of our friends has the items they requested from the store. Friend.getItems() returns an array of Item objects (Item implements the Comparable interface so you can use .equals() to compare two items). If the Item is not on the shopping list, we'll add it to an ArrayList<Item> called requests. The Item class also has a publicly accessible boolean that marks if the Item has been claimed: Item.claimed.

    public ArrayList<Item> checkShoppingList(Friends[] friends, ArrayList<Item> list){

Okay, so you know how a regular array works
Now a 2D arrays has a whole array in each spot
You don't have to just use dumb old ints. Instantiated objects are cool too
We use row-major to define the 2D array of pixels that makes a picture
2D traversals go row by row and each column between each row