require 'sdl' require 'bizzieLibrary' require 'bizzieSDL' require 'bizzieMatrix' require 'bizzieRandom' require 'opengl' require 'glut' require 'mathn' require 'bizzieDraw' require 'bizzieTime' require 'bizzieSDL' $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 $counterA = 0.0 $counterB = 0.0 $lastTime $ta = 1.0 $tb = 0.5 pic = SDL::Surface.load("testPic6.bmp") $colorMatrix = SimpleMatrix.new(pic.w, pic.h) puts "loading!" (0..pic.w - 1).each do |x| (0..pic.h - 1).each do |y| $colorMatrix.put(x, y, getColor(pic.getPixel(x,y), pic)) end end puts "loaded!" $line = Line2d.new([-0.5, -0.7], [0.5, 0.7]) $multX = (2.0 / pic.w) $multY = (2.0 / pic.h) $rwX = RandomWalk.new(0.05, 0.0, -1.0, 1.0) $rwY = RandomWalk.new(0.05, 0.0, -1.0, 1.0) display = Proc.new { # ----- BUSINES ----- # ----------------------- time = getTime / 1000.0 if ($onceClear) clearScreen $onceClear = false $lastTime = time $x1 = 0.0 $y1 = 0.0 elsif ($clear) clearScreen end deltaTime = time - $lastTime $lastTime = time $x2 = $rwX.step $y2 = $rwY.step ptA = Point2d.new($multX * $x1 - 1.0, -1 * $multY * $y1 + 1.0) ptB = Point2d.new($multX * $x2 - 1.0, -1 * $multY * $y2 + 1.0) colorX1 = max(((($x1 + 1.0) / 2.0) * pic.w).round - 1, 0) colorY1 = max((((-1 * $y1 + 1.0) / 2.0)* pic.h).round - 1, 0) colorX2 = max(((($x2 + 1.0) / 2.0) * pic.w).round - 1, 0) colorY2 = max((((-1 * $y2 + 1.0) / 2.0)* pic.h).round - 1, 0) color1 = $colorMatrix.get(colorX1, colorY1) color2 = $colorMatrix.get(colorX2, colorY2) #drawPathColor(Line2d.new(ptA, ptB), Line.new(color1, color2), 0.1) setColor(color1) drawLine($x1, $y1, $x2, $y2) # ------------------------------- # ----- END BUSINESS ----- $x1 = $x2 $y1 = $y2 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 $state = nil SDL::Mixer.open() $a = SDL::Mixer::Wave.load("testSound.wav") $b = SDL::Mixer::Wave.load("testSound2.wav") SDL::Mixer.allocateChannels(50) def actionA setColor($white) drawLine(randomPoint2d, randomPoint2d) SDL::Mixer::playChannel(-1, $a, 0) end def actionB setColor($blue) drawLine(randomPoint2d, randomPoint2d) SDL::Mixer::playChannel(-1, $b, 0) 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 'r'[0], 'R'[0] upTheta when 't'[0], 'T'[0] downTheta when 'a'[0], 'A'[0] $rwX.init $rwY.init when 's'[0], 'S'[0] $tb *= 0.5 when 'd'[0], 'D'[0] $ta *= 3.0 when 'f'[0], 'F'[0] $tb *= 5.0 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