From e26284910f95d23a987d8d7dd9e66ff26cdef0e4 Mon Sep 17 00:00:00 2001 From: Oreolek Date: Fri, 21 Dec 2012 20:02:42 +0700 Subject: [PATCH] a proper ellipsoid --- python.rb => ellipsoid.rb | 6 ++---- particle.rb | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) rename python.rb => ellipsoid.rb (81%) diff --git a/python.rb b/ellipsoid.rb similarity index 81% rename from python.rb rename to ellipsoid.rb index 27753a0..b86bc2e 100644 --- a/python.rb +++ b/ellipsoid.rb @@ -1,12 +1,10 @@ -# python who ate an elephant - -class Python +class Ellipsoid attr_reader :columns, :rows def initialize radius @columns = @rows = radius * 2 lower_half = (0...radius).map do |y| - x = Math.sqrt(radius**2 - y**2).round + x = Math.sqrt(1 - y**2/radius**2) right_half = "#{"\xff" * x}#{"\x00" * (radius - x)}" "#{right_half.reverse}#{right_half}" end.join diff --git a/particle.rb b/particle.rb index 8a86f8f..76bc553 100644 --- a/particle.rb +++ b/particle.rb @@ -1,4 +1,4 @@ -require './python.rb' +require './ellipsoid.rb' # One particle is basically a sprite, that moves itself by speed every tick along an angle. # It also has a concept of decay, in how quickly the particle dies. In this case, the draw @@ -15,7 +15,7 @@ class Particle @decay = decay radius = (rand * 10).floor - @img = Gosu::Image.new(window, Python.new(radius), false) + @img = Gosu::Image.new(window, Ellipsoid.new(radius), false) end def update