def lighterColor(aColor): r = umath.intMin(255, intround(GetRValue(aColor) * 1.5)) g = umath.intMin(255, intround(GetGValue(aColor) * 1.5)) b = umath.intMin(255, intround(GetBValue(aColor) * 1.5)) result = support_rgb(r, g, b) #result := support_rgb(GetRValue(aColor) div 2, GetGValue(aColor) div 2, GetBValue(aColor) div 2); return result
def combineRects(rect1, rect2): result = TRect() result.Left = umath.intMin(rect1.Left, rect2.Left) result.Right = umath.intMax(rect1.Right, rect2.Right) result.Top = umath.intMin(rect1.Top, rect2.Top) result.Bottom = umath.intMax(rect1.Bottom, rect2.Bottom) return result
def lighterColor(aColor): result = TColorRef() r = 0 g = 0 b = 0 r = umath.intMin(255, intround(UNRESOLVED.GetRValue(aColor) * 1.5)) g = umath.intMin(255, intround(UNRESOLVED.GetGValue(aColor) * 1.5)) b = umath.intMin(255, intround(UNRESOLVED.GetBValue(aColor) * 1.5)) result = support_rgb(r, g, b) # result := support_rgb(GetRValue(aColor) div 2, GetGValue(aColor) div 2, GetBValue(aColor) div 2); return result
def breedFromParents(self, aFirstParent, aSecondParent, fractionOfMaxAge): newPlant = PdPlant() i = 0 newAge = 0 fileNameWithPath = "" newTdo = KfObject3D() inputFile = TextFile() tdos = TListCollection() localOptions = BreedingAndTimeSeriesOptionsStructure() self.firstParent = aFirstParent if self.firstParent == None: return if udomain.domain == None: return self.secondParent = aSecondParent self.plants.clear() self.selectedPlants.Clear() tdos = None if (udomain.domain.breedingAndTimeSeriesOptions.chooseTdosRandomlyFromCurrentLibrary) and (not udomain.domain.checkForExistingDefaultTdoLibrary()): MessageDialog("Because you didn't choose a 3D object library, the breeder won't be able" + chr(13) + "to randomly choose 3D objects for your breeding offspring." + chr(13) + chr(13) + "You can choose a library later by choosing Custom from the Variation menu" + chr(13) + "and choosing a 3D object library there.", mtWarning, [mbOK, ], 0) try: if udomain.domain.breedingAndTimeSeriesOptions.chooseTdosRandomlyFromCurrentLibrary: tdos = ucollect.TListCollection().Create() fileNameWithPath = udomain.domain.defaultTdoLibraryFileName if not FileExists(fileNameWithPath): udomain.domain.breedingAndTimeSeriesOptions.chooseTdosRandomlyFromCurrentLibrary = false else: # cfk note: is it really ok to read the whole tdo file each time? AssignFile(inputFile, fileNameWithPath) try: # v1.5 usupport.setDecimalSeparator() Reset(inputFile) while not UNRESOLVED.eof(inputFile): newTdo = utdo.KfObject3D().create() newTdo.readFromFileStream(inputFile, utdo.kInTdoLibrary) tdos.Add(newTdo) finally: CloseFile(inputFile) for i in range(0, udomain.domain.breedingAndTimeSeriesOptions.plantsPerGeneration): newPlant = uplant.PdPlant().create() self.plants.Add(newPlant) newPlant.reset() if udomain.domain.breedingAndTimeSeriesOptions.variationType != udomain.kBreederVariationNoNumeric: newPlant.randomize() self.setLocalOptionsToDomainOptions(localOptions) newPlant.useBreedingOptionsAndPlantsToSetParameters(localOptions, self.firstParent, self.secondParent, tdos) newAge = intround(newPlant.pGeneral.ageAtMaturity * fractionOfMaxAge) newPlant.setAge(umath.intMin(newAge, newPlant.pGeneral.ageAtMaturity)) # v2.0 plants take rotation angles from first parent newPlant.xRotation = self.firstParent.xRotation newPlant.yRotation = self.firstParent.yRotation newPlant.zRotation = self.firstParent.zRotation finally: tdos.free
def updateForChangeToDomainOptions(self): i = 0 if udomain.domain.breedingAndTimeSeriesOptions.numTimeSeriesStages != self.numStages: self.numStages = udomain.domain.breedingAndTimeSeriesOptions.numTimeSeriesStages for i in range(0, self.numStages): self.percentsOfMaxAge[i] = umath.intMin(100, umath.intMax(0, (i + 1) * 100 / self.numStages)) if self.grid.ColCount != self.numStages: self.grid.ColCount = self.numStages self.updateForNewNumberOfStages() if self.grid.DefaultColWidth != udomain.domain.breedingAndTimeSeriesOptions.thumbnailWidth: self.grid.DefaultColWidth = udomain.domain.breedingAndTimeSeriesOptions.thumbnailWidth if self.grid.DefaultRowHeight != udomain.domain.breedingAndTimeSeriesOptions.thumbnailHeight: self.grid.DefaultRowHeight = udomain.domain.breedingAndTimeSeriesOptions.thumbnailHeight self.grid.RowHeights[1] = kStageNumberTextHeight self.redrawPlants()
def breedFromParents(self, aFirstParent, aSecondParent, fractionOfMaxAge): self.firstParent = aFirstParent if self.firstParent == None: return if udomain.domain == None: return self.secondParent = aSecondParent self.plants.Clear() self.selectedPlants.Clear() tdos = None if (udomain.domain.breedingAndTimeSeriesOptions.chooseTdosRandomlyFromCurrentLibrary) and (not udomain.domain.checkForExistingDefaultTdoLibrary()): MessageDialog("Because you didn't choose a 3D object library, the breeder won't be able" + chr(13) + "to randomly choose 3D objects for your breeding offspring." + chr(13) + chr(13) + "You can choose a library later by choosing Custom from the Variation menu" + chr(13) + "and choosing a 3D object library there.", mtWarning, [mbOK, ], 0) if udomain.domain.breedingAndTimeSeriesOptions.chooseTdosRandomlyFromCurrentLibrary: tdos = ucollect.TListCollection() fileNameWithPath = udomain.domain.defaultTdoLibraryFileName if not FileExists(fileNameWithPath): udomain.domain.breedingAndTimeSeriesOptions.chooseTdosRandomlyFromCurrentLibrary = False else: # cfk note: is it really ok to read the whole tdo file each time? AssignFile(inputFile, fileNameWithPath) try: # v1.5 usupport.setDecimalSeparator() Reset(inputFile) while not UNRESOLVED.eof(inputFile): newTdo = utdo.KfObject3D() newTdo.readFromFileStream(inputFile, utdo.kInTdoLibrary) tdos.Add(newTdo) finally: CloseFile(inputFile) for i in range(0, udomain.domain.breedingAndTimeSeriesOptions.plantsPerGeneration): newPlant = uplant.PdPlant() self.plants.Add(newPlant) newPlant.reset() if udomain.domain.breedingAndTimeSeriesOptions.variationType != udomain.kBreederVariationNoNumeric: newPlant.randomize() localOptions = uplant.BreedingAndTimeSeriesOptionsStructure() self.setLocalOptionsToDomainOptions(localOptions) newPlant.useBreedingOptionsAndPlantsToSetParameters(localOptions, self.firstParent, self.secondParent, tdos) newAge = intround(newPlant.pGeneral.ageAtMaturity * fractionOfMaxAge) newPlant.setAge(umath.intMin(newAge, newPlant.pGeneral.ageAtMaturity)) # v2.0 plants take rotation angles from first parent newPlant.xRotation = self.firstParent.xRotation newPlant.yRotation = self.firstParent.yRotation newPlant.zRotation = self.firstParent.zRotation
def blendColors(firstColor, secondColor, aStrength): #blend first color with second color, # weighting the second color by aStrength (0-1) and first color by (1 - aStrength). aStrength = umath.max(0.0, umath.min(1.0, aStrength)) r1 = umath.intMax(0, umath.intMin(255, GetRValue(firstColor))) g1 = umath.intMax(0, umath.intMin(255, GetGValue(firstColor))) b1 = umath.intMax(0, umath.intMin(255, GetBValue(firstColor))) r2 = umath.intMax(0, umath.intMin(255, GetRValue(secondColor))) g2 = umath.intMax(0, umath.intMin(255, GetGValue(secondColor))) b2 = umath.intMax(0, umath.intMin(255, GetBValue(secondColor))) result = support_rgb(intround(r1 * (1.0 - aStrength) + r2 * aStrength), intround(g1 * (1.0 - aStrength) + g2 * aStrength), intround(b1 * (1.0 - aStrength) + b2 * aStrength)) return result
def updateForPrinterInfo(self): xResolution_pixelsPerInch = 0 yResolution_pixelsPerInch = 0 portraitOrLandscape = "" printerDC = HDC() printerColorBits = 0 printerColors = 0 xResolution_pixelsPerInch = UNRESOLVED.GetDeviceCaps(UNRESOLVED.Printer.Handle, delphi_compatability.LOGPIXELSX) yResolution_pixelsPerInch = UNRESOLVED.GetDeviceCaps(UNRESOLVED.Printer.Handle, delphi_compatability.LOGPIXELSY) self.smallestPrintResolution_pxPin = umath.intMin(xResolution_pixelsPerInch, yResolution_pixelsPerInch) self.printPageWidth_in = umath.safedivExcept(UNRESOLVED.Printer.pageWidth - 1, xResolution_pixelsPerInch, 0) self.printPageHeight_in = umath.safedivExcept(UNRESOLVED.Printer.pageHeight - 1, yResolution_pixelsPerInch, 0) self.wholePageWidth_in = umath.safedivExcept(UNRESOLVED.GetDeviceCaps(UNRESOLVED.Printer.Handle, UNRESOLVED.PHYSICALWIDTH), xResolution_pixelsPerInch, 0) self.wholePageHeight_in = umath.safedivExcept(UNRESOLVED.GetDeviceCaps(UNRESOLVED.Printer.Handle, UNRESOLVED.PHYSICALHEIGHT), xResolution_pixelsPerInch, 0) self.printMinMarginLeft_in = umath.safedivExcept(UNRESOLVED.GetDeviceCaps(UNRESOLVED.Printer.Handle, UNRESOLVED.PhysicalOffsetX), xResolution_pixelsPerInch, 0) self.printMinMarginTop_in = umath.safedivExcept(UNRESOLVED.GetDeviceCaps(UNRESOLVED.Printer.Handle, UNRESOLVED.PhysicalOffsetY), xResolution_pixelsPerInch, 0) self.printMinMarginRight_in = self.wholePageWidth_in - self.printPageWidth_in - self.printMinMarginLeft_in self.printMinMarginBottom_in = self.wholePageHeight_in - self.printPageHeight_in - self.printMinMarginTop_in if UNRESOLVED.Printer.orientation == UNRESOLVED.poPortrait: portraitOrLandscape = "Portrait" else: portraitOrLandscape = "Landscape" printerDC = UNRESOLVED.CreateCompatibleDC(UNRESOLVED.Printer.Handle) try: printerColorBits = (UNRESOLVED.GetDeviceCaps(printerDC, delphi_compatability.BITSPIXEL) * UNRESOLVED.GetDeviceCaps(printerDC, delphi_compatability.PLANES)) finally: UNRESOLVED.ReleaseDC(0, printerDC) UNRESOLVED.DeleteDC(printerDC) if printerColorBits != 32: printerColors = 1 << printerColorBits else: printerColors = intround(umath.power(2.0, printerColorBits)) self.printerOrFileTypeInfoLabel.Caption = "Printer: " + IntToStr(UNRESOLVED.GetDeviceCaps(UNRESOLVED.Printer.Handle, delphi_compatability.LOGPIXELSX)) + " x " + IntToStr(UNRESOLVED.GetDeviceCaps(UNRESOLVED.Printer.Handle, delphi_compatability.LOGPIXELSY)) + " pixels/inch, " + IntToStr(printerColors) + " colors (" + IntToStr(printerColorBits) + " bits)" #+ portraitOrLandscape; #printerInfoLabel.hint := 'Printer name: ' + Printer.Printers[Printer.printerIndex]; self.updatePrintPreview()