System.Drawing.Color.FromArgb

Here are the examples of the python api System.Drawing.Color.FromArgb taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

4 Examples 7

Example 1

Project: Honeybee Source File: Honeybee_Visualize Microclimate Map.py
Function: main
def main(pointValues, viewFactorMesh, dataType, lb_preparation, lb_visualization, legendPar, analysisPeriod, simStepPossible, annualData, percentOrTotal):
    #Read the legend parameters.
    lowB, highB, numSeg, customColors, legendBasePoint, legendScale, legendFont, legendFontSize, legendBold, decimalPlaces, removeLessThan = lb_preparation.readLegendParameters(legendPar, False)
    
    #Read the data type and assign default values for mesh types.
    if dataType == 'Degrees From Target' or dataType == 'Predicted Mean Vote' or dataType == 'Degrees From Neutral UTCI' or dataType == 'PET Category':
        pointValuesFinal = pointValues
        if dataType == 'Degrees From Target' or dataType == 'Degrees From Neutral UTCI': legendTitle = 'C'
        elif dataType == 'PET Category': legendTitle = 'PET Category'
        else: legendTitle = 'PMV'
        if dataType == 'Degrees From Target': dataType = dataType + ' Temperature'
        if len(legendPar_) == 0:
            if dataType == 'Degrees From Neutral UTCI': customColors = lb_visualization.gradientLibrary[9]
            else: customColors = lb_visualization.gradientLibrary[8]
            if dataType == 'Degrees From Target Temperature':
                numSeg = 11
                lowB = -5
                highB = 5
            elif dataType == 'Degrees From Neutral UTCI':
                numSeg = 12
                lowB = -32
                highB = 12
            elif dataType == 'PET Category':
                numSeg = 11
                lowB = -2
                highB = 2
            else:
                numSeg = 11
                lowB = -1
                highB = 1
        elif legendPar_[3] == []:
            if dataType == 'Degrees From Neutral UTCI': customColors = lb_visualization.gradientLibrary[9]
            else: customColors = lb_visualization.gradientLibrary[8]
    elif 'Thermal Comfort Percent' in dataType or 'Thermal Autonomy' in dataType or 'Over-Heated Percent' in dataType or 'Under-Heated Percent' in dataType:
        if percentOrTotal == False:
            if 'Percent' in dataType: dataType = dataType.split('Percent')[0] + 'Hours'
            legendTitle = 'Hours'
        else: legendTitle = '%'
        all100Comf = True
        pointValuesFinal = []
        for valCount, value in enumerate(pointValues):
            if value < 1.0: all100Comf = False
            if percentOrTotal == False:
                all100Comf = False
                pointValuesFinal.append(value)
            else: pointValuesFinal.append(value*100)
        if len(legendPar_) == 0:
            if all100Comf == False:
                if 'Thermal Comfort' in dataType or 'Thermal Autonomy' in dataType: customColors = lb_visualization.gradientLibrary[7]
                elif 'Over-Heated' in dataType: customColors = lb_visualization.gradientLibrary[10]
                else: customColors = lb_visualization.gradientLibrary[11]
            else: customColors = [System.Drawing.Color.FromArgb(255,255,255), System.Drawing.Color.FromArgb(255,255,255)]
        elif legendPar_[3] == []:
            if all100Comf == False:
                if 'Thermal Comfort' in dataType or 'Thermal Autonomy' in dataType: customColors = lb_visualization.gradientLibrary[7]
                elif 'Over-Heated' in dataType: customColors = lb_visualization.gradientLibrary[10]
                else: customColors = lb_visualization.gradientLibrary[11]
            else: customColors = [System.Drawing.Color.FromArgb(255,255,255), System.Drawing.Color.FromArgb(255,255,255)]
    else:
        pointValuesFinal = pointValues
        legendTitle = 'C'
    
    #Get the colors for each zone.
    allColors = []
    transparentColors = []
    colors = lb_visualization.gradientColor(pointValuesFinal, lowB, highB, customColors)
    allColors.append(colors)
    
    #Get a list of colors with alpha values as transparent
    for color in colors:
        transparentColors.append(Drawing.Color.FromArgb(125, color.R, color.G, color.B))
    
    #Color the view factor meshes.
    resultMesh = []
    segmentedColors = []
    segmentedTanspColors = []
    segmentedValues = []
    
    colorCounter = 0
    for meshCount, mesh in enumerate(viewFactorMesh):
        mesh.VertexColors.CreateMonotoneMesh(System.Drawing.Color.Gray)
        resultMesh.append(mesh)
        segmentedColors.append(colors[colorCounter:(colorCounter+mesh.Faces.Count)])
        segmentedTanspColors.append(transparentColors[colorCounter:(colorCounter+mesh.Faces.Count)])
        segmentedValues.append(pointValuesFinal[colorCounter:(colorCounter+mesh.Faces.Count)])
        colorCounter+=mesh.Faces.Count
    
    for meshCount, mesh in enumerate(resultMesh):
        counter = 0
        for srfNum in range(mesh.Faces.Count):
            if mesh.Faces[srfNum].IsQuad:
                mesh.VertexColors[counter + 0] = segmentedColors[meshCount][srfNum]
                mesh.VertexColors[counter + 1] = segmentedColors[meshCount][srfNum]
                mesh.VertexColors[counter + 2] = segmentedColors[meshCount][srfNum]
                mesh.VertexColors[counter + 3] = segmentedColors[meshCount][srfNum]
                counter+=4
            else:
                mesh.VertexColors[counter + 0] = segmentedColors[meshCount][srfNum]
                mesh.VertexColors[counter + 1] = segmentedColors[meshCount][srfNum]
                mesh.VertexColors[counter + 2] = segmentedColors[meshCount][srfNum]
                counter+=3
    
    #Create the legend.
    lb_visualization.calculateBB(resultMesh, True)
    if legendBasePoint == None: legendBasePoint = lb_visualization.BoundingBoxPar[0]
    legendSrfs, legendText, legendTextCrv, textPt, textSize = lb_visualization.createLegend(pointValuesFinal, lowB, highB, numSeg, legendTitle, lb_visualization.BoundingBoxPar, legendBasePoint, legendScale, legendFont, legendFontSize, legendBold, decimalPlaces, removeLessThan)
    legendColors = lb_visualization.gradientColor(legendText[:-1], lowB, highB, customColors)
    legendSrfs = lb_visualization.colorMesh(legendColors, legendSrfs)
    
    #Make lists that assist with the labaeling of the rest of the title.
    monthNames = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
    timeNames = ["1:00", "2:00", "3:00", "4:00", "5:00", "6:00", "7:00", "8:00", "9:00", "10:00", "11:00", "12:00", "13:00", "14:00", "15:00", "16:00", "17:00", "18:00", "19:00", "20:00", "21:00", "22:00", "23:00", "24:00"]
    
    #If there is an analysis period, format the text for it in the legend title.
    try:
        if len(analysisPeriod_) == 0 and annualData == False:
            startMonth = analysisPeriod[0][0]
            endMonth = analysisPeriod[1][0]
            startDay = analysisPeriod[0][1]
            endDay = analysisPeriod[1][1]
            startHour = analysisPeriod[0][2]
            endHour = analysisPeriod[1][2]
            if analysisPeriod[0] != analysisPeriod[1]:
                titleDate = str(monthNames[startMonth-1]) + " " + str(startDay) + " " + str(timeNames[startHour-1]) + " - " + str(monthNames[endMonth-1]) + " " + str(endDay) + " " + str(timeNames[endHour-1])
            else: titleDate = str(monthNames[startMonth-1]) + " " + str(startDay) + " " + str(timeNames[startHour-1])
        else:
            startMonth = analysisPeriod_[0][0]
            endMonth = analysisPeriod_[1][0]
            startDay = analysisPeriod_[0][1]
            endDay = analysisPeriod_[1][1]
            startHour = analysisPeriod_[0][2]
            endHour = analysisPeriod_[1][2]
            titleDate = str(monthNames[startMonth-1]) + " " + str(startDay) + " " + str(timeNames[startHour-1]) + " - " + str(monthNames[endMonth-1]) + " " + str(endDay) + " " + str(timeNames[endHour-1])
    except:
        startMonth = analysisPeriod[0][0]
        endMonth = analysisPeriod[1][0]
        startDay = analysisPeriod[0][1]
        endDay = analysisPeriod[1][1]
        startHour = analysisPeriod[0][2]
        endHour = analysisPeriod[1][2]
        if analysisPeriod[0] != analysisPeriod[1]:
            titleDate = str(monthNames[startMonth-1]) + " " + str(startDay) + " " + str(timeNames[startHour-1]) + " - " + str(monthNames[endMonth-1]) + " " + str(endDay) + " " + str(timeNames[endHour-1])
        else: titleDate = str(monthNames[startMonth]) + " " + str(startDay) + " " + str(timeNames[startHour-1])
    
    #Create the Title.
    try:
        if stepOfSimulation_ != None and simStepPossible == True:
            startHOY = lb_preparation.date2Hour(startMonth, startDay, startHour)
            actualHOY = startHOY + stepOfSimulation_ - 1
            date = lb_preparation.hour2Date(actualHOY)
            titleTxt = '\n' + dataType + '\n' + date
        elif len(analysisPeriod) > 0: titleTxt = '\n' + dataType + '\n' + titleDate
        else: titleTxt = '\n' + 'Average ' + dataType
    except:
        titleTxt = '\n' + 'Average ' + dataType
    titleBasePt = lb_visualization.BoundingBoxPar[5]
    titleTextCurve = lb_visualization.text2srf([titleTxt], [titleBasePt], legendFont, textSize, legendBold)
    
    #Bring the legend and the title together.
    fullLegTxt = lb_preparation.flattenList(legendTextCrv + titleTextCurve)
    
    
    return segmentedValues, segmentedTanspColors, resultMesh, [legendSrfs, fullLegTxt], legendBasePoint

Example 2

Project: Butterfly Source File: Butterfly_Plot Residuals.py
def main():
    
    assert hasattr(_solution, 'residualFile'), \
        '{} is not a valid Solution.'.format(_solution)
    
    p = ResidualParser(_solution.residualFile)
    
    if not _fields_:
        try:
            fields = _solution.residualFields
        except:
            raise ValueError('Failed to load fields from solution {}.'.format(_solution))
    else:
        fields = _fields_
    
    for f in fields:
        print f
    
    timeRange = '{} To {}'.format(*p.timeRange)
    
    # calculate curves
    crvs = tuple(rc.Geometry.PolylineCurve(rc.Geometry.Point3d(c, float(i), 0)
        for c, i in enumerate(p.getResiduals(field, timeRange_)))
        for field in fields)
        
    # find bounding box for curves
    bbox = crvs[0].GetBoundingBox(True)
    
    for crv in crvs[1:]:
        bbox = rc.Geometry.BoundingBox.Union(bbox, crv.GetBoundingBox(True))
    
    # create residual line
    startPt = rc.Geometry.Point3d(0, _targetRes_, 0)
    length = bbox.Max[0] - bbox.Min[0]
    resLine = rc.Geometry.Line(startPt, rc.Geometry.Vector3d(length, 0, 0)).ToNurbsCurve()
    bbox = rc.Geometry.BoundingBox.Union(bbox, resLine.GetBoundingBox(True))
    
    # scale curves
    curves = rectToRectMapping(crvs, rectFromBoundingBox(bbox),
                      rectFromBoundingBox(_rect.GetBoundingBox(True)))
    
    resLine = rectToRectMapping((resLine,), rectFromBoundingBox(bbox),
                                       rectFromBoundingBox(_rect.GetBoundingBox(True)))
    
    # create colored meshes
    cs3 = ((102,194,165), (252,141,98), (141,160,203), (231,138,195),
       (166,216,84), (255,217,47), (229,196,148))
    colors = tuple(Color.FromArgb(*rgb) for rgb in cs3)

    if method_ % 2:
        residualLine = coloredMeshFromCurve(resLine, width=_lineWidth_,
                                            colors=[Color.Black])
        
        meshes = coloredMeshFromCurve(curves,  width=_lineWidth_,
                                              colors= colors)
        
        return timeRange, curves, meshes, residualLine, colors[:len(curves)]
    
    return timeRange, curves, [], resLine, colors[:len(curves)]

Example 3

Project: Honeybee Source File: Honeybee_Color Surfaces by EP Result.py
Function: main
def main(zoneValues, zones, srfBreps, srfHeaders, title, legendTitle, lb_preparation, lb_visualization, legendPar):
    #Read the legend parameters.
    lowB, highB, numSeg, customColors, legendBasePoint, legendScale, legendFont, legendFontSize, legendBold, decimalPlaces, removeLessThan = lb_preparation.readLegendParameters(legendPar, False)
    
    #Get the colors
    colors = lb_visualization.gradientColor(zoneValues, lowB, highB, customColors)
    
    #Get a list of colors with alpha values as transparent
    transparentColors = []
    for color in colors:
        transparentColors.append(Drawing.Color.FromArgb(125, color.R, color.G, color.B))
    
    #Create a series of colored meshes and zone curves.
    srfMeshes = []
    zoneWires = []
    
    for count, brep in enumerate(srfBreps):
        meshSrfs = rc.Geometry.Mesh.CreateFromBrep(brep, rc.Geometry.MeshingParameters.Default)
        for mesh in meshSrfs:
            mesh.VertexColors.CreateMonotoneMesh(colors[count])
            srfMeshes.append(mesh)
    
    for brep in zones:
        wireFrame = brep.DuplicateEdgeCurves()
        for crv in wireFrame:
            zoneWires.append(crv)
    
    #Create the legend.
    lb_visualization.calculateBB(zones, True)
    if legendBasePoint == None: legendBasePoint = lb_visualization.BoundingBoxPar[0]
    legendSrfs, legendText, legendTextCrv, textPt, textSize = lb_visualization.createLegend(zoneValues, lowB, highB, numSeg, legendTitle, lb_visualization.BoundingBoxPar, legendBasePoint, legendScale, legendFont, legendFontSize, legendBold, decimalPlaces, removeLessThan)
    legendColors = lb_visualization.gradientColor(legendText[:-1], lowB, highB, customColors)
    legendSrfs = lb_visualization.colorMesh(legendColors, legendSrfs)
    
    #Create the Title.
    titleTxt = '\n' + title[0] + '\n' + title[1]
    titleBasePt = lb_visualization.BoundingBoxPar[5]
    titleTextCurve = lb_visualization.text2srf([titleTxt], [titleBasePt], legendFont, textSize, legendBold)
    
    #Flatten the lists.
    legendTextCrv = lb_preparation.flattenList(legendTextCrv)
    titleTextCurve = lb_preparation.flattenList(titleTextCurve)
    
    return transparentColors, srfBreps, srfMeshes, zoneWires, [legendSrfs, legendTextCrv, titleTextCurve], legendBasePoint

Example 4

Project: Honeybee Source File: Honeybee_Color Zones by EP Result.py
Function: main
def main(zoneValues, zones, zoneFloors, newZoneBreps, zoneHeaders, title, legendTitle, lb_preparation, lb_visualization, legendPar):
    #Read the legend parameters.
    lowB, highB, numSeg, customColors, legendBasePoint, legendScale, legendFont, legendFontSize, legendBold, decimalPlaces, removeLessThan = lb_preparation.readLegendParameters(legendPar, False)
    
    #Get the colors
    colors = lb_visualization.gradientColor(zoneValues, lowB, highB, customColors)
    
    #Get a list of colors with alpha values as transparent
    transparentColors = []
    for color in colors:
        transparentColors.append(Drawing.Color.FromArgb(125, color.R, color.G, color.B))
    
    #Create a series of colored zone meshes and zone curves
    zoneMeshes = []
    zoneWires = []
    zoneCentPts = []
    zoneBreps = []
    
    joinedFloors = []
    for list in zoneFloors:
        try: joinedFloor = rc.Geometry.Brep.JoinBreps(list, sc.doc.ModelAbsoluteTolerance)[0]
        except: joinedFloor = None
        joinedFloors.append(joinedFloor)
    
    for count, brep in enumerate(joinedFloors):
        if brep != None:
            zoneMeshSrfs = rc.Geometry.Mesh.CreateFromBrep(brep, rc.Geometry.MeshingParameters.Default)
            joinedFloorMesh = rc.Geometry.Mesh()
            for mesh in zoneMeshSrfs:
                mesh.VertexColors.CreateMonotoneMesh(colors[count])
                joinedFloorMesh.Append(mesh)
            zoneMeshes.append(joinedFloorMesh)
        else:
            zoneMeshes.append(None)
    
    for brep in zones:
        wireFrame = brep.DuplicateEdgeCurves()
        for crv in wireFrame:
            zoneWires.append(crv)
        bBox = brep.GetBoundingBox(False)
        zoneCentPts.append(bBox.Center)
    
    #Create the legend.
    lb_visualization.calculateBB(zones, True)
    if legendBasePoint == None: legendBasePoint = lb_visualization.BoundingBoxPar[0]
    legendSrfs, legendText, legendTextCrv, textPt, textSize = lb_visualization.createLegend(zoneValues, lowB, highB, numSeg, legendTitle, lb_visualization.BoundingBoxPar, legendBasePoint, legendScale, legendFont, legendFontSize, legendBold, decimalPlaces, removeLessThan)
    legendColors = lb_visualization.gradientColor(legendText[:-1], lowB, highB, customColors)
    legendSrfs = lb_visualization.colorMesh(legendColors, legendSrfs)
    
    #Create the Title.
    titleTxt = '\n' + title[0] + '\n' + title[1]
    titleBasePt = lb_visualization.BoundingBoxPar[5]
    titleTextCurve = lb_visualization.text2srf([titleTxt], [titleBasePt], legendFont, textSize, legendBold)
    
    #Flatten the lists.
    legendTextCrv = lb_preparation.flattenList(legendTextCrv)
    titleTextCurve = lb_preparation.flattenList(titleTextCurve)
    
    return transparentColors, newZoneBreps, zoneMeshes, zoneWires, [legendSrfs, legendTextCrv, titleTextCurve], legendBasePoint