diff options
-rw-r--r-- | .gitignore | 18 | ||||
-rw-r--r-- | README.md | 9 | ||||
-rw-r--r-- | bin/README.md | 3 | ||||
-rw-r--r-- | dev/README.md | 1 | ||||
-rw-r--r-- | dev/a1_textrain/a1_textrain.pde | 159 | ||||
-rw-r--r-- | dev/a1_textrain/data/TextRainInput.mov | bin | 0 -> 5615074 bytes | |||
-rw-r--r-- | dev/a1_textrain/data/TextRainInput2.mov | bin | 0 -> 7548818 bytes | |||
-rw-r--r-- | dev/a1_textrain/data/TextRainInput3.mov | bin | 0 -> 11075890 bytes | |||
-rw-r--r-- | dev/a1_textrain/data/TextRainInput4.mov | bin | 0 -> 12460114 bytes | |||
-rw-r--r-- | include/README.md | 3 | ||||
-rw-r--r-- | lib/README.md | 3 | ||||
-rw-r--r-- | share/README.md | 3 | ||||
-rw-r--r-- | worksheets/README.md | 1 | ||||
-rw-r--r-- | worksheets/a1_textrain.md | 68 |
14 files changed, 268 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5ff499b --- /dev/null +++ b/.gitignore @@ -0,0 +1,18 @@ +.DS_Store* + +# These directories are meant for installing files generated inside the dev/ directory +# They are in the git repo only so that students will checkout the intended directory +# structure from the start, but we do not want to add anything inside them to git. +# So, we ignore all files inside the directories except for a README. + +bin/* +!bin/README.md + +include/* +!include/README.md + +lib/* +!lib/README.md + +share/* +!share/README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..5a4fca7 --- /dev/null +++ b/README.md @@ -0,0 +1,9 @@ +The directory structure is as follows: + +dev/ -- sourcecode for software under development, including assignments +worksheets/ -- .md files you should edit and then git commit for the worksheet portion of each assignment + +bin/ -- executables and .dlls should be installed here. this directory should be added to your Windows PATH environment variable +include/ -- C++ header files should be installed here. +lib/ -- C++ libraries should be installed here +share/ -- shared data (images, config files, etc.) needed by installed programs should go here diff --git a/bin/README.md b/bin/README.md new file mode 100644 index 0000000..bc686c5 --- /dev/null +++ b/bin/README.md @@ -0,0 +1,3 @@ +This directory is only for installing binary, executable files. +Nothing other than this README file should be committed to git. +The .gitignore file in the root directory is setup to ignore everything in this directory except for the README file. diff --git a/dev/README.md b/dev/README.md new file mode 100644 index 0000000..58f4032 --- /dev/null +++ b/dev/README.md @@ -0,0 +1 @@ +This directory is for storing sourcecode for software under development, including assignments diff --git a/dev/a1_textrain/a1_textrain.pde b/dev/a1_textrain/a1_textrain.pde new file mode 100644 index 0000000..686824c --- /dev/null +++ b/dev/a1_textrain/a1_textrain.pde @@ -0,0 +1,159 @@ +/* + * CSci-4611 Assignment #1 Text Rain + */ + + +/* Note: if Processing's video library does not support your particular combination of webcam and + operating system, then the Sketch may hang in the setup() routine when the list of available + image capture devices is requestd with "Capture.list()". If this happens, you can skip all of + the camera initilization code and just run in movie mode by setting the following global + variable to true. + */ +boolean forceMovieMode = false; + +// Global vars used to access video frames from either a live camera or a prerecorded movie file +import processing.video.*; +String[] cameraModes; +Capture cameraDevice; +Movie inputMovie; +boolean initialized = false; + + +// Both modes of input (live camera and movie) will update this same variable with the lastest +// pixel data each frame. Use this variable to access the new pixel data each frame! +PImage inputImage; + + + +// Called automatically by Processing, once when the program starts up +void setup() { + size(1280, 720); + inputImage = createImage(width, height, RGB); + + if (!forceMovieMode) { + println("Querying avaialble camera modes."); + cameraModes = Capture.list(); + println("Found " + cameraModes.length + " camera modes."); + for (int i=0; i<cameraModes.length; i++) { + println(" " + i + ". " + cameraModes[i]); + } + // if no cameras were detected, then run in offline mode + if (cameraModes.length == 0) { + println("Starting movie mode automatically since no cameras were detected."); + initializeMovieMode(); + } + else { + println("Press a number key in the Processing window to select the desired camera mode."); + } + } +} + + + +// Called automatically by Processing, once per frame +void draw() { + // start each frame by clearing the screen + background(0); + + if (!initialized) { + // IF NOT INITIALIZED, DRAW THE INPUT SELECTION MENU + drawMenuScreen(); + } + else { + // IF WE REACH THIS POINT, WE'RE PAST THE MENU AND THE INPUT MODE HAS BEEN INITIALIZED + + + // GET THE NEXT FRAME OF INPUT DATA FROM LIVE CAMERA OR MOVIE + if ((cameraDevice != null) && (cameraDevice.available())) { + // Get image data from cameara and copy it over to the inputImage variable + cameraDevice.read(); + inputImage.copy(cameraDevice, 0,0,cameraDevice.width,cameraDevice.height, 0,0,inputImage.width,inputImage.height); + } + else if ((inputMovie != null) && (inputMovie.available())) { + // Get image data from the movie file and copy it over to the inputImage variable + inputMovie.read(); + inputImage.copy(inputMovie, 0,0,inputMovie.width,inputMovie.height, 0,0,inputImage.width,inputImage.height); + } + + + // DRAW THE INPUTIMAGE ACROSS THE ENTIRE SCREEN + // Note, this is like clearing the screen with an image. It will cover up anything drawn before this point. + // So, draw your text rain after this! + set(0, 0, inputImage); + + + // DRAW THE TEXT RAIN, ETC. + // TODO: Much of your implementation code should go here. At this point, the latest pixel data from the + // live camera or movie file will have been copied over to the inputImage variable. So, if you access + // the pixel data from the inputImage variable, your code should always work, no matter which mode you run in. + + + + } +} + + +// Called automatically by Processing once per frame +void keyPressed() { + if (!initialized) { + // CHECK FOR A NUMBER KEY PRESS ON THE MENU SCREEN + if ((key >= '0') && (key <= '9')) { + int input = key - '0'; + if (input == 0) { + initializeMovieMode(); + } + else if ((input >= 1) && (input <= 9)) { + initializeLiveCameraMode(input); + } + } + } + else { + // CHECK FOR KEYPRESSES DURING NORMAL OPERATION + // TODO: Fill in your code to handle keypresses here.. + if (key == CODED) { + if (keyCode == UP) { + // up arrow key pressed + } + else if (keyCode == DOWN) { + // down arrow key pressed + } + } + else if (key == ' ') { + // spacebar pressed + } + } +} + + + +// Loads a movie from a file to simulate camera input. +void initializeMovieMode() { + String movieFile = "TextRainInput.mov"; + println("Simulating camera input using movie file: " + movieFile); + inputMovie = new Movie(this, movieFile); + inputMovie.loop(); + initialized = true; +} + + +// Starts up a webcam to use for input. +void initializeLiveCameraMode(int cameraMode) { + println("Activating camera mode #" + cameraMode + ": " + cameraModes[cameraMode]); + cameraDevice = new Capture(this, cameraModes[cameraMode-1]); + cameraDevice.start(); + initialized = true; +} + + +// Draws a quick text-based menu to the screen +void drawMenuScreen() { + int y=10; + text("Press a number key to select an input mode", 20, y); + y += 40; + text("O: Offline mode, test with TextRainInput.mov movie file instead of live camera feed.", 20, y); + y += 40; + for (int i = 0; i < min(9,cameraModes.length); i++) { + text(i+1 + ": " + cameraModes[i], 20, y); + y += 40; + } +} diff --git a/dev/a1_textrain/data/TextRainInput.mov b/dev/a1_textrain/data/TextRainInput.mov Binary files differnew file mode 100644 index 0000000..ae45b66 --- /dev/null +++ b/dev/a1_textrain/data/TextRainInput.mov diff --git a/dev/a1_textrain/data/TextRainInput2.mov b/dev/a1_textrain/data/TextRainInput2.mov Binary files differnew file mode 100644 index 0000000..d8fce10 --- /dev/null +++ b/dev/a1_textrain/data/TextRainInput2.mov diff --git a/dev/a1_textrain/data/TextRainInput3.mov b/dev/a1_textrain/data/TextRainInput3.mov Binary files differnew file mode 100644 index 0000000..c1e6386 --- /dev/null +++ b/dev/a1_textrain/data/TextRainInput3.mov diff --git a/dev/a1_textrain/data/TextRainInput4.mov b/dev/a1_textrain/data/TextRainInput4.mov Binary files differnew file mode 100644 index 0000000..9dff13b --- /dev/null +++ b/dev/a1_textrain/data/TextRainInput4.mov diff --git a/include/README.md b/include/README.md new file mode 100644 index 0000000..431edf3 --- /dev/null +++ b/include/README.md @@ -0,0 +1,3 @@ +This directory is only for installing header files. +Nothing other than this README file should be committed to git. +The .gitignore file in the root directory is setup to ignore everything in this directory except for the README file. diff --git a/lib/README.md b/lib/README.md new file mode 100644 index 0000000..7ce7a2a --- /dev/null +++ b/lib/README.md @@ -0,0 +1,3 @@ +This directory is only for installing library files. +Nothing other than this README file should be committed to git. +The .gitignore file in the root directory is setup to ignore everything in this directory except for the README file. diff --git a/share/README.md b/share/README.md new file mode 100644 index 0000000..a27e2de --- /dev/null +++ b/share/README.md @@ -0,0 +1,3 @@ +This directory is only for installing shared data and config files. +Nothing other than this README file should be committed to git. +The .gitignore file in the root directory is setup to ignore everything in this directory except for the README file. diff --git a/worksheets/README.md b/worksheets/README.md new file mode 100644 index 0000000..d56eece --- /dev/null +++ b/worksheets/README.md @@ -0,0 +1 @@ +This directory is for "markdown" (.md) files that you will edit for the worksheet portion of each assignment. diff --git a/worksheets/a1_textrain.md b/worksheets/a1_textrain.md new file mode 100644 index 0000000..b588d1c --- /dev/null +++ b/worksheets/a1_textrain.md @@ -0,0 +1,68 @@ +# Assignment 1 (Text Rain) Worksheet + +For the conceptual worksheets in this course, we'll provide a Markdown +template from the shared-upstream repository. As described in the Canvas +assignment handouts, you'll pull each Markdown template into your repository, +directly edit your local copy with your answers, and commit and push your +answers to GitHub in your `worksheets` folder of your repository. If you're +unfamiliar with Markdown syntax, [check out this lovely guide provided by +GitHub](https://guides.github.com/features/mastering-markdown/) before you get +started. + +_Do not make a copy of the provided Markdown template and submit that instead._ +Our grading scripts will be looking for these modified files within your +`worksheets` folder of your repository. Do not change the filenames, simply +modify the contents. + +## Background + +By default, Processing uses the integer-based `0-255` convention to represent +colors. For instance, bright, full-saturation red is represented as +`color(255, 0, 0)`. Processing also supports grayscale colors; black is +`color(0)` and white is `color(255)`. You may wish to look at the [color class +documentation](https://processing.org/reference/color_.html) and/or the +[tutorial explaining color in +Processing](https://processing.org/tutorials/color/). + + +## Q1: Indexing + +As mentioned in the assignment handout, accessing/setting pixel data via +Processing's `get()` and `set()` routines is a bit easier to code, but it's +much slower than directly accessing/changing a [PImage +object's](https://processing.org/reference/PImage.html) `pixels[]` array. +Processing stores a 2D image in this 1D array, so getting the proper pixel out +requires a little additional math. + +In the code block below, write the equation for obtaining the index in the 1D +array from a (row, column) in the 2D pixels array. Keep in mind you can use +information from `inputImg` to help you. + +``` +PImage inputImg = loadImage("test.jpg"); + +int index1D = /* --- Fill this in --- */; +``` + + +## Q2: Thresholding + +The image processing technique known as *thresholding* will be useful while +creating your Text Rain. During the thresholding operation, if a pixel's +grayscale value is less than `threshold`, then it becomes black. If the +value is greater than `threshold`, it becomes white. You can use the green +channel of the color as the grayscale value. + +In the code block below, write a Java code snippet for thresholding one pixel +(`inputPixel`) to black or white. + +```java +final int threshold = 128; + +// Returns: thresholded color (black or white) +color thresholdPixel(color inputPixel) { + + /* --- Fill this in --- */ + +} +``` |