require 'bizzieLibrary' require 'bizzieSDL' require 'bizzieMatrix' require 'bizzieRandom' require 'opengl' require 'glut' require 'mathn' require 'bizzieDraw' require 'bizzieTime' $pt = $origin2d $mvPt = $origin2d $centerPt = $origin2d $clickPt = $clickPt $clickDown = false $begun = false $crossHatches = [] $points = [] $changed = false $path = DiscretePath.new() $width = 600 $height = 600 $theta = 0.0 $delTheta = 10.0 $epsilon = 0.01 $epsilonDelta = 0.01 $epsilon2 = 0.5 $epsilon2Delta = 0.002 $alpha = 1.0 $alphaDel = 0.999 $counter = 3 $counterDelta = 1 $numLines = 10 $numLinesDelta = 1 $onceClear = true $clear = false $usedPath = $rainbowPath $colorScheme1 = $rainbowPath $colorScheme2 = $whiteCyanBluePath $colorScheme3 = $blackRedBlackPath $colorCounter = 1 $param = 0.7 $upLeft = Point2d.new(-1 * $param, $param) $upRight = Point2d.new($param, $param) $downRight = Point2d.new($param, -1 * $param) $downLeft = Point2d.new(-1 * $param, -1 * $param) $upLine = Line2d.new($upLeft, $upRight) $rightLine = Line2d.new($upRight, $downRight) $downLine = Line2d.new($downRight, $downLeft) $leftLine = Line2d.new($downLeft, $upLeft) $upLineX = Line2d.new($upRight, $upLeft) $downLineX = Line2d.new($downLeft, $downRight) $rightLineX = Line2d.new($downRight, $upRight) $leftLineX = Line2d.new($upLeft, $downLeft) def transformPoint(screenX, screenY) x = (screenX - ($width / 2.0)) / ($width / 2.0) y = -1 * (screenY - ($height / 2.0)) / ($height / 2.0) return Point2d.new(x, y) end def init GL.Enable(GL::LINE_SMOOTH); GL.Enable(GL::BLEND); GL.BlendFunc(GL::SRC_ALPHA, GL::ONE_MINUS_SRC_ALPHA); GL.Hint(GL::LINE_SMOOTH_HINT, GL::DONT_CARE); GL.LineWidth(0.5); GL.ClearColor(0.0, 0.0, 0.0, 0.0); end $rwX1 = RandomWalk.new(0.03, 0.0, -1.0, 1.0) $rwY1 = RandomWalk.new(0.02, 0.0, -1.0, 1.0) $rwC1 = RandomWalk.new(0.001, 0.5, 0.0, 1.0) $rwX2 = RandomWalk.new(0.03, 0.0, -1.0, 1.0) $rwY2 = RandomWalk.new(0.01, 0.0, -1.0, 1.0) $rwC2 = RandomWalk.new(0.001, 0.0, 0.0, 1.0) $rwX3 = RandomWalk.new(0.01, 0.0, -1.0, 1.0) $rwY3 = RandomWalk.new(0.02, 0.0, -1.0, 1.0) $rwC3 = RandomWalk.new(0.001, 0.0, 0.0, 1.0) $alpha = 1.0 display = Proc.new { # ----- BUSINES ----- # ----------------------- $alpha *= 0.99999 time = getTime / 1000.0 if ($onceClear) clearScreen $onceClear = false $lastTime = time elsif ($clear) clearScreen end (1..200).each do |x| setColor($usedPath.doPathPoint($rwC1.step).setAlpha($alpha)) drawLine($rwX1.value, $rwY1.value, $rwX1.step, $rwY1.step) setColor($usedPath.doPathPoint($rwC1.value).setAlpha(0.1 * square($alpha))) drawLine($rwX1.value, $rwY1.value, $rwX2.value, $rwY2.value) setColor($usedPath.doPathPoint($rwC1.value).setAlpha($alpha)) drawLine($rwX2.value, $rwY2.value, $rwX2.step, $rwY2.step) setColor($usedPath.doPathPoint($rwC1.value).setAlpha(0.1 * square($alpha))) drawLine($rwX2.value, $rwY2.value, $rwX3.value, $rwY3.value) setColor($usedPath.doPathPoint($rwC1.value).setAlpha($alpha)) drawLine($rwX3.value, $rwY3.value, $rwX3.step, $rwY3.step) end GL.Flush sleep(0.001) } reshape = Proc.new {|w, h| GL.Viewport(0, 0, w, h); GL.MatrixMode(GL::PROJECTION); GL.LoadIdentity(); if (w <= h) GLU.Ortho2D(-1.0, 1.0, -1.0*h/w, 1.0*h/w); else GLU.Ortho2D(-1.0*w/h, 1.0*w/h, -1.0, 1.0); end GL.MatrixMode(GL::MODELVIEW); GL.LoadIdentity(); $onceClear = true } def cycleColors $colorCounter += 1 if $colorCounter == 4 $colorCounter = 1 end if $colorCounter == 1 $usedPath = $colorScheme1 elsif $colorCounter == 2 $usedPath = $colorScheme2 else $usedPath = $colorScheme3 end end def randomColors $usedPath = BezierPath.new([randomColor, randomColor, randomColor, randomColor]) end def upTheta $theta += $delTheta if $theta >= 360.0 $theta %= 360.0 end $alpha = $alpha * $alphaDel GLUT.PostRedisplay end def downTheta $theta -= $delTheta if $theta < 0.0 $theta += 360.0 end $epsilon2 -= $epsilon2Delta if $epsilon2 <= 0 $epsilon2 = $epsilon2Delta end GLUT.PostRedisplay end keyboard = Proc.new {|key, x, y| case (key) when 'a'[0], 'A'[0] $rwX.init $rwY.init when 'x'[0], 'X'[0] cycleColors when 27 #/* Escape Key */ exit(0); end } GLUT.Init GLUT.InitDisplayMode(GLUT::SINGLE | GLUT::RGB) GLUT.InitWindowSize($width, $height) GLUT.CreateWindow($0) init() GLUT.ReshapeFunc(reshape) GLUT.KeyboardFunc(keyboard) GLUT.DisplayFunc(display) GLUT.IdleFunc(display) GLUT.MainLoop