Wednesday 7 January 2009

Chunk16 - Add Ons

Saving Chunk16 Images


Chunk 16 sometimes produces images that I really want to keep, so I added this function that saves an image when any key is pressed:
void keyPressed() {
save("_0ch16.jpg");
}
This is an event driven function and responds to a key press. Unfortunately it often doesnt save the image being viewed but copies the next one. I generally open the applications folder and have it sitting alongside the running application, that way I can see the image that has been saved. If I dont like the image, I press a key to save the next image. The path can be edited to save the image to any folder and file you like. I have named the saved file '_0ch16.jpg' as I use it in another application that uses this format. This function only ever produces one image at a time, as I dont want to waste space and have to delete files I dont want. If you want to keep an image remove it from the folder or rename it, before saving any other images.

KaChunk
I had intended to write a kaleidoscope type program for chunk 16 but I got sidetracked, hence the name 'KaChunk'.
When you want to 'KaChunk' an image add it to the kachunk folder and name it _0ch16.jpg. When you run the program it will display and save an image consisting of four smaller copies of the reuired image. pressing any key repeats the process. The following slide show demonstrates the images produced by KaChunk.
SlideShow
Walker
The Walker applicaton allows the images produced by KaChunk to be 'walked' through using the up and down keys. When the program starts it loads the original '_0ch16.jpg' file. Because this is the 'closest' you can get to the image the up key wont work until you are viewing smaller images. Use the down key to move further away and the up key to zoom in.

Chunk16 Photo Frame
This function just centres an image at the end of the draw method.

void doImage(){
imageMode(CENTER);
image(b,centre,centre);
}

I added a date function to the photo frame which toggles the display of month, date and time on or off, and pressing the p key toggles the photo.
The key presses are a bit iffy and it can take up to 3 draws to toggle. The save image function still works too so photos can be saved with a Chunk16 frame. Press any key except p or d to save a copy of what is on the screen.
The code below has to be added to Chunk16 to allow the photo frame and date functions to work. Place a photo in the path for fName and edit the fName to use your photo.

Global Variables
boolean showDate=false;
boolean showImage=true;
String IMAGE_PATH = "C:/ch16/";
String fName=IMAGE_PATH+"pic1.jpg";
PImage b=loadImage(fName);
PFont font;
String [] months={"January","February","March","April","May","June","July","August","September","October","November","December"};
int h=b.height/2;
int w=b.width/2;

Add these statements to the setup method:
font = loadFont("AccordLightSF-30.vlw");
textFont(font, 30);

Add these statements to the end of the draw method
default:
repeatShapes(round(random(5,width/2)),'4');//draws squares
}
}
if(showImage){doImage();}
if(showDate){doCalendar();}

Add these functions:
void doImage(){
imageMode(CENTER);
image(b,centre,centre);
}
void doCalendar(){
int d = day(); // Values from 1 - 31
int m = month(); // Values from 1 - 12
int y = year(); // 2003, 2004, 2005, etc.
int sec = second(); // Values from 0 - 59
int min = minute(); // Values from 0 - 59
int h = hour(); // Values from 0 - 23

String s = String.valueOf(y);
fill(255);
rect(centre,50,200,50);
fill(0);
textFont(font, 30);
//text(s,centre-25,55);
s=months[m-1]+" "+d;
text(s,centre-75,55);
fill(255);
rect(centre,height-50,200,50);
fill(0);

s = String.valueOf(h)+":"+String.valueOf(min)+":"+String.valueOf(sec);
text(s,centre-75,height-36);
}

void keyPressed() {
if (key == 'd' || key == 'D') {showDate=!showDate;}
else if (key == 'p' || key == 'P') {showImage=!showImage;}
else{
save("_0ch16.jpg");}
}

Possibilities:
Some of the KaChunk images make really good desktop backgrounds. Vista has a very neat slideshow utility, which can be used to show the images in any folder. It has various options for displaying the images including greyscale and sepia. Sometime in the future I might make a Processing application which saves 50 images to quickly make a slideshow. There would have to be an editor which allows unwanted images to be deleted and replaced....

KaChunk Code:
/*
title: KaChunk
description: random pattern generator
created: December 16, 2008
by: Rosie Wood
*/
// define Global variable values
//These are constant variables and therefore they are not changed
//by the program. Setting their value here in one place helps with maimtenance
int sizeWindow=600;
int centre=sizeWindow/2;
int xpos = centre;
int ypos = centre;
String IMAGE_PATH = "C:/Users/Rosie/Documents/processing-1.0/myWork/kaChunk/";
PImage b;
//int patternsPerPicture=round(random(2,50));

boolean [] recs=new boolean[9];

//this variable is changed frequently by the application
int interval=30;
int count;
int images=0;
String fName="_0ch16.jpg";
// set the sketch window size and background
//turn off fill so that patterns underneath can be seen
//set the rate that the screen refreshes at (found this value was best for this application?)
void setup(){
size(sizeWindow, sizeWindow);
background(0);
stroke(204, 102, 0);//colour red
noFill();
int images=1;
b=loadImage("_0ch16.jpg");
draw();}

void draw(){
b=loadImage(fName);
//if(images==0){
//image(b,0,0);}
//else{
image(b,0,0,width/2,width/2);
image(b,width/2,0,width/2,width/2);
image(b,0,width/2,width/2,width/2);
image(b,width/2,width/2,width/2,width/2);
// }
}

void keyPressed() {
images++;
fName="_"+images+"ch16.jpg";
save(fName);
}

Walker Code:


int sizeWindow=600;
int centre=sizeWindow/2;
int xpos = centre;
int ypos = centre;
int images=256;
int count=0;
//Change this to your path!
String IMAGE_PATH = "C:/Users/USERNAME/Documents/Processing/walker/data/";
PImage b;
String fName="_0ch16.jpg";
//String []fNames=new String[13];

void setup(){
size(sizeWindow, sizeWindow,P3D);
background(0);
noFill();
//findMaxPOW();
//frameRate(.2);

b=loadImage("_0ch16.jpg");
draw();

}
void draw(){

// b=loadImage(IMAGE_PATH+"_"+images+"ch16.jpg");
image(b,0,0,width,width);
}

void keyPressed() {
if(keyCode==DOWN){
if(count<12){ count="12;}}" count="0;" fname="_" b="">




3 comments:

  1. I tried using the code to embed a slideshow of the images on the page but it just takes the user to the images folder.
    I replaced it with a link to the slide show.

    ReplyDelete
  2. My eyes must have been playing tricks with me but the first that occurred to me looking at your photo-frame was the BBC test-card. Apparently the BBC are bringing it back (presumable in widescreen format now).

    ReplyDelete
  3. Teehee, I never noticed that!
    Hope they don't sue me,,,

    ReplyDelete