summaryrefslogtreecommitdiffstats
path: root/dev/a1_textrain/a1_textrain.pde
diff options
context:
space:
mode:
authorMatt Strapp <matt@mattstrapp.net>2021-09-20 18:15:14 -0500
committerMatt Strapp <matt@mattstrapp.net>2021-09-20 18:15:14 -0500
commit342403a02f8063903d0f38327430721d4d0ae331 (patch)
tree29d020a27bc16939c568dd4b29166566d1c0e658 /dev/a1_textrain/a1_textrain.pde
parentFix parenthesis (diff)
downloadcsci4611-342403a02f8063903d0f38327430721d4d0ae331.tar
csci4611-342403a02f8063903d0f38327430721d4d0ae331.tar.gz
csci4611-342403a02f8063903d0f38327430721d4d0ae331.tar.bz2
csci4611-342403a02f8063903d0f38327430721d4d0ae331.tar.lz
csci4611-342403a02f8063903d0f38327430721d4d0ae331.tar.xz
csci4611-342403a02f8063903d0f38327430721d4d0ae331.tar.zst
csci4611-342403a02f8063903d0f38327430721d4d0ae331.zip
Diffstat (limited to 'dev/a1_textrain/a1_textrain.pde')
-rw-r--r--dev/a1_textrain/a1_textrain.pde382
1 files changed, 219 insertions, 163 deletions
diff --git a/dev/a1_textrain/a1_textrain.pde b/dev/a1_textrain/a1_textrain.pde
index 1acde87..f1b7456 100644
--- a/dev/a1_textrain/a1_textrain.pde
+++ b/dev/a1_textrain/a1_textrain.pde
@@ -1,163 +1,219 @@
-/*
- * 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.
-
- If you having trouble accessing the cameara on a mac laptop due to a security issue. Some
- students found this post helpful:
- https://github.com/processing/processing-video/issues/134#issuecomment-664778394
- */
-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-1]);
- 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;
- }
-}
+/*
+ * 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.
+
+ If you having trouble accessing the cameara on a mac laptop due to a security issue. Some
+ students found this post helpful:
+ https://github.com/processing/processing-video/issues/134#issuecomment-664778394
+ */
+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;
+int threshhold = 128;
+
+
+// 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;
+PFont f;
+
+
+// Called automatically by Processing, once when the program starts up
+void setup() {
+ size(1280, 720);
+ inputImage = createImage(width, height, RGB);
+ y = new int [width * height];
+ for (int k=0;k<y.length;k++)
+ y[k] = int(random(0,720));
+ f = createFont("Arial",16,true);
+
+ 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.");
+ }
+ }
+}
+boolean debug;
+
+int [] y;
+// Called automatically by Processing, once per frame
+void draw() {
+ // start each frame by clearing the screen
+ background(0);
+ textFont(f);
+
+ 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!
+ inputImage.filter(GRAY);
+ set(0, 0, inputImage);
+ loadPixels();
+ //Debug toggle
+ if (debug) {
+ for (int k=0; k<pixels.length;k++) {
+ if (red(pixels[k]) < threshhold) {
+ pixels[k]=color(0);
+ } else {
+ pixels[k]=color(255);
+ }
+ }
+ }
+
+ for (int i=0;i<inputImage.width-1;i++) {
+ for (int j=0;j<inputImage.height-1;j++) {
+ color swap;
+ swap=pixels[i+j*inputImage.width];
+ println(red(pixels[i+j*inputImage.width]));
+ println(red(pixels[(inputImage.width-i)+j*inputImage.width]));
+ pixels[i+j*inputImage.width]=pixels[(inputImage.width-i)+j*inputImage.width]; //<>//
+ pixels[(inputImage.width-i)+j*inputImage.width]=swap;
+ }
+ }
+ updatePixels();
+
+ int x=0;
+
+ // 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.
+ //String message = "TEXT AND THINGS AND TEXT AND THINGS";
+ String message = "Let's go for a drive / And see the town tonight / There's nothing to do / But I don't mind when I'm with you";
+
+ for(int i=0; i < message.length(); i++){
+ fill(255, 0, 0);
+
+ int rainlength = int(random(1,5));
+ x += 11;
+ y[x] = (y[x]+rainlength)%inputImage.height;
+ if (red(pixels[x+y[x]*inputImage.width]) < threshhold) {
+ y[x] = (y[x]-rainlength*2)%inputImage.height;
+ if (y[x] <= 0)
+ y[x]=1;
+ if (y[x] >= inputImage.height)
+ y[x]=inputImage.height-1;
+ }
+ text(message.charAt(i),x,y[x]);
+ }
+
+
+ }
+}
+
+
+// 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
+ threshhold+=5;
+ if (threshhold > 255)
+ threshhold=255;
+ println("New threshhold: ",threshhold);
+ }
+ else if (keyCode == DOWN) {
+ // down arrow key pressed
+ println("DOWN");
+ threshhold-=5;
+ if (threshhold < 0)
+ threshhold=5;
+ println("New threshhold: ",threshhold);
+ }
+ }
+ else if (key == ' ') {
+ // spacebar pressed
+ println("DEBUG TOGGLED");
+ debug = !debug;
+ }
+ }
+}
+
+
+
+// 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-1]);
+ 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;
+ }
+}