Post Reply 
Color Values in Python?
04-21-2021, 07:49 AM (This post was last modified: 04-21-2021 07:52 AM by toml_12953.)
Post: #4
RE: Color Values in Python?
(04-21-2021 07:23 AM)cyrille de brébisson Wrote:  Hello,

Honestly, the best way is to hard code the colors.
create yourself a const variable that has the colors that you want. This will be the fastest...

Else, define rgb as
def rgb(r,g,b):
return 65536*r + 256*g + b;

Please do NOT call hpprime primitives for such things, the performance hit will be enormous...
Understand that calling hpprime.eval as suggested means transforming integers to a string, concactenating strings (lots of memory moves and the like), then passing all that to the prime system (meaning switching from UTF8 to wchars), followed by parsing of the string, evaluation, and finally an analysis of the result to transform it back to python structures!

I know that prime allows easy use and switch between PPL, cas and python, but these should be used sparingly, only when absolutely nessecary, with large swats in an language or another, but small, repeted calles from one realm to the others are not a good idea.
They will be, at best slow, at worse highlighting bugs and causing problems...

Cyrille

I just found out the hard way! Try this in Python

hpprime.eval("rgb(0,255,0)")

My machine crashes with a conversion error.

Tom L
Cui bono?
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Color Values in Python? - toml_12953 - 04-21-2021, 12:23 AM
RE: Color Values in Python? - critor - 04-21-2021, 07:01 AM
RE: Color Values in Python? - toml_12953 - 04-21-2021 07:49 AM
RE: Color Values in Python? - critor - 04-21-2021, 09:03 AM
RE: Color Values in Python? - toml_12953 - 04-21-2021, 02:23 PM
RE: Color Values in Python? - toml_12953 - 04-22-2021, 01:26 PM



User(s) browsing this thread: 1 Guest(s)