loading...

Patterns



include Math

W=1920
H=1080

def svin(x) return sin(x)*0.5+0.5 end

puts "P3\n#{W} #{H}\n255"

scale=[W,H].min*0.5

(0...H).each { |py|
    s=""
    (0...W).each { |px|
  
        x = (px-W/2) / scale
        y = (py-H/2) / scale
  
        ra = x*x + y*y
        a  = atan2(y,x)
        r  = svin( (ra + svin(a*25) ) * 23 ) * 255
        g  = svin( (ra + svin(a*26) ) * 22 ) * 255
        b  = svin( (ra + svin(a*27) ) * 21 ) * 255
  
        s += "#{r.to_i} #{g.to_i} #{b.to_i} "
    }
    puts s
}