Wednesday, 29 June 2011

Video Transparency hack part II




/**
* hacked background subtraction and transparency effect in live video - needs refining!!
* E.DARE 2011
*/

import processing.video.*;
PImage star;
Capture cam;

void setup() {
size(320, 240);

cam = new Capture(this, 320, 240);
star =loadImage("back.jpg");

}


void draw() {
image(star, 0, 0, cam.width, cam.height);
if (cam.available() == true) {
cam.read();
cam.loadPixels();
color cc =color(255, 0); //

for (int x = 0; x < cam.width; x++) {
for (int y = 0; y < cam.height; y++ ) {
int loc = x + y*cam.width;
if (brightness(cam.pixels[loc])>=120) { //set your threshold here
cam.pixels[loc] = cc;//
}
}
}


}
cam.format = ARGB;
cam.updatePixels();
image(cam, 0, 0);
}

Remove background and make it transparent

/*
removes a black background from the vase picture and replaces it with translucent pixels, so the image behind the vase is revealed
*/
PImage img, img3, destination;


void setup() {
size(300, 300);
img = loadImage("vase.jpg");
destination = createImage(img.width, img.height, RGB);


img3 = loadImage("star.jpg");
}

float threshold = 12;
void draw() {
//noLoop();
background(255);

img.loadPixels();
destination.loadPixels();
color cc =color(255, 255, 255, 0); //with transluscent alpha channel
//could just write 255, 0
color cc2 =color(0, 0, 255);

for (int x = 0; x < img.width; x++) {
for (int y = 0; y < img.height; y++ ) {
int loc = x + y*img.width;

if (brightness(img.pixels[loc])>=threshold) {
destination.pixels[loc] = img.pixels[loc];// the vase , could be a color fill too i.e =cc2;
}
else if(brightness(img.pixels[loc])<=threshold) {

destination.pixels[loc] = cc;
}
}
}
destination.format = ARGB; //this is the crucial line
destination.updatePixels();


image(img3, -20, -20);
image(destination,0,0);
}

Tuesday, 28 June 2011

Creativity and Cognition artwork accepted for Atlanta conference

Creativity and Cognition

Had my artwork proposal (the Lost Memories project) accepted to be exhibited/performed at the Atlanta conference, Creativity and Cognition 2011:

The 8th ACM Conference on Creativity and Cognition will be held from November 3rd through November 6th at Georgia Institute of Technology in Atlanta, Georgia, USA. Starting in 1993, the Creativity & Cognition (C&C) conference series have evolved into lively interdisciplinary meetings, bringing together artists and scientists, designers and educators, researchers and practitioners.

The theme of Creativity and Cognition 2011 is Creativity and Technology. We seek to understand human creativity in its many manifestations, to design new interactive techniques and tools to augment and amplify human creativity, and to use computational media technologies to explore new creative processes and artifacts in all human endeavors ranging from the arts to science, from design to education.

Saturday, 25 June 2011

The I Ching in 8 Bytes: 00000010010001010100001101001100101101100011101011 10011110111111


I really like the idea of this circular sequence as the whole of the I Ching, a 64 bit number which I stumbled upon tonight while looking for visual mappings of the hexagrams to binary numbers.
http://www.onlineclarity.co.uk/friends/showthread.php?t=5212
So from left ro right, 000000 is the hexagram kūn, Earth, the receptive:
_ _
_ _
_ _






image from http://proporzionedivina.blogspot.com/2009/06/i-ching-as-binary-system.html


00000010010001010100001101001100101101100011101011 10011110111111
6*64 = 384 lines to represent the entire realm of change...

Nice data visualisation


http://www.webdesignerdepot.com/2009/06/50-great-examples-of-data-visualization/

Friday, 24 June 2011

Simple visual version of Bubble Sort


