本文整理汇总了C++中VMDApp::color_change_rgb方法的典型用法代码示例。如果您正苦于以下问题:C++ VMDApp::color_change_rgb方法的具体用法?C++ VMDApp::color_change_rgb怎么用?C++ VMDApp::color_change_rgb使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VMDApp
的用法示例。
在下文中一共展示了VMDApp::color_change_rgb方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: py_set_colorid
static PyObject* py_set_colorid(PyObject *self, PyObject *args,
PyObject *kwargs)
{
const char *kwnames[] = {"id", "rgb", NULL};
float rgb[3];
int colorid;
VMDApp *app;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i(fff):color.set_colorid",
(char**) kwnames, &colorid, &rgb[0], &rgb[1],
&rgb[2]))
return NULL;
if (!(app = get_vmdapp()))
return NULL;
if (colorid >= app->num_regular_colors() || colorid < 0) {
PyErr_Format(PyExc_ValueError, "color index '%d' out of range", colorid);
return NULL;
}
app->color_change_rgb(app->color_name(colorid), rgb[0], rgb[1], rgb[2]);
Py_INCREF(Py_None);
return Py_None;
}
示例2: py_set_colors
static PyObject* py_set_colors(PyObject *self, PyObject *args, PyObject *kwargs)
{
PyObject *newdict, *newtuple, *keys, *vals;
const char *kwnames[] = {"colors", NULL};
PyObject *retval = NULL;
char *keyname;
float rgb[3];
VMDApp *app;
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O!:color.set_colors",
(char**) kwnames, &PyDict_Type, &newdict))
return NULL;
if (!(app = get_vmdapp()))
return NULL;
keys = PyDict_Keys(newdict);
vals = PyDict_Values(newdict);
for (int i=0; i<PyList_Size(keys); i++) {
// Get color name from input dictionary
keyname = as_charptr(PyList_GetItem(keys, i));
if (PyErr_Occurred())
goto cleanup;
// Check this color name actually exists
if (app->color_index(keyname) < 0) {
PyErr_Format(PyExc_ValueError, "Unknown color '%s'", keyname);
goto cleanup;
}
// Unpack value tuples into 3 floats
newtuple = PyList_GetItem(vals, i);
if (!PyTuple_Check(newtuple) || PyTuple_Size(newtuple) != 3) {
PyErr_SetString(PyExc_ValueError,
"color definition must be 3-tuple of floats");
goto cleanup;
}
for (int j=0; j<3; j++) {
rgb[j] = (float)PyFloat_AsDouble(PyTuple_GET_ITEM(newtuple, j));
if (PyErr_Occurred()) {
PyErr_SetString(PyExc_ValueError, "color definition must be floats");
goto cleanup;
}
}
// Finally actually change the color
app->color_change_rgb(keyname, rgb[0], rgb[1], rgb[2]);
}
retval = Py_None;
// Getting the keys and values from the dictionary makes a new reference.
// We tell Python we're done with it so as to not leak memory.
// This needs to happen even if there was a problem setting color, which is
// why we don't return NULL from the error checking statements above.
cleanup:
Py_DECREF(keys);
Py_DECREF(vals);
Py_XINCREF(retval);
return retval;
}