Вот 2 способа интерполяции:
private static float interpolate(final float a, final float b, final float proportion) {
return a + (b - a) * proportion;
}
/** Returns an interpoloated color, between <code>a</code> and <code>b</code> */
public static int interpolateColorHsv(final int a, final int b, final float proportion) {
final float[] hsva = new float[3];
final float[] hsvb = new float[3];
Color.colorToHSV(a, hsva);
Color.colorToHSV(b, hsvb);
for (int i = 0; i < 3; ++i) {
hsvb[i] = interpolate(hsva[i], hsvb[i], proportion);
}
return Color.HSVToColor(hsvb);
}
public static int interpolateRGB(final int colorA, final int colorB, final float bAmount) {
final float aAmount = 1.0f - bAmount;
final int red = (int) (Color.red(colorA) * aAmount + Color.red(colorB) * bAmount);
final int green = (int) (Color.green(colorA) * aAmount + Color.green(colorB) * bAmount);
final int blue = (int) (Color.blue(colorA) * aAmount + Color.blue(colorB) * bAmount);
return Color.rgb(red, green, blue);
}
Объекты списка реализованы как массивы. Они оптимизированы для быстрого операции фиксированной длины и требуют O (n) затраты на перемещение памяти для pop (0) и insert (0, v) операции, которые изменяют как размер, так и положение базовое представление данных.
См. также: http://docs.python.org/library/collections.html#collections.deque
Кстати, мне интересно, что учебник Python по структурам данных рекомендует использовать pop (0) для имитации очереди, но делает не упоминайте O (n) или опцию deque.
http://docs.python.org/tutorial/datastructures.html#using-lists-as-queues
CPython:
typedef struct {
PyObject_VAR_HEAD
/* Vector of pointers to list elements. list[0] is ob_item[0], etc. */
PyObject **ob_item;
/* ob_item contains space for 'allocated' elements. The number
* currently in use is ob_size.
* Invariants:
* 0 <= ob_size <= allocated
* len(list) == ob_size
* ob_item == NULL implies ob_size == allocated == 0
* list.sort() temporarily sets allocated to -1 to detect mutations.
*
* Items must normally not be NULL, except during construction when
* the list is not yet visible outside the function that builds it.
*/
Py_ssize_t allocated;
} PyListObject;
Как видно из следующего В строке список объявлен как массив указателей на PyObjects
.
PyObject **ob_item;