//----------------------------------mathutils.Color() ------------------- //makes a new color for you to play with static PyObject *Color_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { float col[3]= {0.0f, 0.0f, 0.0f}; if (kwds && PyDict_Size(kwds)) { PyErr_SetString(PyExc_TypeError, "mathutils.Color(): " "takes no keyword args"); return NULL; } switch(PyTuple_GET_SIZE(args)) { case 0: break; case 1: if ((mathutils_array_parse(col, COLOR_SIZE, COLOR_SIZE, PyTuple_GET_ITEM(args, 0), "mathutils.Color()")) == -1) return NULL; break; default: PyErr_SetString(PyExc_TypeError, "mathutils.Color(): " "more then a single arg given"); return NULL; } return Color_CreatePyObject(col, Py_NEW, type); }
static PyObject *Color_copy(ColorObject *self) { if (BaseMath_ReadCallback(self) == -1) return NULL; return Color_CreatePyObject(self->col, Py_NEW, Py_TYPE(self)); }
/* -obj * returns the negative of this object */ static PyObject *Color_neg(ColorObject *self) { float tcol[COLOR_SIZE]; if (BaseMath_ReadCallback(self) == -1) return NULL; negate_vn_vn(tcol, self->col, COLOR_SIZE); return Color_CreatePyObject(tcol, Py_NEW, Py_TYPE(self)); }
PyObject *Color_CreatePyObject_cb(PyObject *cb_user, unsigned char cb_type, unsigned char cb_subtype) { ColorObject *self = (ColorObject *)Color_CreatePyObject(NULL, Py_NEW, NULL); if (self) { Py_INCREF(cb_user); self->cb_user = cb_user; self->cb_type = cb_type; self->cb_subtype = cb_subtype; PyObject_GC_Track(self); } return (PyObject *)self; }
/* subtraction: obj - obj */ static PyObject *Color_sub(PyObject *v1, PyObject *v2) { ColorObject *color1 = NULL, *color2 = NULL; float col[COLOR_SIZE]; if (!ColorObject_Check(v1) || !ColorObject_Check(v2)) { PyErr_Format(PyExc_TypeError, "Color subtraction: (%s - %s) " "invalid type for this operation", Py_TYPE(v1)->tp_name, Py_TYPE(v2)->tp_name); return NULL; } color1 = (ColorObject*)v1; color2 = (ColorObject*)v2; if (BaseMath_ReadCallback(color1) == -1 || BaseMath_ReadCallback(color2) == -1) return NULL; sub_vn_vnvn(col, color1->col, color2->col, COLOR_SIZE); return Color_CreatePyObject(col, Py_NEW, Py_TYPE(v1)); }
static PyObject *color_mul_float(ColorObject *color, const float scalar) { float tcol[COLOR_SIZE]; mul_vn_vn_fl(tcol, color->col, COLOR_SIZE, scalar); return Color_CreatePyObject(tcol, Py_NEW, Py_TYPE(color)); }