public void SetColor(ref Color color, int index) { //float velocity = VectorFuncts.Length(this.vecX[i], this.vecY[i]); //byte alpha = (byte) TweenFuncts.Linear(velocity, 0, 4, 127, 255); //var HLSColor = ColorFuncts.HSLToRGB(TweenFuncts.Linear(angle, (float) -Math.PI, (float) Math.PI, 0, 359), 60, 40, 255); float angle = (float)Math.Atan2(this.vecX[index], this.vecY[index]); if (angle > 0) { color.R = (byte)TweenFuncts.Linear(angle, 0, (float)Math.PI, 0, 255); } else { color.R = (byte)TweenFuncts.Linear(angle, (float)-Math.PI, 0, 255, 0); } color.G = 64; color.B = 127; color.A = 255; }
public void Update(float deltaTime) { deltaTime *= 8; /*for (int i = 0; i < this.gridSize; i++) { * for (int j = 0; j < this.gridSize; j++) { * float avgX = this.vfVecX[MathFuncts.Mod(i - 1, this.gridSize), MathFuncts.Mod(j - 1, this.gridSize)] + this.vfVecX[i, MathFuncts.Mod(j - 1, this.gridSize)] + this.vfVecX[MathFuncts.Mod(i + 1, this.gridSize), MathFuncts.Mod(j - 1, this.gridSize)] + this.vfVecX[MathFuncts.Mod(i - 1, this.gridSize), j] + this.vfVecX[i, j] + this.vfVecX[MathFuncts.Mod(i + 1, this.gridSize), j] + this.vfVecX[MathFuncts.Mod(i - 1, this.gridSize), MathFuncts.Mod(j + 1, this.gridSize)] + this.vfVecX[i, MathFuncts.Mod(j + 1, this.gridSize)] + this.vfVecX[MathFuncts.Mod(i + 1, this.gridSize), MathFuncts.Mod(j + 1, this.gridSize)]; * avgX /= 9f; * float avgY = this.vfVecY[MathFuncts.Mod(i - 1, this.gridSize), MathFuncts.Mod(j - 1, this.gridSize)] + this.vfVecY[i, MathFuncts.Mod(j - 1, this.gridSize)] + this.vfVecY[MathFuncts.Mod(i + 1, this.gridSize), MathFuncts.Mod(j - 1, this.gridSize)] + this.vfVecY[MathFuncts.Mod(i - 1, this.gridSize), j] + this.vfVecX[i, j] + this.vfVecY[MathFuncts.Mod(i + 1, this.gridSize), j] + this.vfVecY[MathFuncts.Mod(i - 1, this.gridSize), MathFuncts.Mod(j + 1, this.gridSize)] + this.vfVecY[i, MathFuncts.Mod(j + 1, this.gridSize)] + this.vfVecY[MathFuncts.Mod(i + 1, this.gridSize), MathFuncts.Mod(j + 1, this.gridSize)]; * avgY /= 9f; * * this.vfVecX[i, j] = avgX; * this.vfVecY[i, j] = avgY; * } * }*/ Parallel.For((long)0, this.pointSize, index => { int gridWidthIndex = (int)Math.Clamp(Math.Floor((this.gridSize - 1) / (float)this.width * this.posX[index]), 0, this.gridSize - 1); int gridHeightIndex = (int)Math.Clamp(Math.Floor((this.gridSize - 1) / (float)this.height * this.posY[index]), 0, this.gridSize - 1); this.vecX[index] += this.vfVecX[gridWidthIndex, gridHeightIndex] * this.vfFriction * 1f; this.vecY[index] += this.vfVecY[gridWidthIndex, gridHeightIndex] * this.vfFriction * 1f; this.vfVecX[gridWidthIndex, gridHeightIndex] += this.vecX[index] * this.pointFriction * deltaTime; this.vfVecY[gridWidthIndex, gridHeightIndex] += this.vecY[index] * this.pointFriction * deltaTime; if (RandomFuncts.GetRandomDouble(0, 1) < this.vfRandomReset) { this.ResetVectorField(gridWidthIndex, gridHeightIndex); } else { if (VectorFuncts.Length(this.vfVecX[gridWidthIndex, gridHeightIndex], this.vfVecY[gridWidthIndex, gridHeightIndex]) > this.vfMaxSpeed) { TweenFuncts.ExponentialSmoothing(ref this.vfVecX[gridWidthIndex, gridHeightIndex], this.vfSmoothingScalar); TweenFuncts.ExponentialSmoothing(ref this.vfVecY[gridWidthIndex, gridHeightIndex], this.vfSmoothingScalar); } } if (RandomFuncts.GetRandomDouble(0, 1) < this.pointRandomReset) { this.ResetPoint((int)index); } else { this.posX[index] += this.vecX[index] * deltaTime; this.posY[index] += this.vecY[index] * deltaTime; if (VectorFuncts.Length(this.vecX[index], this.vecY[index]) > this.pointMaxSpeed) { TweenFuncts.ExponentialSmoothing(ref this.vecX[index], this.pointSmoothingScalar); TweenFuncts.ExponentialSmoothing(ref this.vecY[index], this.pointSmoothingScalar); } } this.WrapAroundWindow((int)index); this.SetVertex((int)index); }); /*for (int i = 0; i < this.pointSize; i++) { * int gridWidthIndex = (int) Math.Clamp(Math.Floor((this.gridSize - 1) / (float) this.width * this.posX[i]), 0, this.gridSize - 1); * int gridHeightIndex = (int) Math.Clamp(Math.Floor((this.gridSize - 1) / (float) this.height * this.posY[i]), 0, this.gridSize - 1); * * this.vecX[i] += this.vfVecX[gridWidthIndex, gridHeightIndex] * this.vfFriction * 1f; * this.vecY[i] += this.vfVecY[gridWidthIndex, gridHeightIndex] * this.vfFriction * 1f; * this.vfVecX[gridWidthIndex, gridHeightIndex] += this.vecX[i] * this.pointFriction * deltaTime; * this.vfVecY[gridWidthIndex, gridHeightIndex] += this.vecY[i] * this.pointFriction * deltaTime; * * if (RandomFuncts.GetRandomDouble(0, 1) < this.vfRandomReset) { * this.ResetVectorField(gridWidthIndex, gridHeightIndex); * } * else { * if (VectorFuncts.Length(this.vfVecX[gridWidthIndex, gridHeightIndex], this.vfVecY[gridWidthIndex, gridHeightIndex]) > this.vfMaxSpeed) { * TweenFuncts.ExponentialSmoothing(ref this.vfVecX[gridWidthIndex, gridHeightIndex], this.vfSmoothingScalar); * TweenFuncts.ExponentialSmoothing(ref this.vfVecY[gridWidthIndex, gridHeightIndex], this.vfSmoothingScalar); * } * } * * if (RandomFuncts.GetRandomDouble(0, 1) < this.pointRandomReset) { * this.ResetPoint(i); * } * else { * this.posX[i] += this.vecX[i] * deltaTime; * this.posY[i] += this.vecY[i] * deltaTime; * * if (VectorFuncts.Length(this.vecX[i], this.vecY[i]) > this.pointMaxSpeed) { * TweenFuncts.ExponentialSmoothing(ref this.vecX[i], this.pointSmoothingScalar); * TweenFuncts.ExponentialSmoothing(ref this.vecY[i], this.pointSmoothingScalar); * } * } * * this.WrapAroundWindow(i); * this.SetVertex(i); * }*/ }