Simple visual version of Bubble Sort, adapted from previous code
<----void draw() {


// If the mouse is pressed sort the array
if (mousePressed == true) {
bubbleSort(myArray);
for(int i=0;i fill(myArray[i]*20, myArray[i]*25, myArray[i]*5, myArray[i]*20);
ellipse(50, +i*25, myArray[i]*2, myArray[i]*2);
print(" " + myArray[i]);
}
}
}
------>

Bubble Sort algorithm




Nice bubble sort example from Kevin, I've made a simpler version below
/*
demonstrates a bubble sort algorithm, a variety of 'comparison sort'.
involves repeatedly stepping through the list to be sorted, comparing each pair of adjacent
items and swapping them if they are in the wrong order. The pass through the list is
repeated until no swaps are needed, which indicates that the list is sorted.
The algorithm gets its name from the way smaller elements "bubble" to the top of the list
adapted from Kevin:
http://processing.org/discourse/yabb/YaBB.cgi?board=Programs;action=display;num=1059766998


**/

//NASTY BLOG DOESNT WANT TO DISPLAY CODE PROPERLY

void bubbleSort(int array[])
{
int i, j;
boolean sorted = false;

// while the array isn't sorted
while (!sorted) {
sorted = true;
// loop through array
for (i=0;i array[i+1]) {
// swap values
j = array[i];
array[i] = array[i+1];
array[i+1] = j;
//println(array);
// trigger's been hit, array isn't sorted.
sorted = false;
}
}
}
}






Thursday, 23 June 2011

Factorials: 5 ! = 5 * 4 *3 *2 * 1 = 120 \

5 ! = 5  \times  4  \times  3  \times  2  \times  1 = 120  \
(! means factorial) The factorial function (symbol: !) means to multiply a series of descending natural numbers. Can be used to find permutations and combinations, especially of large numbers
Here first 20 factorials:

void setup() {

for(int i=0;i<20;i++) {
long N = i;
println(i+ " :" +factorial(N));
}
}

long factorial(long n) {
if (n < 0) throw new RuntimeException("Underflow error in factorial");
else if (n > 20) throw new RuntimeException("Overflow error in factorial");
else if (n == 0) return 1;
else return n * factorial(n-1);
}





//Processing variation adapted from http://introcs.cs.princeton.edu/java/23recursion/Factorial.java.html



Output from code:

0 :1
1 :1
2 :2
3 :6
4 :24
5 :120
6 :720
7 :5040
8 :40320
9 :362880
10 :3628800
11 :39916800
12 :479001600
13 :6227020800
14 :87178291200
15 :1307674368000
16 :20922789888000
17 :355687428096000
18 :6402373705728000
19 :121645100408832000

Wednesday, 22 June 2011

Find prime numbers/prime factors

simple algorithm to find prime numbers and prime factors
depending on the value of N

void setup() {
long N =463;
for (long i = 2 ; i <= N ; i++) {
while (N % i == 0) {
System.out.println(i);
N = N/i;
}
}
}

Heron of Alexandria/Babylonian Algorithm to find square roots

imperative programming :
'imperative programs define sequences of commands for the computer to perform.'

Heron of Alexandria/Babylonian Algorithm to find the square root of a number, 3 versions here:

/*
1. Start with an initial guess (g) of what the square root of some number
(call it n) might be. The initial guess doesn't even have to be close. For simplicity's sake, let's always choose g = 1.
2. Compute result = ((n/g) + g)/2. Let g be the result just computed.
3. Repeat step 2 until the last two results obtained are the same.
sucessive approximation? Adapted from some C++ code I found on the web
*/

void setup() {
}
void draw() {

//doesn't really need to be in draw()

heronSqrt(44);
}

double heronSqrt(int number) {

double x = number/2;
for (int i = 0; i< 10; i++) {
x = (x + number/x)*0.5; //0.5
println("next approximate: " +x);
}
println("Processing guess: " + sqrt(number));
return x;
}
}

////another 2 variants:

//heron 2
void setup() {
heronTwo(44);
println(" ");
println(heron3(44));
}


