From: Daniel Moore Date: 2009-02-07T01:59:33+09:00 Subject: [QUIZ] Mathematical Image Generator (#191) -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- The three rules of Ruby Quiz: 1. Please do not post any solutions or spoiler discussion for this quiz until 48 hours have elapsed from the time this message was sent. 2. Support Ruby Quiz by submitting ideas and responses as often as you can! Visit: 3. Enjoy! Suggestion: A [QUIZ] in the subject of emails about the problem helps everyone on Ruby Talk follow the discussion. Please reply to the original quiz message, if you can. -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- ## Mathematical Image Generator (#191) This week's quiz is about the generation of images based on mathematical functions. The red, green, and blue values at each point in the image will each be determined by a separate function based on the coordinates at that position. Here are some functions to get started: Math.sin(Math::PI * ?) Math.cos(Math::PI * ?) (? + ?)/2 ? * ? (?) ** 3 The question marks represent the parameters to the functions (x, y, or another function). The x and y values range between 0 and 1: the proportion of the current position to the total width or height. Feel free to add your own functions, but keep in mind that they work best when the inputs and output are between -1 and 1. Example Output: http://strd6.com/?attachment_id=145 depth: 3 red: Math.sin(Math::PI * Math.cos(Math::PI * y * x)) green: Math.sin(Math::PI * (Math.sin(Math::PI * y)) ** 3) blue: (Math.cos(Math::PI * Math.cos(Math::PI * y))) ** 3 The depth is how many layers of functions to combine. The bottom layer is always x or y. Depth 3 is where things begin to get a little bit interesting, but 5 and higher is much more exciting. Performance can be an issue with so many computations per pixel, therefore the solution that performs quickest on a 1600x1200 image with depth of 7 will be the winner of this quiz! Good luck! -- -Daniel http://rubyquiz.strd6.com