FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Topics & Contributions
   Simulation, Artificial Life
(Moderator: REAS)
   Vine
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Vine  (Read 508 times)
rgovostes

rgovostes
Vine
« on: Sep 5th, 2003, 8:44pm »

I wrote a little script (my 2nd so far!) which looks like a growing vine to me. Any suggestions welcome.
 
Basically a 'turtle' starts in the center of the applet and randomly moves around. Every time it enters a pixel, it adds a bit of green to it. There's a line I commented out that makes additional turtles when a pixel reaches maximum brightness, but it runs infinitely and crashes (oops).
 
In future versions I'd like to fix the additional turtles, and perhaps make the turtles go in a general directions, so when a new turtle is created it goes in the opposite direction of its creator.
 
Code:
// Vine v1 (Sep 05 '03)
// by Ryan Govostes
 
int x[] = new int[1];
int y[] = new int[1];
 
void setup() {
  size(200, 200);
  noBackground();
  colorMode(RGB, 10);
 
  fill(0, 0, 0);
  rect(0, 0, width, height);
 
  x[0] = width  / 2;
  y[0] = height / 2;
}
 
void loop() {
  int nbrTurtles = x.length;
   
  for (int i = 0; i < nbrTurtles; i ++) {
    color c = getPixel(x[i], y[i]);
    c = color(0, green(c) + 1, 0);
    setPixel(x[i], y[i], c);
     
    //if (green(c) == 10) { newTurtle(x[i], y[i]); }
    moveRandom(i);
  }
}
 
void moveRandom(int i) {
  int r = int(random(8));
  if (r == 0 || r == 3 || r == 5) { x[i] = max(x[i] - 1, 0); x[i] = min(x[i], width); }  // 012
  if (r == 2 || r == 4 || r == 7) { x[i] = max(x[i] + 1, 0); x[i] = min(x[i], width); }  // 3 4
  if (r == 0 || r == 1 || r == 2) { y[i] = max(y[i] - 1, 0); y[i] = min(y[i], height); } // 567
  if (r == 5 || r == 6 || r == 7) { y[i] = max(y[i] + 1, 0); y[i] = min(y[i], height); }
}
 
void newTurtle(int newx, int newy) {
  int tempx[] = new int[x.length + 1];
  int tempy[] = new int[y.length + 1];
  System.arraycopy(x, 0, tempx, 0, x.length);
  System.arraycopy(y, 0, tempy, 0, y.length);
   
  tempx[x.length] = newx;
  tempy[y.length] = newy;
  x = tempx;
  y = tempy;
   
  print("Turtle added.\n");
}
 
rgovostes

rgovostes
Re: Vine
« Reply #1 on: Sep 5th, 2003, 8:51pm »

I fixed the turtle problem by only allowing one to be generated at each pixel. The script adds one after a few seconds, but soon enough it enters the same infinite loop thing. Bah!
 
It's still pretty cool to watch the big blob form as it brings proce55ing to it's knees (or whatever it has). Just replace the first half of the code with this:
 
Code:
// Vine v1.1 (Sep 05 '03)
// by Ryan Govostes
 
int x[] = new int[1];
int y[] = new int[1];
 
void setup() {
  size(200, 200);
  noBackground();
  colorMode(RGB, 201);
 
  fill(0, 0, 0);
  rect(0, 0, width, height);
 
  x[0] = width  / 2;
  y[0] = height / 2;
}
 
void loop() {
  int nbrTurtles = x.length;
  
  for (int i = 0; i < nbrTurtles; i ++) {
    color c = getPixel(x[i], y[i]);
    if (green(c) < 180) {
      c = color(0, green(c) + 20, 0);
    } else if (green(c) < 201) {
      c = color(0, 201, 0);
      newTurtle(x[i], y[i]);
    }
    
    setPixel(x[i], y[i], c);
    moveRandom(i);
  }
}

 
You still need the newTurtle() and moveRandom() functions from the script above.
« Last Edit: Sep 5th, 2003, 8:57pm by rgovostes »  
rgovostes

rgovostes
Re: Vine
« Reply #2 on: Sep 6th, 2003, 5:48am »

I changed the code a bit and designed a webpage for it. You can see the finished product here (tada!).
 
Feedback on the applet as well as the page is appreciated.
 
flight404

WWW Email
Re: Vine
« Reply #3 on: Sep 6th, 2003, 8:42am »

I am using Safari on OSX and I get a red X where the applet should be.  
 
r
 
mKoser

WWW Email
Re: Vine
« Reply #4 on: Sep 6th, 2003, 1:10pm »

i'm (for the time being) on a crappy old win98 machine, and I get an error saying, "Class vine not found" at the bottom of my browser! (have you uploadet it?)
 
+ mikkel
 

mikkel crone koser | www.beyondthree.com | http://processing.beyondthree.com
rgovostes

rgovostes
Re: Vine
« Reply #5 on: Sep 6th, 2003, 6:28pm »

Hmm, I asked my friend to host it, and as it turns out he's running it off of the web server software that he wrote.
 
I'll post if I get it moved. Sorry bout that.
 
Update: Moved again! A friend was willing to move it here.
Update: I redesigned the page to be more simple.
 
I've had a bunch of reports from Windows IE users who say that they cannot load the "vine.class" file. I'm not sure why, as Processing does not export this file, and I copied the <applet> tag from the index.html file created by Processing.
« Last Edit: Sep 6th, 2003, 10:10pm by rgovostes »  
Pages: 1 

« Previous topic | Next topic »