Re: creating status sounds in python

Edit: I've left my original explanation below, but it came to my attention that I may have misunderstood a comment of yours to mean that you're expecting it to return two values.  If this is not the case, you can stop--it returns the remainder.  Nevertheless, the below provides a good deal of examples and such that might make it clearer, all be it the explanation may be too basic for some.  I do discuss how it can be defined on decimals, though, which is something most people don't know.
% is technically modulus.  The English formula 2%3 is technically read 2 mod 3, and the definition is a bit more complicated (except in C/C++ where % really is remainder--the first thing I had to do was write my own using the bigger definition).  Since we're only talking about positive numbers, we don't need the complicated clock analogies and the following will do nicely:
2%3=2 because  3 goes into 2 0 times with 2 left over.
1 3%5 is 3because 5 goes into 13 twice with 3 left over.
x/y says "how many times does y go into x".  x%y says "if I put y into x however many times it goes in, what's left?"  You could write, though I'm not sure how much it helps in understanding:
x%y == x-int(x/y)*y
If we're talking about ints, then x/y throws out the remainder.  x%y throws out the x/y part, keeping only the remainder.  I'd suggest trying some examples in the Python repl to understand it.
As for the definition on floats, if we say 3.5%2, we're asking for the remainder of dividing 2 into 3.5.  Clearly, 2 goes into 3.5 once, so we say 3.5-1*2, which gives us 1.5.  Since it's defined on floats, we can do 0.75%1--1 goes into 0.75 0 times, with a remainder of 0.75, so the result is 0.75.
The following Python lines may prove illuminating:

[i%5 for i in xrange(15)]
[(float(i)/3)%1 for i in xrange(9)]

The last is the sawtooth wave taken every 1/3rd of a second at frequency 1 hz (we don't have to write *1).
And here's a more algorithmic but 20 times less efficient approach that might be clearer for those who don't get algebra:

def remainder(x, y):
 while(x > y):
  x-=y
 return x

Hopefully this clears it up.



_______________________________________________
Audiogames-reflector mailing list
Audiogames-reflector@sabahattin-gucukoglu.com
https://sabahattin-gucukoglu.com/cgi-bin/mailman/listinfo/audiogames-reflector
  • ... AudioGames . net Forum — Development room : frastlin via Audiogames-reflector
  • ... AudioGames . net Forum — Development room : frastlin via Audiogames-reflector
  • ... AudioGames . net Forum — Development room : frastlin via Audiogames-reflector
  • ... AudioGames . net Forum — Development room : camlorn via Audiogames-reflector
  • ... AudioGames . net Forum — Development room : frastlin via Audiogames-reflector
  • ... AudioGames . net Forum — Development room : camlorn via Audiogames-reflector
  • ... AudioGames . net Forum — Development room : camlorn via Audiogames-reflector
  • ... AudioGames . net Forum — Development room : frastlin via Audiogames-reflector
  • ... AudioGames . net Forum — Development room : CAE_Jones via Audiogames-reflector
  • ... AudioGames . net Forum — Development room : camlorn via Audiogames-reflector
  • ... AudioGames . net Forum — Development room : camlorn via Audiogames-reflector
  • ... AudioGames . net Forum — Development room : camlorn via Audiogames-reflector
  • ... AudioGames . net Forum — Development room : SoundMUD via Audiogames-reflector
  • ... AudioGames . net Forum — Development room : frastlin via Audiogames-reflector
  • ... AudioGames . net Forum — Development room : SoundMUD via Audiogames-reflector
  • ... AudioGames . net Forum — Development room : frastlin via Audiogames-reflector
  • ... AudioGames . net Forum — Development room : camlorn via Audiogames-reflector
  • ... AudioGames . net Forum — Development room : frastlin via Audiogames-reflector
  • ... AudioGames . net Forum — Development room : CAE_Jones via Audiogames-reflector
  • ... AudioGames . net Forum — Development room : CAE_Jones via Audiogames-reflector
  • ... AudioGames . net Forum — Development room : CAE_Jones via Audiogames-reflector

Reply via email to