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)
   invert modulo
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: invert modulo  (Read 254 times)
st33d

WWW Email
invert modulo
« on: Sep 21st, 2004, 6:55pm »

Modulo is wonderful and thanks for putting it into processing. I'm unaware though of an inverted form of modulo that exists as a function in Processing. I sat down and used my limited brain power to cobble together a solution.
 
Code:

//example of modulo in reference section
float a = 0.0;  
void loop() {  
  background(204);  
  a = (a + 0.5)%width;  
  line(a, 0, a, height);  
}
 
//inverted example of code
float a = 0.0;  
void loop() {  
  background(204);
  a = width - a;  
  a = (a + 0.5)%width;  
  a = width - a;
  line(a, 0, a, height);  
}

 
Which solves how to get modulo to work with constantly decrementing as opposed to incrementing. But it's just a teeny tad messy. Does a function in Processing that does a minus modulo exist, or do I write this function myself?
« Last Edit: Sep 21st, 2004, 6:56pm by st33d »  

I could murder a pint.
JohnG

WWW
Re: invert modulo
« Reply #1 on: Sep 24th, 2004, 4:36pm »

inverse modulo isn't really a possible generic function, since modulo isn't quite as limited as it's used in the example.
 
100%5 == 0
95%5 == 0
...
5%5 == 0
 
so what is the inverse modulo of 0?
 
st33d

WWW Email
Re: invert modulo
« Reply #2 on: Sep 27th, 2004, 10:28pm »

Code:

int ind = 0;
int rad = 1000;
float nTh;  
void loop() {  
  background(255);  
  if (mousePressed){traject();}
  line(50,50,50+(50*(cos(nTh))),50+(50*(sin(nTh))));
}  
 
int wrap (int valu, int limi){
int car=valu;
if (car>limi){ car=(car)%limi; }
if (car<0){
car=limi-car;
car=(car)%limi;
car=limi-car;
}
return car;
}//wrap;
 
void traject(){
if (mouseX>(width/2)){
ind=wrap(ind+1,rad);
} else {
ind=wrap(ind-1,rad);
}
nTh=(TWO_PI/rad)*ind;
}//traject;

This is what I was really after. Something to wrap the angle of a pointer that was moved clockwise or anticlockwise. Problem is, I had to put the function in all over again to account for floats elsewhere that I wanted to wrap onto the screen, sheesh! As for flipping around the modulo equation I think I probably phrased my query wrong. I would think about it but I need to sit down and get my head around a new object problem and this Bresenham stuff. Maybe later.
 

I could murder a pint.
Pages: 1 

« Previous topic | Next topic »