Recently I've been looking at Povray, pyprocessing, and cfdg (version 3.0) as tools for creating digital images. I have branched two separate blogs where I mainly explore jruby + processing and processing.py

Monday, 4 July 2011

Negative modulus in python, ruby and java

Java whipped hands down by both ruby and python!!
Java just returns rubbish (see footnote below applet), whereas ruby and python return a value you can use!!!!
If we are talking geometry for example, and we have a negative angle, what we want is the complement of 360, and that's what we get with ruby and python. In java we need some sort of kludge like:-


while(delta < 0){
delta += 360;
}



I came across this when experimenting with sine/cosine lookup tables for my LSystems library for processing.
Here is the example which demonstrates the lookup tables in action, with my LSystems library, a pity I can't get the finish as sexy as my PovRAY rendered Rod Hilbert in previous posts press '+' to increase depth '-' to decrease depth:-



Footnote it was interesting to read this article concerning the implementation of modulo (for negative values) in many computer languages (ie crap in most cases!!), and some spreadsheets.

No comments:

Post a Comment

Followers

Blog Archive

About Me

My photo
Pembrokeshire, United Kingdom
I have developed JRubyArt and propane new versions of ruby-processing for JRuby-9.1.5.0 and processing-3.2.2