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_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   setup and loop issues
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: setup and loop issues  (Read 360 times)
alison


setup and loop issues
« on: Feb 28th, 2005, 5:41pm »

hi
 
Im having problems with this code, what I would like to happen is for the points drawn, to draw one at a time on the stage.  
 
The code as it stands draws eveything in one go understandably cuz it waits for the for loop to finish.
 
Ive attempted all sorts of things, but it seems to me that rather than having a huge for loop I should drop the code into a "void loop()".  Then I can also use the delay function to draw the dots at any speed I want.  
 
But obviously I have huge issues with accessing variables made inside setups and loops, and I just cant get it to work... heres the working code (without my poor attempts to draw stuff one at a time)
 
code:
 
size (850,750);
background(252,255,255);  
 
String intarr [] = loadStrings("UT2004.log");
int len = intarr.length;
String justnum [] = new String [len];
 
 
for (int i=len; --i >=0;) {
  String temp[] =splitStrings(intarr[i]);
  justnum[i] = temp[3];  
  }
 
String formatted = join(justnum, " ");  
 
float thelist[] = splitFloats(formatted);  
 
 
 
for (int i=0;i<len;i=i+3) {
 
int div=12;
int plu=40;
 
  float temp1 = thelist[i];
  float temp2 = thelist[i+1];
  float temp3 = thelist[i+2];
   
  temp1 = temp1+20000;
  temp1 = temp1/plu-95;
    temp2 = temp2+20000;
    temp2 = temp2/plu-40;
 temp3 = temp3+20000;
 temp3 = temp3/plu;
   
  color tempcol = color (0,0,0);
  stroke(tempcol);
  point (temp1,temp2);
 
}
 
any help would be greatly appreciated
thanks
 
fjen

WWW
Re: setup and loop issues
« Reply #1 on: Feb 28th, 2005, 8:51pm »

Quote:
huge issues with accessing variables made inside setups and loops

 
check there to get started with that ("scope"):
http://stage.itp.tsoa.nyu.edu/~dts204/ppaint/week2/index.html  
 
and here is more:  
http://processing.org/learning/examples/variable_scope.html  
 
 
as to your problem:
create a variable to hold your points-array
create a variable to hold a int-position inside the points-array
in setup {
load string and fill the points-array
set position-var to 0
}
in loop {
draw point in points-array at position position-var
increment position-var
use modulo to make sure position-var is smaller than points-array.lenth  ( pvar = pvar % points.length )
}
 
/F
 
Pages: 1 

« Previous topic | Next topic »