bool C4MapScriptAlgoTurbulence::operator () (int32_t x, int32_t y, uint8_t& fg, uint8_t& bg) const { // Evaluate MAPALGO_Turbulence at x,y: // move by a random offset iterations times assert(operands.size()==1); int32_t xy[] = {x, y}; for (int32_t iter=0; iter<iterations; ++iter) { int32_t s[2], p[2]; for (int dim=0; dim<2; ++dim) { s[dim] = divD(xy[dim], scale[dim]); p[dim] = modD(xy[dim], scale[dim]); } int32_t a[2][2]; for (int dim=0; dim<2; ++dim) { int32_t aamp = amp[dim] / (iter+1); if (!aamp) continue; for (int dx=0; dx<2; ++dx) for (int dy=0; dy<2; ++dy) a[dx][dy] = QuerySeededRandomField(seed+dim, s[0]+dx, s[1]+dy, aamp) - aamp/2; int32_t a_interp = a[0][0]*(scale[0]-p[0])*(scale[1]-p[1]) + a[1][0]*( p[0])*(scale[1]-p[1]) + a[0][1]*(scale[0]-p[0])*( p[1]) + a[1][1]*( p[0])*( p[1]); xy[dim] += a_interp / (scale[0]*scale[1]); } } return (*operands[0])(xy[0],xy[1], fg, bg); }
void KPrTimeLineView::mouseMoveEvent(QMouseEvent *event) { // Resize the bar if (m_resize) { const qreal subSteps = 0.2; int startPos = 0; for (int i = 0; i < KPrShapeAnimations::StartTime; i++) { startPos = startPos + m_mainView->widthOfColumn(i); } int row = m_resizedRow; //calculate real start qreal startOffSet = m_mainView->calculateStartOffset(row) / 1000.0; qreal start = m_mainView->model()->data(m_mainView->model()->index(row, KPrShapeAnimations::StartTime)).toInt() / 1000.0; qreal duration = m_mainView->model()->data(m_mainView->model()->index(row, KPrShapeAnimations::Duration)).toInt() / 1000.0; qreal totalSteps = m_mainView->numberOfSteps(); qreal stepSize = m_mainView->widthOfColumn( KPrShapeAnimations::StartTime) / totalSteps; if ((event->pos().x() > (startPos + startOffSet*stepSize + stepSize * start - 5)) && ((event->pos().x()) < (startPos + m_mainView->widthOfColumn( KPrShapeAnimations::StartTime)))) { qreal newLength = (event->pos().x() - startPos - stepSize * start) / (stepSize) - startOffSet; newLength = qFloor((newLength - modD(newLength, subSteps)) * 100.0) / 100.0; // update bar length m_mainView->model()->setData(m_mainView->model()->index(row, KPrShapeAnimations::Duration), newLength * 1000); emit timeValuesChanged(m_mainView->model()->index(row, KPrShapeAnimations::Duration)); m_adjust = false; if (newLength < duration) m_adjust = true; } else if ( ((event->pos().x()) > (startPos + m_mainView->widthOfColumn( KPrShapeAnimations::StartTime)))) { m_mainView->incrementScale(); m_adjust = true; } update(); } //Move the bar if (m_move) { const int Padding = 2; int startPos = 0; const qreal subSteps = 0.2; for (int i = 0; i < KPrShapeAnimations::StartTime; i++) { startPos = startPos + m_mainView->widthOfColumn(i); } int row = m_resizedRow; //calculate real start qreal startOffSet = m_mainView->calculateStartOffset(row) / 1000; qreal duration = m_mainView->model()->data(m_mainView->model()->index(row, KPrShapeAnimations::Duration)).toInt() / 1000.0; qreal start = m_mainView->model()->data(m_mainView->model()->index(row, KPrShapeAnimations::StartTime)).toInt() / 1000.0; qreal totalSteps = m_mainView->numberOfSteps(); qreal stepSize = m_mainView->widthOfColumn(KPrShapeAnimations::StartTime) / totalSteps; qreal Threshold = 0.4; if ((event->pos().x() > (startPos + startDragPos + startOffSet*stepSize)) && ((event->pos().x() + (duration * stepSize - startDragPos) + Padding * 2) < (startPos+m_mainView->widthOfColumn( KPrShapeAnimations::StartTime)))) { qreal newPos = (event->pos().x() - (startPos + startDragPos)) / (stepSize) - startOffSet; newPos = qFloor((newPos - modD(newPos, subSteps)) * 100.0) / 100.0; // update bar position m_mainView->model()->setData(m_mainView->model()->index(row, KPrShapeAnimations::StartTime), newPos * 1000); emit timeValuesChanged(m_mainView->model()->index(row, KPrShapeAnimations::StartTime)); m_adjust = false; if (newPos <= start) { m_adjust = true; } } else if (((event->pos().x() + (duration*stepSize-startDragPos) + Padding * 2) > (startPos + m_mainView->widthOfColumn( KPrShapeAnimations::StartTime)))) { m_mainView->incrementScale(); } else if (event->pos().x() < (startPos + startDragPos + startOffSet * stepSize + Threshold)) { m_mainView->changeStartLimit(row); } update(); } int row = rowAt(event->y()); int column = columnAt(event->x()); if (column == KPrShapeAnimations::StartTime) { QRectF lineRect = getRowRect(row, column); QRectF endLineRect = QRectF(lineRect.right() - RESIZE_RADIUS, lineRect.top() + BAR_MARGIN, RESIZE_RADIUS * 2, lineRect.height() - 2 * BAR_MARGIN); // If the user is near the end of the line they could resize if (endLineRect.contains(event->x(), event->y())) { setCursor(Qt::SizeHorCursor); } else { if (lineRect.contains(event->x(), event->y())) { setCursor( #if QT_VERSION >= 0x040700 Qt::DragMoveCursor #else Qt::ClosedHandCursor #endif ); } else { setCursor(Qt::ArrowCursor); } } } QWidget::mouseMoveEvent(event); }
// Creates a field of random numbers between 0 and scale-1. Returns the value of the field at position x,y // Function should be deterministic for the same value of x,y, but should look somewhat random wrt neighbouring values of x,y int32_t QuerySeededRandomField(int32_t seed, int32_t x, int32_t y, int32_t scale) { return modD((((seed ^ (x*214013))*214013) ^ (y*214013)), scale); }