ModulatedEllipseクラスにサイン波で楕円を変調する機能を追加しました
ModulatedEllipseクラスに以下の4メソッドを追加しました。
setSineEffectRatio()
setSineFrequency()
setSinePhase()
setSinePowerValue()
setSineEffectRatio()で、サイン波変調の効き具合を指定できます。範囲は0.0〜1.0で、値が高いほど効果が強くなります。
setSineFrequency()では、サイン波変調の周期波の繰り返し回数を指定できます。楕円は指定された回数の小片に分けられます。引数は整数で指定します。
setSinePhase()では、サイン波変調の角度を指定できます。引数の単位はラジアンです。
setSinePowerValue()では、サイン波変調に変化を与えることができます。引数が大きいほど、分割された小片の幅が太くなります。
以下はソースコードです。開発環境はMacBook Air、Processingです。
ModulatedEllipseSample.pde
// ModulatedEllipseSample final int cMyWidth = 1280; final int cMyHeight = 720; ModulatedEllipse e; void settings() { size(cMyWidth, cMyHeight); } void setup() { noLoop(); } void draw() { float cellWidth = width / 6; float cellHeight = height / 3; e = new ModulatedEllipse(0, 0, cellWidth - 10, cellHeight - 10); int i; float x = cellWidth / 2; float y = cellHeight / 2; e.setNoiseSmoothRatio(1.0); e.setNoiseEffectRatio(0.0); e.setNoiseSymmetry(false); e.setVertexNum(628); e.setXCoordinateBase(0); e.setSineEffectRatio(1.0); e.setSineFrequency(1); e.setSinePhase(0.0); e.setSinePowerValue(1.0); for (i = 0; i < 6; i++) { e.setPosition(x, y); e.setSineFrequency(i + 1); e.draw(); fill(0); text("NoiseSmoothRatio:" + e.getNoiseSmoothRatio(), x - cellWidth / 2, y - cellHeight / 2 + 10); text("NoiseEffectRatio:" + e.getNoiseEffectRatio(), x - cellWidth / 2, y - cellHeight / 2 + 25); text("NoiseSymmetry:" + e.getNoiseSymmetry(), x - cellWidth / 2, y - cellHeight / 2 + 40); text("VertexNum:" + e.getVertexNum(), x - cellWidth / 2, y - cellHeight / 2 + 55); text("XCoordinateBase:" + e.getXCoordinateBase(), x - cellWidth / 2, y - cellHeight / 2 + 70); text("SineEffectRatio:" + e.getSineEffectRatio(), x - cellWidth / 2, y - cellHeight / 2 + 85); text("SineFrequency:" + e.getSineFrequency(), x - cellWidth / 2, y - cellHeight / 2 + 100); text("SinePhase:" + e.getSinePhase(), x - cellWidth / 2, y - cellHeight / 2 + 115); text("SinePowerValue:" + e.getSinePowerValue(), x - cellWidth / 2, y - cellHeight / 2 + 130); fill(255); x += cellWidth; } x = cellWidth / 2; y += cellHeight; e.setNoiseSmoothRatio(1.0); e.setNoiseEffectRatio(0.0); e.setNoiseSymmetry(false); e.setVertexNum(628); e.setXCoordinateBase(0); e.setSineEffectRatio(0.8); e.setSineFrequency(1); e.setSinePhase(0.0); e.setSinePowerValue(1.0); for (i = 0; i < 6; i++) { e.setPosition(x, y); e.setSineFrequency(i + 1); e.draw(); fill(0); text("NoiseSmoothRatio:" + e.getNoiseSmoothRatio(), x - cellWidth / 2, y - cellHeight / 2 + 10); text("NoiseEffectRatio:" + e.getNoiseEffectRatio(), x - cellWidth / 2, y - cellHeight / 2 + 25); text("NoiseSymmetry:" + e.getNoiseSymmetry(), x - cellWidth / 2, y - cellHeight / 2 + 40); text("VertexNum:" + e.getVertexNum(), x - cellWidth / 2, y - cellHeight / 2 + 55); text("XCoordinateBase:" + e.getXCoordinateBase(), x - cellWidth / 2, y - cellHeight / 2 + 70); text("SineEffectRatio:" + e.getSineEffectRatio(), x - cellWidth / 2, y - cellHeight / 2 + 85); text("SineFrequency:" + e.getSineFrequency(), x - cellWidth / 2, y - cellHeight / 2 + 100); text("SinePhase:" + e.getSinePhase(), x - cellWidth / 2, y - cellHeight / 2 + 115); text("SinePowerValue:" + e.getSinePowerValue(), x - cellWidth / 2, y - cellHeight / 2 + 130); fill(255); x += cellWidth; } x = cellWidth / 2; y += cellHeight; e.setNoiseSmoothRatio(0.0); e.setNoiseEffectRatio(0.3); e.setNoiseSymmetry(false); e.setVertexNum(628); e.setXCoordinateBase(0); e.setSineEffectRatio(0.8); e.setSineFrequency(1); e.setSinePhase(0.0); e.setSinePowerValue(1.0); for (i = 0; i < 6; i++) { e.setPosition(x, y); e.setSineFrequency(i + 1); e.draw(); fill(0); text("NoiseSmoothRatio:" + e.getNoiseSmoothRatio(), x - cellWidth / 2, y - cellHeight / 2 + 10); text("NoiseEffectRatio:" + e.getNoiseEffectRatio(), x - cellWidth / 2, y - cellHeight / 2 + 25); text("NoiseSymmetry:" + e.getNoiseSymmetry(), x - cellWidth / 2, y - cellHeight / 2 + 40); text("VertexNum:" + e.getVertexNum(), x - cellWidth / 2, y - cellHeight / 2 + 55); text("XCoordinateBase:" + e.getXCoordinateBase(), x - cellWidth / 2, y - cellHeight / 2 + 70); text("SineEffectRatio:" + e.getSineEffectRatio(), x - cellWidth / 2, y - cellHeight / 2 + 85); text("SineFrequency:" + e.getSineFrequency(), x - cellWidth / 2, y - cellHeight / 2 + 100); text("SinePhase:" + e.getSinePhase(), x - cellWidth / 2, y - cellHeight / 2 + 115); text("SinePowerValue:" + e.getSinePowerValue(), x - cellWidth / 2, y - cellHeight / 2 + 130); fill(255); x += cellWidth; } } //void draw() //{ // float cellWidth = width / 6; // float cellHeight = height / 3; // e = new ModulatedEllipse(0, 0, cellWidth - 10, cellHeight - 10); // int i; // float x = cellWidth / 2; // float y = cellHeight / 2; // e.setNoiseSmoothRatio(1.0); // e.setNoiseEffectRatio(0.0); // e.setNoiseSymmetry(false); // e.setVertexNum(628); // e.setXCoordinateBase(0); // e.setSineEffectRatio(1.0); // e.setSineFrequency(1); // e.setSinePhase(0.0); // e.setSinePowerValue(1.0); // for (i = 0; i < 6; i++) // { // e.setPosition(x, y); // e.setSinePhase(PI * i / 5); // e.draw(); // fill(0); // text("NoiseSmoothRatio:" + e.getNoiseSmoothRatio(), x - cellWidth / 2, y - cellHeight / 2 + 10); // text("NoiseEffectRatio:" + e.getNoiseEffectRatio(), x - cellWidth / 2, y - cellHeight / 2 + 25); // text("NoiseSymmetry:" + e.getNoiseSymmetry(), x - cellWidth / 2, y - cellHeight / 2 + 40); // text("VertexNum:" + e.getVertexNum(), x - cellWidth / 2, y - cellHeight / 2 + 55); // text("XCoordinateBase:" + e.getXCoordinateBase(), x - cellWidth / 2, y - cellHeight / 2 + 70); // text("SineEffectRatio:" + e.getSineEffectRatio(), x - cellWidth / 2, y - cellHeight / 2 + 85); // text("SineFrequency:" + e.getSineFrequency(), x - cellWidth / 2, y - cellHeight / 2 + 100); // text("SinePhase:" + e.getSinePhase(), x - cellWidth / 2, y - cellHeight / 2 + 115); // text("SinePowerValue:" + e.getSinePowerValue(), x - cellWidth / 2, y - cellHeight / 2 + 130); // fill(255); // x += cellWidth; // } // x = cellWidth / 2; // y += cellHeight; // e.setNoiseSmoothRatio(1.0); // e.setNoiseEffectRatio(0.0); // e.setNoiseSymmetry(false); // e.setVertexNum(628); // e.setXCoordinateBase(0); // e.setSineEffectRatio(1.0); // e.setSineFrequency(1); // e.setSinePhase(0.0); // e.setSinePowerValue(1.0); // for (i = 0; i < 6; i++) // { // e.setPosition(x, y); // e.setSinePhase(PI + PI * i / 5); // e.draw(); // fill(0); // text("NoiseSmoothRatio:" + e.getNoiseSmoothRatio(), x - cellWidth / 2, y - cellHeight / 2 + 10); // text("NoiseEffectRatio:" + e.getNoiseEffectRatio(), x - cellWidth / 2, y - cellHeight / 2 + 25); // text("NoiseSymmetry:" + e.getNoiseSymmetry(), x - cellWidth / 2, y - cellHeight / 2 + 40); // text("VertexNum:" + e.getVertexNum(), x - cellWidth / 2, y - cellHeight / 2 + 55); // text("XCoordinateBase:" + e.getXCoordinateBase(), x - cellWidth / 2, y - cellHeight / 2 + 70); // text("SineEffectRatio:" + e.getSineEffectRatio(), x - cellWidth / 2, y - cellHeight / 2 + 85); // text("SineFrequency:" + e.getSineFrequency(), x - cellWidth / 2, y - cellHeight / 2 + 100); // text("SinePhase:" + e.getSinePhase(), x - cellWidth / 2, y - cellHeight / 2 + 115); // text("SinePowerValue:" + e.getSinePowerValue(), x - cellWidth / 2, y - cellHeight / 2 + 130); // fill(255); // x += cellWidth; // } // x = cellWidth / 2; // y += cellHeight; // e.setNoiseSmoothRatio(0.0); // e.setNoiseEffectRatio(0.3); // e.setNoiseSymmetry(false); // e.setVertexNum(628); // e.setXCoordinateBase(0); // e.setSineEffectRatio(1.0); // e.setSineFrequency(1); // e.setSinePhase(0.0); // e.setSinePowerValue(1.0); // for (i = 0; i < 6; i++) // { // e.setPosition(x, y); // e.setSinePhase(PI * i / 5); // e.draw(); // fill(0); // text("NoiseSmoothRatio:" + e.getNoiseSmoothRatio(), x - cellWidth / 2, y - cellHeight / 2 + 10); // text("NoiseEffectRatio:" + e.getNoiseEffectRatio(), x - cellWidth / 2, y - cellHeight / 2 + 25); // text("NoiseSymmetry:" + e.getNoiseSymmetry(), x - cellWidth / 2, y - cellHeight / 2 + 40); // text("VertexNum:" + e.getVertexNum(), x - cellWidth / 2, y - cellHeight / 2 + 55); // text("XCoordinateBase:" + e.getXCoordinateBase(), x - cellWidth / 2, y - cellHeight / 2 + 70); // text("SineEffectRatio:" + e.getSineEffectRatio(), x - cellWidth / 2, y - cellHeight / 2 + 85); // text("SineFrequency:" + e.getSineFrequency(), x - cellWidth / 2, y - cellHeight / 2 + 100); // text("SinePhase:" + e.getSinePhase(), x - cellWidth / 2, y - cellHeight / 2 + 115); // text("SinePowerValue:" + e.getSinePowerValue(), x - cellWidth / 2, y - cellHeight / 2 + 130); // fill(255); // x += cellWidth; // } //} //void draw() //{ // float cellWidth = width / 6; // float cellHeight = height / 3; // e = new ModulatedEllipse(0, 0, cellWidth - 10, cellHeight - 10); // int i; // float x = cellWidth / 2; // float y = cellHeight / 2; // e.setNoiseSmoothRatio(1.0); // e.setNoiseEffectRatio(0.0); // e.setNoiseSymmetry(false); // e.setVertexNum(628); // e.setXCoordinateBase(0); // e.setSineEffectRatio(1.0); // e.setSineFrequency(1); // e.setSinePhase(0.0); // e.setSinePowerValue(0.5); // for (i = 0; i < 6; i++) // { // e.setPosition(x, y); // e.setSineFrequency(i + 1); // e.draw(); // fill(0); // text("NoiseSmoothRatio:" + e.getNoiseSmoothRatio(), x - cellWidth / 2, y - cellHeight / 2 + 10); // text("NoiseEffectRatio:" + e.getNoiseEffectRatio(), x - cellWidth / 2, y - cellHeight / 2 + 25); // text("NoiseSymmetry:" + e.getNoiseSymmetry(), x - cellWidth / 2, y - cellHeight / 2 + 40); // text("VertexNum:" + e.getVertexNum(), x - cellWidth / 2, y - cellHeight / 2 + 55); // text("XCoordinateBase:" + e.getXCoordinateBase(), x - cellWidth / 2, y - cellHeight / 2 + 70); // text("SineEffectRatio:" + e.getSineEffectRatio(), x - cellWidth / 2, y - cellHeight / 2 + 85); // text("SineFrequency:" + e.getSineFrequency(), x - cellWidth / 2, y - cellHeight / 2 + 100); // text("SinePhase:" + e.getSinePhase(), x - cellWidth / 2, y - cellHeight / 2 + 115); // text("SinePowerValue:" + e.getSinePowerValue(), x - cellWidth / 2, y - cellHeight / 2 + 130); // fill(255); // x += cellWidth; // } // x = cellWidth / 2; // y += cellHeight; // e.setNoiseSmoothRatio(1.0); // e.setNoiseEffectRatio(0.0); // e.setNoiseSymmetry(false); // e.setVertexNum(628); // e.setXCoordinateBase(0); // e.setSineEffectRatio(0.8); // e.setSineFrequency(1); // e.setSinePhase(0.0); // e.setSinePowerValue(3.0); // for (i = 0; i < 6; i++) // { // e.setPosition(x, y); // e.setSineFrequency(i + 1); // e.draw(); // fill(0); // text("NoiseSmoothRatio:" + e.getNoiseSmoothRatio(), x - cellWidth / 2, y - cellHeight / 2 + 10); // text("NoiseEffectRatio:" + e.getNoiseEffectRatio(), x - cellWidth / 2, y - cellHeight / 2 + 25); // text("NoiseSymmetry:" + e.getNoiseSymmetry(), x - cellWidth / 2, y - cellHeight / 2 + 40); // text("VertexNum:" + e.getVertexNum(), x - cellWidth / 2, y - cellHeight / 2 + 55); // text("XCoordinateBase:" + e.getXCoordinateBase(), x - cellWidth / 2, y - cellHeight / 2 + 70); // text("SineEffectRatio:" + e.getSineEffectRatio(), x - cellWidth / 2, y - cellHeight / 2 + 85); // text("SineFrequency:" + e.getSineFrequency(), x - cellWidth / 2, y - cellHeight / 2 + 100); // text("SinePhase:" + e.getSinePhase(), x - cellWidth / 2, y - cellHeight / 2 + 115); // text("SinePowerValue:" + e.getSinePowerValue(), x - cellWidth / 2, y - cellHeight / 2 + 130); // fill(255); // x += cellWidth; // } // x = cellWidth / 2; // y += cellHeight; // e.setNoiseSmoothRatio(1.0); // e.setNoiseEffectRatio(0.0); // e.setNoiseSymmetry(false); // e.setVertexNum(628); // e.setXCoordinateBase(0); // e.setSineEffectRatio(0.8); // e.setSineFrequency(1); // e.setSinePhase(0.0); // e.setSinePowerValue(10.0); // for (i = 0; i < 6; i++) // { // e.setPosition(x, y); // e.setSineFrequency(i + 1); // e.draw(); // fill(0); // text("NoiseSmoothRatio:" + e.getNoiseSmoothRatio(), x - cellWidth / 2, y - cellHeight / 2 + 10); // text("NoiseEffectRatio:" + e.getNoiseEffectRatio(), x - cellWidth / 2, y - cellHeight / 2 + 25); // text("NoiseSymmetry:" + e.getNoiseSymmetry(), x - cellWidth / 2, y - cellHeight / 2 + 40); // text("VertexNum:" + e.getVertexNum(), x - cellWidth / 2, y - cellHeight / 2 + 55); // text("XCoordinateBase:" + e.getXCoordinateBase(), x - cellWidth / 2, y - cellHeight / 2 + 70); // text("SineEffectRatio:" + e.getSineEffectRatio(), x - cellWidth / 2, y - cellHeight / 2 + 85); // text("SineFrequency:" + e.getSineFrequency(), x - cellWidth / 2, y - cellHeight / 2 + 100); // text("SinePhase:" + e.getSinePhase(), x - cellWidth / 2, y - cellHeight / 2 + 115); // text("SinePowerValue:" + e.getSinePowerValue(), x - cellWidth / 2, y - cellHeight / 2 + 130); // fill(255); // x += cellWidth; // } //}
ModulatedEllipse.pde
// ModulatedEllipse class ModulatedEllipse { float mCenterX = 0; float mCenterY = 0; float mDiameterH = 100; float mDiameterV = 100; float mNoiseSmoothRatio = 1.0; float mNoiseRoughnessCoefficient = 0.0; float mNoiseEffectRatio = 0.5; boolean mNoiseSymmetryFlg = false; int mVertexNum = 628; int mXCoordinateBase = 0; float mSineEffectRatio = 1.0; float mSineFrequency = 1.0; float mSinePhase = 0.0; float mSinePowerValue = 1.0; ModulatedEllipse(float x, float y, float h, float v) { mCenterX = x; mCenterY = y; mDiameterH = h; mDiameterV = v; } void setPosition(float x, float y) { mCenterX = x; mCenterY = y; } void setNoiseSmoothRatio(float r) { mNoiseSmoothRatio = r; mNoiseRoughnessCoefficient = map((1.0 - mNoiseSmoothRatio), 0, 1.0, 0.005, 0.1); } float getNoiseSmoothRatio() { return mNoiseSmoothRatio; } void setNoiseEffectRatio(float r) { mNoiseEffectRatio = r; } float getNoiseEffectRatio() { return mNoiseEffectRatio; } void setNoiseSymmetry(boolean f) { mNoiseSymmetryFlg = f; } boolean getNoiseSymmetry() { return mNoiseSymmetryFlg; } void setVertexNum(int n) { mVertexNum = n; } int getVertexNum() { return int(mVertexNum); } void setXCoordinateBase(int c) { mXCoordinateBase = c; } int getXCoordinateBase() { return mXCoordinateBase; } void setSineEffectRatio(float r) { mSineEffectRatio = r; } float getSineEffectRatio() { return mSineEffectRatio; } void setSineFrequency(int f) { mSineFrequency = f; } int getSineFrequency() { return int(mSineFrequency); } void setSinePhase(float p) { mSinePhase = p; } float getSinePhase() { return mSinePhase; } void setSinePowerValue(float v) { mSinePowerValue = v; } float getSinePowerValue() { return mSinePowerValue; } void draw() { float h = mDiameterH / 2.0; float v = mDiameterV / 2.0; int xCoordinate = 1; int cnt = 0; float theta = 0.0; beginShape(); for (cnt = -1; cnt <= mVertexNum + 1; cnt++) { theta = TWO_PI * cnt / mVertexNum; if (mNoiseSymmetryFlg) { if (cnt < 0) { xCoordinate = 2; } else if (cnt >= mVertexNum) { xCoordinate = 1 + cnt % mVertexNum; } else { if (cnt > int(mVertexNum / 2.0)) { xCoordinate = int(mVertexNum / 2.0) - (cnt - int(mVertexNum / 2.0)); } else { xCoordinate = cnt + 1; } } } else { if (cnt < 0) { xCoordinate = mVertexNum; } else if (cnt >= mVertexNum) { xCoordinate = 1 + cnt % mVertexNum; } else { xCoordinate = cnt + 1; } } curveVertex( mCenterX + cos(-HALF_PI + theta) * h * (1.0 - noise(mXCoordinateBase + xCoordinate * mNoiseRoughnessCoefficient) * mNoiseEffectRatio) * (1.0 - pow(abs(sin((theta * mSineFrequency - mSinePhase) / 2.0)), mSinePowerValue) * mSineEffectRatio), mCenterY + sin(-HALF_PI + theta) * v * (1.0 - noise(mXCoordinateBase + xCoordinate * mNoiseRoughnessCoefficient) * mNoiseEffectRatio) * (1.0 - pow(abs(sin((theta * mSineFrequency - mSinePhase) / 2.0)), mSinePowerValue) * mSineEffectRatio)); } endShape(CLOSE); } }