use of edu.mit.d54.Display2D in project d54 by mitrisdev.
the class TestPlugin method loop.
@Override
protected void loop() {
Display2D display = getDisplay();
time += dt;
for (int x = 0; x < display.getWidth(); x++) {
for (int y = 0; y < display.getHeight(); y++) {
display.setPixelHSB(x, y, (float) (x + y + time * 3) / 36.f, 1f, 1f);
}
}
}
use of edu.mit.d54.Display2D in project d54 by mitrisdev.
the class Erl30Plugin method loop.
@Override
protected void loop() {
Display2D display = getDisplay();
time += dt;
Graphics2D g = display.getGraphics();
float timeInLoop;
float timeInSegment;
int segment1Length = 5;
int segment2Length = 10;
int segment3Length = (int) Math.ceil((255 + 2 * 17) * dt);
int transitionLength = 1;
int totalLength = segment1Length + segment2Length + segment3Length;
float maxBrightness;
int[][] ErlCoords = { { 0, 0 }, { 0, 1 }, { 0, 2 }, { 1, 0 }, { 2, 0 }, { 2, 1 }, { 3, 0 }, { 4, 0 }, { 4, 1 }, { 4, 2 }, { 6, 0 }, { 6, 1 }, { 6, 2 }, { 7, 0 }, { 7, 2 }, { 8, 0 }, { 8, 1 }, { 9, 0 }, { 9, 2 }, { 10, 0 }, { 10, 2 }, { 12, 0 }, { 13, 0 }, { 14, 0 }, { 15, 0 }, { 16, 0 }, { 16, 1 }, { 16, 2 } };
int[][] ThirtyCoords = { { 1, 5 }, { 1, 6 }, { 1, 7 }, { 2, 4 }, { 2, 8 }, { 3, 8 }, { 4, 7 }, { 5, 8 }, { 6, 4 }, { 6, 8 }, { 7, 5 }, { 7, 6 }, { 7, 7 }, { 9, 5 }, { 9, 6 }, { 9, 7 }, { 10, 4 }, { 10, 8 }, { 11, 4 }, { 11, 8 }, { 12, 4 }, { 12, 8 }, { 13, 4 }, { 13, 8 }, { 14, 4 }, { 14, 8 }, { 15, 5 }, { 15, 6 }, { 15, 7 } };
float brightness = 0f;
timeInLoop = (float) time % totalLength;
if (timeInLoop < 0.5 * dt) {
loopNum = (loopNum + 1) % 3;
}
// Segment 1
if (timeInLoop >= 0 && timeInLoop < segment1Length) {
timeInSegment = timeInLoop;
int framesInSegment = (int) Math.round(timeInSegment / dt);
maxBrightness = 1f;
g.drawImage(waveimg[loopNum][framesInSegment], 0, 0, null);
} else // Segment 2
if (timeInLoop >= segment1Length && timeInLoop < segment1Length + segment2Length) {
timeInSegment = timeInLoop - segment1Length;
if (timeInSegment <= transitionLength) {
maxBrightness = timeInSegment / transitionLength;
} else if (segment2Length - timeInSegment <= transitionLength) {
maxBrightness = (segment2Length - timeInSegment) / transitionLength;
} else {
maxBrightness = 1f;
}
for (int idx = 0; idx < ErlCoords.length; idx++) {
int y = ErlCoords[idx][0];
int x = ErlCoords[idx][1];
if (y <= 5)
display.setPixelHSB(x, y, 0f, 0.5f, 1f * maxBrightness);
else if (y <= 10)
display.setPixelHSB(x, y, 0f, 0.67f, 0.7f * maxBrightness);
else
display.setPixelHSB(x, y, 0f, 0.85f, 0.3f * maxBrightness);
}
for (int idx = 0; idx < ThirtyCoords.length; idx++) {
int y = ThirtyCoords[idx][0];
int x = ThirtyCoords[idx][1];
if ((int) (Math.random() * (5)) == 0) {
brightness = 1f;
} else {
brightness = 0.5f;
}
display.setPixelHSB(x, y, 1f, 0f, brightness * maxBrightness);
}
} else // Segment 3
if (timeInLoop >= segment1Length + segment2Length && timeInLoop < totalLength) {
timeInSegment = timeInLoop - segment1Length - segment2Length;
g.drawImage(erlScrollingText, 0, -(255 + 17) + (int) Math.round(timeInSegment / dt), null);
}
}
use of edu.mit.d54.Display2D in project d54 by mitrisdev.
the class FlagPlugin method loop.
@Override
protected void loop() {
float wavePeriodT = Float.parseFloat(getKnobValue("wavePeriodT"));
float wavePeriodX = Float.parseFloat(getKnobValue("wavePeriodX"));
float wavePeriodY = Float.parseFloat(getKnobValue("wavePeriodY"));
float waveDepth = Float.parseFloat(getKnobValue("waveDepth"));
Display2D d = getDisplay();
for (int x = 0; x < d.getWidth(); x++) {
for (int y = 0; y < d.getHeight(); y++) {
float intensity = (float) ((1 - (waveDepth / 2)) + (waveDepth / 2) * Math.cos((getTime() / wavePeriodT + x / wavePeriodX + y / wavePeriodY) * 2 * Math.PI));
if (x < 5 && y < 7) {
if ((x + y) % 2 == 0)
d.setPixelHSB(x, y, 0.666f, 1, intensity);
else
d.setPixelHSB(x, y, 0, 0, intensity);
} else {
if (x % 2 == 0)
d.setPixelHSB(x, y, 0, 1, intensity);
else
d.setPixelHSB(x, y, 0, 0, intensity);
}
}
}
}
Aggregations