Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/volumeobject.py
diff options
context:
space:
mode:
Diffstat (limited to 'volumeobject.py')
-rw-r--r--volumeobject.py81
1 files changed, 73 insertions, 8 deletions
diff --git a/volumeobject.py b/volumeobject.py
index 16a74cf..a0df582 100644
--- a/volumeobject.py
+++ b/volumeobject.py
@@ -39,12 +39,32 @@ class VolumeObject(MovableObject):
self.lower_radius = lower_radius
self.upper_radius = upper_radius
- #if upper_radius > lower_radius:
+ self.shifted_pos = Vector(0, 0)
+ self.x0 = 0
+ self.y0 = 0
+
+ self.a1 = 0
+ self.b1 = 0
+ self.h1 = 0
+ self.a2 = 0
+ self.b2 = 0
+ self.h2 = 0
+
+ # For debugging, set this equal to True to draw a simple
+ # trapezoid with a dot at the center.
+ self.ellipses_and_letter_visible = True
+
+ # Modify this so the centroid is really at (0, 0)? Maybe this isn't necessary.
self.points = [ Vector(-self.upper_radius, -self.height/2.), Vector(self.upper_radius-self.lower_radius, self.height/2.), \
Vector(self.lower_radius, self.height/2.), Vector(-self.lower_radius, self.height/2.) ]
- #else:
- # self.points = [ Vector(-self.upper_radius, -self.height/2.), Vector(self.upper_radius-self.lower_radius, self.height/2.), \
- # Vector(self.lower_radius, self.height/2.), Vector(self.upper_radius, self.height/2.) ]
+
+ #self.points = [ Vector(-self.upper_radius, -self.height * ( 4. * self.upper_radius + 2. * self.lower_radius)/(3. * (2. * self.upper_radius + 2. * self.lower_radius)) ), \
+ #
+ # Vector(self.upper_radius, -self.height * ( 4. * self.upper_radius + 2. * self.lower_radius)/(3. * (2. * self.upper_radius + 2. * self.lower_radius)) ), \
+ #
+ # Vector(self.lower_radius, self.height * ( 2. * self.upper_radius + 4. * self.lower_radius)/(3. * (2. * self.upper_radius + 2. * self.lower_radius)) ), \
+ #
+ # Vector(-self.lower_radius, self.height * ( 2. * self.upper_radius + 4. * self.lower_radius)/(3. * (2. * self.upper_radius + 2. * self.lower_radius)) ) ]
self.water_height = 0
self.water_lower_radius = lower_radius
@@ -55,6 +75,8 @@ class VolumeObject(MovableObject):
self.animated_water_volume = 0
self.animated_water_height = 0
+
+ self.initial_volume_to_pour_out = 0
self.filling_from_faucet = False
@@ -152,9 +174,10 @@ class VolumeObject(MovableObject):
def draw_ellipse(self, cr, x, y, width, height):
cr.new_sub_path()
cr.save()
- cr.translate (x + width / 2., y)
- cr.scale(width / 2., height / 2.)
- cr.arc(0., 0., 1., 0., 2 * math.pi)
+ if self.ellipses_and_letter_visible:
+ cr.translate (x + width / 2., y)
+ cr.scale(width / 2., height / 2.)
+ cr.arc(0., 0., 1., 0., 2 * math.pi)
cr.restore()
def animate(self):
@@ -165,6 +188,34 @@ class VolumeObject(MovableObject):
self.queue_draw()
elif self.animated_water_volume > self.water_volume:
+ #print "animating: self.animated_water_volume = ", self.animated_water_volume
+ #print "animating: self.initial_volume_to_pour_out = ", self.initial_volume_to_pour_out
+ # Have the angle change from 0 deg to 90 deg.
+ angle = 90.0 * (1.0 - self.animated_water_volume/self.initial_volume_to_pour_out)
+ self.rotate(angle * math.pi/180.0)
+
+ theta = angle * math.pi/180.0
+
+ a1 = self.a1
+ b1 = self.b1
+ h1 = self.h1
+ a2 = self.a2
+ b2 = self.b2
+ h2 = self.h2
+
+ x_shift = - b2/2. - b1/2.
+ y_shift = - h2/2. + h1/2.
+
+ x_shift = - b2/2. - b1 * math.cos(theta) /2. - h1 * math.sin(theta) /2.
+ y_shift = - h2/2. + h1 * math.cos(theta) /2. - b1 * math.sin(theta) /2.
+
+ #print "x_shift =", x_shift
+ #print "y_shift =", y_shift
+
+ shifted_pos = Vector(self.x0 + x_shift, self.y0 + y_shift)
+
+ self.move(shifted_pos)
+
self.animated_water_volume = max(self.animated_water_volume - VolumeObject.FILL_RATE, self.water_volume)
self.animated_water_height = self.calculate_water_height(self.animated_water_volume)
self.calculate_bounds()
@@ -231,18 +282,32 @@ class VolumeObject(MovableObject):
cr.line_to(ll.x, ll.y)
cr.move_to(ur.x, ur.y)
cr.line_to(lr.x, lr.y)
+
+ if not self.ellipses_and_letter_visible:
+ cr.move_to(ul.x, ur.y)
+ cr.line_to(ur.x, ur.y)
+ cr.move_to(ll.x, lr.y)
+ cr.line_to(lr.x, lr.y)
self.draw_ellipse(cr, ll.x, ll.y, 2.0 * self.lower_radius, self.lower_radius/2.0)
self.draw_ellipse(cr, ul.x, ul.y, 2.0 * self.upper_radius, self.upper_radius/2.0)
cr.stroke()
# Draw the symbol (capital letter representing the shape's area).
- if self.symbol_visible:
+ if self.symbol_visible and self.ellipses_and_letter_visible:
cr.set_source_rgb(0, 0, 0)
cr.set_font_size(50)
x_bearing, y_bearing, width, height = cr.text_extents(self.symbol)[:4]
cr.move_to(-x_bearing - width/2, -y_bearing - height/2)
cr.show_text(self.symbol)
+
+ # For debugging purposes, draw a dot to show the center of mass.
+ if not self.ellipses_and_letter_visible:
+ cr.save()
+ cr.arc(0, 0, 4, 0, 2.*math.pi)
+ cr.set_source_rgb(0., 0., 0.)
+ cr.fill()
+ cr.restore()
def calculate_bounds(self):
r = max(self.upper_radius, self.lower_radius)