Skip to content

Instantly share code, notes, and snippets.

@ejfox
Created February 10, 2021 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ejfox/a081d4b59064a31e16ff9bf17d3531a6 to your computer and use it in GitHub Desktop.
Save ejfox/a081d4b59064a31e16ff9bf17d3531a6 to your computer and use it in GitHub Desktop.
Doomscroller Processing Script
PImage img; // Declare a variable of type PImage
float yScroll = 0;
// float scrollAmt = 50;
float threshold = 127;
PImage destination;
int lines = 1;
int scrollStart = 768;
float scrollScreens;
int revealAmt;
String[] sources = {
"www.apnews.com",
"www.npr.org",
"nypost.com",
"www.cnn.com",
"www.nydailynews.com",
"mobile.reuters.com",
"www.nbcnews.com",
"www.washingtonpost.com",
"www.wsj.com",
"www.breitbart.com",
"www.theblaze.com",
"dailycaller.com",
"drudgereport.com",
"www.msnbc.com",
"www.foxnews.com",
"www.nytimes.com",
"news.vice.com",
"www.latimes.com",
"m.huffpost.com",
"abcnews.go.com",
"www.cbsnews.com",
"newrepublic.com",
"www.motherjones.com",
"www.slate.com",
"talkingpointsmemo.com",
"www.redstate.com",
"www.nationalreview.com"
};
void setup() {
size(1024, 768, P3D);
initImg();
destination = createImage(1024, 5000, RGB);
}
void initImg () {
int rand = (int)random(sources.length);
lines = 1;
String source = sources[rand];
// String today = "2021-01-8";
String today = year() + "-" + nf(month(), 2) + "-" + day();
print("\n today:" + today);
String imgPath = "../../newsdivide/day/" + today + "/" + source + ".jpg";
yScroll = 0;
revealAmt = (int)random(25);
scrollScreens = (int)random(3);
scrollScreens = scrollScreens + 0.25;
// Make a new instance of a PImage by loading an image file
img = loadImage(imgPath);
}
void draw() {
int scrollAmt = (int)random(50) + 5;
int rndX = (int)random(img.width);
int rndY = (int)random(img.height);
//print("\n scrollScreens" + scrollScreens);
//print("\n lines" + lines);
//print("\n " + img.height);
if (lines > scrollStart) {
yScroll = yScroll - scrollAmt;
}
// background(0);
// Draw the image to the screen at coordinate (0,0)
//image(img,0,yScroll);
// print(lines);
for (int x = 0; x < img.width; x++) {
for (int y = 0; y < img.height; y++ ) {
int loc = x + y*img.width;
if (y > lines && (lines < scrollStart)) {
//destination.pixels[loc] = color(255, 0, 0);
} else {
if (brightness(img.pixels[loc]) > threshold) {
//destination.pixels[loc] = color(255);
float bt = brightness(img.pixels[loc]);
destination.pixels[loc] = color(bt);
} else {
destination.pixels[loc] = color(0);
}
}
}
}
destination.updatePixels();
image(destination, 0, yScroll);
fill(0);
//text(day()+"/"+month()+"/"+year()+" - "+hour()+":"+minute()+":"+second(),width/2,height/2);
//image(destination, 0, 0);
if (lines < img.height) {
lines = lines+revealAmt;
}
if ( (yScroll < -(768*scrollScreens))) {
initImg();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment