Original User: thyandrecardosoHey, I thought I might share some things here, in the sense that it might be useful to someone.I've coded some functions to retrieve R, G and B values, given Hue Saturation and Lightness:
hue2R(H, S, L) =
case S == 0.0:
L
else:
hue2RGB( temp1(L, S), temp2(L, S), H + truncTo1000( 1.0/3.0 ) )
hue2G(H, S, L) =
case S == 0.0:
L
else:
hue2RGB( temp1(L, S), temp2(L, S), H)
hue2B(H, S, L) =
case S == 0.0:
L
else:
hue2RGB( temp1(L, S), temp2(L, S), H - truncTo1000( 1.0 / 3.0 ) )
hue2RGB(v1, v2, vH ) = //Function Hue_2_RGB
case vH < 0.0:
hue2RGB(v1, v2, truncTo1000(vH + 1.0))
case vH > 1.0:
hue2RGB(v1, v2, truncTo1000(vH - 1.0))
else:
case truncTo1000(6.0 * vH) < 1.0:
( truncTo1000(v1 + ( v2 - v1 )) * truncTo1000(6.0 * vH) )
case truncTo1000(2.0 * vH) < 1.0:
v2
case truncTo1000(3.0 * vH) < 2.0:
( (v1 + ( v2 - v1 )) * truncTo1000( ( 2.0 / 3.0 ) - vH) * 6.0 )
else:
0
temp2(l, sat) =
case l < 0.5:
l * (1+sat)
else:
(l+sat) - (l*sat)
temp1(l, sat) =
(2.0 * l) - temp2(l, sat)
truncTo1000(val) =
truncTo(val, 1000)
truncTo100(val) =
truncTo(val, 100)
truncTo(val, order) =
((rint(val * order)) / order)
Which allows one to do things like the ones in the pictures attached!################################################On the python side, some really small snippets that I personally find very usefull (please don't mind possible lack of naming conventions or whatever... I'm not a python programmer):
def getAttrFilterFunction(ce_instance, attr, value):
return lambda x: ce_instance.getAttribute(x, attr) == value
def getAttrContainingFilter(ce_instance, attr, value):
return lambda x: value in ce_instance.getAttribute(x, attr)
def getAttrExistsFilter(ce_instance, attr):
return lambda x: attr in ce_instance.getAttributeList(x)
# determines if shape is sidewalk
def getSidewalkFilter(ce_instance):
return lambda x: ce_instance.getUUID(x).__str__().endswith(":1") or ce_instance.getUUID(x).__str__().endswith(":2")
# determines if shape is street
def getStreetFilter(ce_instance):
return lambda x: ce_instance.getUUID(x).__str__().endswith(":0")
For example, with these you can use the python "filter" function:
allShapes = ce.selection()
myStreetsFilter = getStreetFilter(ce)
onlyStreets = filter(myStreetsFilter, allShapes)
Hey, please share other useful snippets! And please warn me about bugs in the things I've posted 🙂Cheers!André