double heronTwo(int n) {


double guess = n/2;
double r = 0.00;
for(int i = 0; i < 10; i++)
{
r = n / guess;
guess = (guess + r) / 2;
System.out.println(guess);
}

System.out.println("The square root of "+n+" is:");
System.out.printf(" [ %4.2f ]", r);//printf = formatted according to flags

return r;
}


double heron3(double number)

{ //square root Babylonian method



double estimate=number;

double divisor=2;

//below 100 is arbitrary, for very small decimals i values must be large

for(int i=0; i<100; i++)

{

estimate=number/divisor;

estimate=(estimate+divisor)/2; //find average estimate & divisor

divisor=estimate;
}

return estimate;
}

LCM and HCF algorithms

/*work out the Highest Common Factor, i.e the largest number that can
fit into the two numbers
and the lowest common multiple
i.e the smallest whole number which is a multiple of the two numbers
i.e 12 and 15
*/


/*the two numbers I'm working out LCM and HCF for */
long a =12;
long b =15;

long d=2;
long s=1;
void setup() {


while(a>=d && b>=d)
{
if((a%d==0) && (b%d==0)) {

s=s*d;
a=a/d;
b=b/d;
}
else
{
d++;
}
}
println("HCF = " + s);
println("LCM= " + s*a*b);
}


void draw() {
//do nothing here
}

Great Writing Conference

Took part in the Great Writing Conference this weekend at Imperial College, heard some interesting papers and presented my own garbled version of a paper, but left wondering what the point of it was.

Thursday, 2 June 2011

Dreamt I was in a crashing plane




The last few weeks I've been discussing lucid dreaming with a number of different people, several of whom have said you should try to read a book or look at your hands to see if you can recogonise patterns etc while dreaming, since those conversations I've had two more lucid dreams in which I've remembered to find something to read and to look at my hands, then turn them over and try to remember the lines on them. Last night I dreamt I was in a plane that was crashing, as it was about to hit a bridge I thought, 'this is really going to hurt' then I realised it was a dream and said to myself 'it cant hurt' and just went straight through the concrete and out the other side. I looked at my hands to remember the patterns on them, I'd done that before, but they were blue, this time they were my normal hands and I could remember the patterns, I found a boy reading a book and I looked at the title, it was a book on Coffee...I woke up and it was morning...the most lucid dream I've had so far.

Wednesday, 1 June 2011

Derek Jarman's Wittgenstein

http://www.youtube.com/watch?v=6WzqyO-wIMI
Found Derek Jarman's Wittgenstein on the web, I'm framing the Buddha box/Zen garden as an investigation into the limits of symbolic logic, carefully (and slowly!) reading the The Tractatus Logico-Philosophicus ("Logical-Philosophical Treatise"). Section 4 is the tricky one:

4.1 Propositions represent the existence and non-existence of states of affairs.
4.11 The totality of true propositions is the whole of natural science (or the whole corpus of the natural sciences).
4.111 Philosophy is not one of the natural sciences. (The word "philosophy" must mean something whose place is above or below the natural sciences, not beside them.)
4.112 Philosophy aims at the logical clarification of thoughts. Philosophy is not a body of doctrine but an activity. A philosophical work consists essentially of elucidations. Philosophy does not result in "philosophical propositions", but rather in the clarification of propositions. Without philosophy thoughts are, as it were, cloudy and indistinct: its task is to make them clear and to give them sharp boundaries.
4.113 Philosophy sets limits to the much disputed sphere of natural science.
4.114 It must set limits to what can be thought; and, in doing so, to what cannot be thought. It must set limits to what cannot be thought by working outwards through what can be thought.
4.115 It will signify what cannot be said, by presenting clearly what can be said.

With the Buddha Box you can never see directly in it, only via a camera, and then only when Brainwave states are those synonymous with 'higher consciousness'.

http://ijb.cgpublisher.com/product/pub.27/prod.388

hooray!