本文整理汇总了C++中VMDApp::color_changevalue方法的典型用法代码示例。如果您正苦于以下问题:C++ VMDApp::color_changevalue方法的具体用法?C++ VMDApp::color_changevalue怎么用?C++ VMDApp::color_changevalue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VMDApp
的用法示例。
在下文中一共展示了VMDApp::color_changevalue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
static PyObject *set_colorid(PyObject *self, PyObject *args) {
int colorid;
float rgb[3];
if (!PyArg_ParseTuple(args, (char *)"i(fff)", &colorid, &rgb[0], &rgb[1], &rgb[2])) {
return NULL;
}
VMDApp *app = get_vmdapp();
if (colorid >= app->num_regular_colors() || colorid < 0) {
PyErr_SetString(PyExc_ValueError, (char *) "color index out of range");
return NULL;
}
const char *name = app->color_name(colorid);
app->color_changevalue(name, rgb[0], rgb[1], rgb[2]);
//We declare that we are returning a pyobject, so lets actually return one!
Py_INCREF(Py_None);
return Py_None;
}
示例2:
static PyObject *set_colors(PyObject *self, PyObject *args) {
PyObject *newdict;
if (!PyArg_ParseTuple(args, (char *)"O!", &PyDict_Type, &newdict))
return NULL;
VMDApp *app = get_vmdapp();
PyObject *keys = PyDict_Keys(newdict);
PyObject *vals = PyDict_Values(newdict);
int error = 0;
for (int i=0; i<PyList_Size(keys); i++) {
char *keyname = PyString_AsString(PyList_GET_ITEM(keys, i));
if (PyErr_Occurred()) {
error = 1;
break;
}
if (app->color_index(keyname) < 0) {
PyErr_SetString(PyExc_ValueError, (char *)"Unknown color");
error = 1;
break;
}
PyObject *newtuple = PyList_GET_ITEM(vals, i);
if (!PyTuple_Check(newtuple) || PyTuple_Size(newtuple) != 3) {
PyErr_SetString(PyExc_ValueError, (char *)"color definition must be 3-tuple of floats");
error = 1;
break;
}
float rgb[3];
for (int j=0; j<3; j++)
rgb[j] = (float)PyFloat_AsDouble(PyTuple_GET_ITEM(newtuple, j));
if (PyErr_Occurred()) {
error = 1;
break;
}
app->color_changevalue(keyname, rgb[0], rgb[1], rgb[2]);
}
Py_DECREF(keys);
Py_DECREF(vals);
if (error)
return NULL;
Py_INCREF(Py_None);
return Py_None;
}