Locust movement 7

November 6, 2013 § Leave a comment

Starting to work in my background for the movement of the locusts and experimenting with the size of the locusts too.  Now I have the capability to use a background, i will soon be making many variations of layout and of typography. 

Locust Movement 6

November 5, 2013 § Leave a comment

After speaking with my coding lecture Spencer, he has really helped me with the offset of the locusts. He has also shown me an easier way of changing the code for additional images. Rather than using the “box” analogy but using a “filling cabinet”. With this new method i can easily change the amount of locusts I want, and also adjust the offset.  The new version of the code also doesn’t just load the image once, it selects randomly from the range of images you have ( in this case 3) until it has loaded 30 images.

The below videos are with 30 and 60 locusts.

int offset=350;
PImage[] locusts;
float [] x;
float[] y;
int locustnum=60;

float h,v;

void setup(){
size(640,360);
imageMode(CENTER);
locusts=new PImage[locustnum];
x=new float[locustnum];
y=new float[locustnum];
for(int lop=0;lop<locustnum;lop=lop+1){
locusts[lop]=loadImage(“locust”+int(random(1,4))+”.png”);
h=locusts[lop].width/2;
v=locusts[lop].height/2;
x[lop] =( width / 2)+random(offset)-random(offset);
y[lop] = (height / 2)+random(offset)-random(offset);
}

}

void draw(){
background(255);
for(int lop=0;lop<locustnum;lop=lop+1){

if (abs(mouseX – x[lop]) < h &&
abs(mouseY -y[lop]) < v) {
x[lop] += random(-10, 10);
y[lop] += random(-10, 10);

}
image(locusts[lop],x[lop],y[lop]);

}

}

Locust movement 4

November 5, 2013 § Leave a comment

Slowly making progress in making the coding into what i want it to be like. After restructuring the code i manged to implement a second locust. With a more tidy format of code i can more easily put more images.

Here is the version with 6 locusts in.  My next step from here is to re-photograph my locusts so i can code them so they are all unique.

Here is a tidier version of my code.  I have highlighted the lines of code for one individual locust, which has to be copied for all additional locust, but with the values changed.

PImage locust1;
PImage locust2;
PImage locust3;
float x1;
float y1;
// X1 AND Y1 FOR LOCUST1
float x2;
float y2; // X2 AND Y2 FOR LOCUST2
float x3;
float y3; // X3 AND Y3 FOR LOCUST3
float hr, vr; // Size of images (94×44)

void setup() {
size (640,360);
background(255);

imageMode(CENTER);
locust1=loadImage(“locust1.png”);
locust2=loadImage(“locust2.png”);
locust3=loadImage(“locust3.png”);

hr =94 / 2;
vr = 44 / 2;
noStroke();
x1 = width / 2;
y1 = height / 2;

x2 = width / 2;
y2 = height / 2;

x3 = width / 2;
y3 = height / 2;

}

void draw() {
// Instead of clearing the background, fade it by drawing
// a semi-transparent rectangle on top
fill(255, 255);
rect(0, 0, width, height);

// If the cursor is over the text, change the position
if (abs(mouseX – x1) < hr &&
abs(mouseY – y1) < vr) {
x1 += random(-10, 10);
y1 += random(-10, 10);

}
if (abs(mouseX – x2) < hr &&
abs(mouseY – y2) < vr) {
x2 += random(-10, 10);
y2 += random(-10, 10);
}
if (abs(mouseX – x3) < hr &&
abs(mouseY – y3) < vr) {
x3 += random(-10, 10);
y3 += random(-10, 10);

}
fill(0);
image(locust1,x1,y1);
image(locust2,x2,y2);
image(locust3,x3,y3);
}

Moving Locust 5

November 5, 2013 § Leave a comment

Now i have a workable piece of code, that i can change and mold to what i want to work with i have deiced to reflect on what i have created and what i would like to achieve further from it.

What I would know like to achieve next are

  • Have an offset of the locusts so they all dont just load in the middle
  • Create the coding with 30 separate images
  • Make it easier to input new images
  • Create a Informational background on my collection

Locust Movement 3

November 4, 2013 § Leave a comment

Slowly been making progression with the coding. I do feel like I am hitting many roadblocks on the way, by my limited knowledge on coding.

I manged to fix the code so the image moves how i wanted.

PImage back;
float xpos;
float ypos;
float xvel = 2;
float yvel = 1;
int imwidth;
int imheight;
float hr, vr;

void setup() {
imageMode(CENTER);
size (1280,720);
back=loadImage(“locust.png”);
xpos=width/2;
ypos=height/2;
imwidth=back.width;
imheight=back.height;
image(back,xpos, ypos);
}

void draw() {
float x,y;

x=mouseX;
y=mouseY;

if(abs(x-xpos)>xvel) {

if (x>xpos) {
xpos+=xvel;
}
else
{
xpos-=xvel;
}
}
if(abs(y-ypos)>yvel) {
if (y>ypos) {
ypos+=yvel;
}
else
{
ypos-=yvel;
}

image(back, x += random(-5, 5),x += random(-5, 5));
}
}

]

Locust movement 2

November 4, 2013 § Leave a comment

Finally (after many coffees, shouting at the screen and tears) i managed to make the coding to work (ish) for an image.

The problem with this is it seems to only repel diagonally away from the mouse on one line.

Locust Movement

November 4, 2013 § Leave a comment

For my taxonomy project i am planning on using code in a way to display my locusts.

My aim for this coding is to display my locusts so when the mouse is over the top of them, they move away for the mouse.

Without any previous knowledge of coding before Spencer’s first session. I have watched various tutorials to come up with the motion away from the mouse. But with text rather than an image.

Here is my first attempt

String message = “locusts”;
float x, y;
float hr, vr;
void setup() {
size(640, 360);

textAlign(CENTER, CENTER);

hr = textWidth(message) / 2;
vr = (textAscent() + textDescent()) / 2;
noStroke();
x = width / 2;
y = height / 2;
}

void draw() {

fill(204, 120);
rect(0, 0, width, height);

if (abs(mouseX – x) < hr &&
abs(mouseY – y) < vr) {
x += random(-5, 5);
y += random(-5, 5);
}
fill(0);
text(“locust”, x, y);
}

mocust image

Unfortunately the screen grab doesn’t capture the mouse on the video below.

But when the mouse is on top on word, the word pulses away.

Starting to take pictures of my Obects

October 22, 2013 § Leave a comment

locust

Here is one of first edited pictures of my locusts.

Where Am I?

You are currently browsing entries tagged with taxonomy at sammdickinson.