def __init__(self, disp): super(AnimationEngine, self).__init__(disp) self.app = exp.Experiment(self.disp) self.app.engine = self self.rect = self.app.get_render_area() self.beaker = pEquip.WaterBeaker(self.rect.centerx, self.rect.centery, self.rect.height - 50) self.pressureGauge = pEquip.PressureGauge(self.beaker.rect.right - 63, self.rect.centery, 50) self.thermometer = pEquip.Thermometer(self.beaker.rect.left + 55, self.rect.centery, 300) self.bulbBeaker = pEquip.BulbBeaker(self.thermometer.minTemp, self.thermometer.maxTemp) self.equipment = pygame.sprite.Group() self.equipment.add(self.beaker) self.equipment.add(self.pressureGauge) self.equipment.add(self.thermometer) self.currentTemp = 20 self.pressure = self.genValues() # Get values for pressure self.thermometer.setupMarker(self.disp, self.currentTemp) self.pressureGauge.setupPointer(self.genValues(), self.disp) self.isSetup = False self.endTempCalculated = False thermometerLbl = template.DiagramLabel(self.thermometer.rect.left - 70, self.thermometer.rect.centery, self.thermometer, False, False, "Thermometer") pressureGaugeLbl = template.DiagramLabel( self.pressureGauge.rect.centerx, self.pressureGauge.rect.bottom + 60, self.pressureGauge, True, False, "Pressure Gauge") bulbBeakerLbl = template.DiagramLabel(self.bulbBeaker.rect.centerx, self.bulbBeaker.rect.bottom + 40, self.bulbBeaker, True, False, "Bulb Beaker") self.labels = [] self.labels.append(thermometerLbl) self.labels.append(pressureGaugeLbl) self.labels.append(bulbBeakerLbl)
def render(self, rect): self.disp.fill( colours.BLUE) # Background Colour to complement menu colour self.equipment.draw(self.disp) if self.app.showLabels: ballLabel = template.DiagramLabel(self.ball.rect.left - 40, self.ball.rect.centery, self.ball, False, False, "Ball") self.rulerLabel.draw(self.disp) self.clampLabel.draw(self.disp) ballLabel.draw(self.disp) if not self.isSetup and self.app.variablesInputted: self.setExperimentVariables() self.isSetup = True if not self.isPaused and self.app.animationRunning and not self.app.experimentFinished: if not self.runStarted: if self.currentHeight < self.endHeight: #Until currentHeight == endHeight self.currentHeight += self.heightInterval self.setBall( ) # self.ball.rect.bottom = self.ruler.getStartPositionY(self.currentHeight,400) self.runStarted = True elif self.currentHeight == self.endHeight: #Last Iteration of self.setBall() print("Ball Bottom:", self.ball.rect.bottom) print("Ruler Top:", self.ruler.rect.top) self.runStarted = True else: self.ball.setSpeed(self.time) if self.ball.rect.bottom < self.ruler.rect.bottom: self.ball.move() else: self.ball.rect.bottom = self.ruler.rect.bottom self.runStarted = False self.sendValues(self.getTime()) pygame.time.wait(100) if self.currentHeight == self.endHeight and self.ball.rect.bottom == self.ruler.rect.bottom: self.app.experimentFinished = True self.time += 1 / 2 return rect, # Give back rect that has been drawn on
def __init__(self, disp): super(AnimationEngine, self).__init__(disp) self.app = exp.Experiment(self.disp) self.app.engine = self self.rect = self.app.get_render_area() self.startTime = None self.endTime = None self.interval = None self.currentTime = 0 self.nextRecordPoint = 0 self.wireColour = colours.BLACK self.block = sEquip.CopperBlock(10, 100, 400, 300) self.block.insertThermometer() self.block.insertHeater() self.blockRight = self.block.x + self.block.width midBetweenBlockAndEdge = self.block.x + self.block.width + ( self.rect.right - (self.block.x + self.block.width)) // 2 batteryFactor = 1 ammeterFactor = 40 voltmeterFactor = 40 self.battery = eEquip.Battery(midBetweenBlockAndEdge, self.rect.bottom - 60, int(57 * batteryFactor), int(48 * batteryFactor)) self.ammeter = eEquip.Ammeter(self.rect.right - 30, self.rect.centery, int(ammeterFactor * 1)) self.voltmeter = eEquip.Voltmeter(midBetweenBlockAndEdge, 100, int(voltmeterFactor * 1)) self.equipment = pygame.sprite.Group() self.equipment.add(self.block.thermometer) self.equipment.add(self.block.heater) self.equipment.add(self.ammeter) self.equipment.add(self.voltmeter) self.equipment.add(self.battery) self.block.thermometer.setupMarker(self.disp, 20) self.arrowGroup = pygame.sprite.Group() nOfArrows = 7 spacing = 30 y = self.block.y for i in range(nOfArrows): if i == nOfArrows - 1: x = self.block.heaterBasePoint y += spacing angle = 90 elif i % 2 == 0: x = self.block.heaterBasePoint - 40 y += spacing angle = 0 else: x = self.block.heaterBasePoint + 40 angle = 180 a = sEquip.HeatArrow(x, y, angle, 2) self.arrowGroup.add(a) thermometerLabel = template.DiagramLabel( self.block.thermometerBasePoint, self.rect.bottom - 40, self.block.thermometer, True, False, "Thermometer") heaterLabel = template.DiagramLabel(self.block.heaterBasePoint, self.rect.bottom - 30, self.block.heater, True, False, "Heater") blockLabel = template.DiagramLabelPointToPoint( (70, 30), (70, self.block.y), True, True, "1kg Metal Block") ammeterReading = template.DiagramLabel(midBetweenBlockAndEdge, self.ammeter.centerY, self.ammeter, False, False, "Reading: 4A") voltemeterReading = template.DiagramLabel(midBetweenBlockAndEdge, self.voltmeter.centerY - 40, self.voltmeter, True, True, "Reading: 10V") self.labels = [] self.labels.append(thermometerLabel) self.labels.append(heaterLabel) self.labels.append(blockLabel) self.labels.append(ammeterReading) self.labels.append(voltemeterReading)