diff options
author | pmoxhay <pmoxhay@earthlink.net> | 2009-06-05 17:28:53 (GMT) |
---|---|---|
committer | pmoxhay <pmoxhay@earthlink.net> | 2009-06-05 17:28:53 (GMT) |
commit | 09db6111e8610c4d3aa7440751641eb2bb7890da (patch) | |
tree | 9a8f09eb7ca1d01debada643dcafa29798ec013b | |
parent | 89d634579e872666a0b536a94bc406dbf1715ce2 (diff) |
Volume comparison fits into AnswerBox.
-rw-r--r-- | TODO | 4 | ||||
-rw-r--r-- | compare3lesson.py | 17 | ||||
-rw-r--r-- | volumeobject.py | 60 | ||||
-rw-r--r-- | volumeproblem.py | 55 |
4 files changed, 102 insertions, 34 deletions
@@ -13,14 +13,14 @@ General Compare3 Lesson - Control movement from one problem type to another. - Don't repeat colors or letters from one problem to the next. -+ Don't repeat recently used problems. +- Don't repeat recently used problems. - Add more problems for some comparisons. + Make something happen when progress is completed successfully. + Display intersection between Shapes in a different color? IntersectionObject maybe? - Mass comparison: fit into answer box. - Fix drawing of mass parallelopipeds (ThreeDObjects). - Fix behavior of line segments (drops getting rejected). -+ Volume comparison: fit into answer box. +- Volume comparison: fit into answer box. + Amount comparison: fit into answer box (maybe make wider and reposition). + Amount comparison: refine appearance of object groups. - Amount comparison: refine appearance of model (make pagelike). diff --git a/compare3lesson.py b/compare3lesson.py index 7bbeed5..0fbbe13 100644 --- a/compare3lesson.py +++ b/compare3lesson.py @@ -168,7 +168,7 @@ class Compare3Lesson(ObjectArea): #print "self.recently_used = ", self.recently_used # Uncomment this to choose a particular problem type. - #self.problem_type = 'length' + #self.problem_type = 'volume' if self.problem_type == 'length': self.problem = LengthProblem(self, self.color_scheme, (self.alphabetical_letter1, self.alphabetical_letter2) ) @@ -214,7 +214,6 @@ class Compare3Lesson(ObjectArea): self.add_object(self.shapesanswer) if self.problem_type == 'area' or self.problem_type == 'length' \ - or self.problem_type == 'volume' \ or self.problem_type == 'cutting': self.problem.shape1.in_answer_box = True self.problem.shape2.in_answer_box = True @@ -240,6 +239,20 @@ class Compare3Lesson(ObjectArea): self.problem.finish_problem_stage1() self.problem.shape1.calculate_bounds() self.problem.shape2.calculate_bounds() + # Make the ShapeObjects inactive. + self.problem.shape1.selected = False + self.problem.shape1.draggable = False + self.problem.shape2.selected = False + self.problem.shape2.draggable = False + elif self.problem_type == 'volume': + self.problem.finish_problem_stage1() + self.problem.shape1.calculate_bounds() + self.problem.shape2.calculate_bounds() + # Make the ShapeObjects inactive. + self.problem.shape1.selected = False + self.problem.shape1.draggable = False + self.problem.shape2.selected = False + self.problem.shape2.draggable = False def pose_problem_stage2(self): #print "pose_problem_stage2 called" diff --git a/volumeobject.py b/volumeobject.py index 8f4c3c4..90c43aa 100644 --- a/volumeobject.py +++ b/volumeobject.py @@ -27,10 +27,22 @@ class VolumeObject(MovableObject): self.symbol = symbol
+ self.area = 0
+ self.centroid = Vector(0, 0)
+ self.bounds_min = Vector(0, 0)
+ self.bounds_max = Vector(0, 0)
+
self.height = height
self.lower_radius = lower_radius
self.upper_radius = upper_radius
+ #if upper_radius > lower_radius:
+ 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.water_height = 0
self.water_lower_radius = lower_radius
self.water_upper_radius = lower_radius
@@ -46,6 +58,9 @@ class VolumeObject(MovableObject): self.contains_water = False
self.full = False
+
+ # Get the current bounding rectangle.
+ self.calculate_bounds()
def calculate_volume(self):
return (math.pi * self.height / 3.0) * \
@@ -128,13 +143,6 @@ class VolumeObject(MovableObject): return pow(x, 1.0/3.0)
else:
return -pow(abs(x), 1.0/3.0)
-
- #def draw_ellipse(self, cr, x, y, width, height):
- # cr.save()
- # cr.translate (x + width / 2., y + height / 2.)
- # cr.scale(width / 2., height / 2.)
- # cr.arc(0., 0., 1., 0., 2 * math.pi)
- # cr.restore()
def draw_ellipse(self, cr, x, y, width, height):
cr.save()
@@ -143,15 +151,6 @@ class VolumeObject(MovableObject): cr.arc(0., 0., 1., 0., 2 * math.pi)
cr.restore()
- #def fill_ellipse(self, cr, x, y, width, height):
- # cr.save()
- # cr.translate (x + width / 2., y + height / 2.)
- # cr.scale(width / 2., height / 2.)
- # cr.arc(0., 0., 1., 0., 2 * math.pi)
- # cr.set_source_rgb(0.37, 0.74, 1.0)
- # cr.fill()
- # cr.restore();
-
def fill_ellipse(self, cr, x, y, width, height):
cr.save()
cr.translate (x + width / 2., y)
@@ -162,8 +161,12 @@ class VolumeObject(MovableObject): cr.restore();
def draw(self, cr):
- cr.scale(self.scale, self.scale)
+ #cr.set_source_rgb(1, 0, 1)
+ #self_bounds_mn, self_bounds_mx = self.get_bounds()
+ #cr.rectangle(self_bounds_mn.x, self_bounds_mn.y, self_bounds_mx.x - self_bounds_mn.x, self_bounds_mx.y - self_bounds_mn.y)
+ #cr.fill()
+ cr.scale(self.scale, self.scale)
points = [
self.pos + Vector(-self.upper_radius, -self.height/2),
self.pos + Vector(self.upper_radius, -self.height/2),
@@ -280,8 +283,23 @@ class VolumeObject(MovableObject): cr.move_to(self.pos.x - x_bearing - width/2, self.pos.y - y_bearing - height/2)
cr.show_text(self.symbol)
- def get_bounds(self):
- max_radius = max(self.upper_radius, self.lower_radius) + 2
- return Vector(self.pos.x - max_radius, self.pos.y - self.height/2 - self.upper_radius), \
- Vector(self.pos.x + max_radius, self.pos.y + self.height/2 + self.lower_radius)
+ def calculate_bounds(self):
+ # Get the current width and height of the bounding rectangle.
+ self.bounds_min = Vector(float('inf'), float('inf'))
+ self.bounds_max = Vector(float('-inf'), float('-inf'))
+ for p in self.points:
+ p = self.transform_point(p)
+ p = p.scaled(self.scale)
+ self.bounds_min = self.bounds_min.min(p)
+ self.bounds_max = self.bounds_max.max(p)
+
+ # Adjust the bounds to show the ellipses.
+ self.bounds_min -= Vector(2, 2 + self.upper_radius/4.)
+ self.bounds_max += Vector(2, 2 + self.lower_radius/4.)
+ def get_bounds(self):
+ return self.bounds_min, self.bounds_max
+
+ def transform_point(self, p):
+ return p.rotate(self.angle) + self.pos
+
\ No newline at end of file diff --git a/volumeproblem.py b/volumeproblem.py index 730f97f..7b9858a 100644 --- a/volumeproblem.py +++ b/volumeproblem.py @@ -51,7 +51,6 @@ class VolumeProblem(Problem): #self.pan2_position = Vector(725, 500) def generate_problem(self): - # The total number of problems. self.n_problems = 12 @@ -60,7 +59,7 @@ class VolumeProblem(Problem): self.problem_number = random.randrange(0, self.n_problems) # Uncomment to test a particular problem. - #problem_number = 0 + #self.problem_number = 0 # Define the various problems. if self.problem_number == 0: @@ -299,15 +298,19 @@ class VolumeProblem(Problem): if self.shape1.pos.approx_equal(self.under_faucet_position, tolerance=100): #print " first volume is under the faucet" if not self.shape1.full and not self.shape2.full: - self.shape1.pos = self.under_faucet_position + #self.shape1.pos = self.under_faucet_position + self.shape1.move(self.under_faucet_position) + self.shape1.calculate_bounds() self.shape1.contains_water = True self.shape1.full = True self.shape1.water_height = self.shape1.height - self.shape1.fill_to_given_volume(self.shape1.volume) + self.shape1.fill_to_given_volume(self.shape1.volume) elif self.shape2.pos.approx_equal(self.under_faucet_position, tolerance=100): #print " second volume is under the faucet" if not self.shape1.full and not self.shape2.full: - self.shape2.pos = self.under_faucet_position + #self.shape2.pos = self.under_faucet_position + self.shape2.move(self.under_faucet_position) + self.shape2.calculate_bounds() self.shape2.contains_water = True self.shape2.full = True self.shape2.water_height = self.shape2.height @@ -341,6 +344,11 @@ class VolumeProblem(Problem): else: self.shape1.pos = Vector(self.shape2.pos.x + 250, self.shape2.pos.y) + #self.shape1.calculate_bounds() + #self.shape2.calculate_bounds() + + self.place_objects_in_final_positions() + return True elif self.shape2.full and not self.shape1.full: @@ -366,15 +374,44 @@ class VolumeProblem(Problem): #print " After: volume2 =", self.shape2.water_volume #print " volume1 =", self.shape1.water_volume - if self.shape1.pos.x > 250: - self.shape2.pos = Vector(self.shape1.pos.x - 250, self.shape1.pos.y) - else: - self.shape2.pos = Vector(self.shape1.pos.x + 250, self.shape1.pos.y) + #if self.shape1.pos.x > 250: + # self.shape2.pos = Vector(self.shape1.pos.x - 250, self.shape1.pos.y) + #else: + # self.shape2.pos = Vector(self.shape1.pos.x + 250, self.shape1.pos.y) + + self.place_objects_in_final_positions() return True #print " returning False" return False + + def finish_problem_stage1(self): + #print "VolumeProblem: finish_problem_stage1 called" + pass + + def place_objects_in_final_positions(self): + #print "VolumeProblem: place_objects_in_final_positions called" + + for o in self.container.objects: + if isinstance(o, VolumeObject): + o.scale = 0.9 + o.calculate_bounds() + + x_left_final = 300 + x_right_final = 550 + y_final = 450 + + if self.shape1.pos.x < self.shape2.pos.x: + #print "shape1 is on left" + self.shape1.move(Vector(x_left_final, y_final)) + self.shape2.move(Vector(x_right_final, y_final)) + else: + #print "shape1 is on right" + self.shape2.move(Vector(x_left_final, y_final)) + self.shape1.move(Vector(x_right_final, y_final)) + + self.container.remove_object(self.faucet_object) def find_answer(self): if self.shape1.volume > self.shape2.volume: |