Thursday, November 30, 2006

Processing Week 8

Etchasketch with image

This time i use the etchasketch coding and arrow key parameters and place the image of an actual etchasketch in the background.
N.B. the file in the background "onlineetch.gif" has to be within the saved sketch folder inside another folder called data. My folder path - C:\Uni stuff\creative code\week 9 etch a sketch and drawing interface\etchsketch\data

coding -
int x = 100;
int y = 100;
PImage myimage;


void setup()
{
size(230,190);
//background(128,130,140);
myimage = loadImage("onlineetch.gif");
image(myimage,0,0);

}



void draw()
{
stroke(0);
point(x,y);

}

void keyPressed() {
if (keyCode == LEFT) {
x = x - 1;
}
if (keyCode == RIGHT) {
x = x + 1;
}
if (keyCode == UP) {
y = y - 1;
}
if (keyCode == DOWN) {
y = y + 1;
}

}



Etchasketch attempt 1



trying to impersonate an etch a sketch using mouse key commands

coding -
void setup()
{
size(500,500);
background(150,150,150);
}

int x = 200;
int y = 250;

void draw() {
fill(0);
rect(x,y,3,3);

//point(x,y);
}

void keyPressed() {
if (keyCode == LEFT) {
x = x - 5;
}
if (keyCode == RIGHT) {
x = x + 5;
}
if (keyCode == UP) {
y = y - 5;
}
if (keyCode == DOWN) {
y = y + 5;
}

}





If Line Statement -




This is a funky feature i found when using simple void draw along with an if statement affected by the the up,down,left and right arrow keys.
coding is -

void setup()
{
size(500,500);
background(255,0,0);

}
// Click on the image to give it focus,
// and then press any key
int x = 250;

int y = 250;

void draw() {
line(250,250,x,y);
}

void keyPressed() {
if (keyCode == LEFT) {
x = x - 10;
}
if (keyCode == RIGHT) {
x = x + 10;
}
if (keyCode == UP) {
y = y - 10;
}
if (keyCode == DOWN) {
y = y + 10;
}

}

No comments: