xxxxxxxxxx
/**
* Star Waves (v1.1.4)
* by canslp
* mod GoToLoop (2023/Jul/07)
*
* Discourse.Processing.org/t/am-i-allowed-to-use-pgraphics-in-html/42375/2
*
* OpenProcessing.org/sketch/1968681
*/
static final color
C_BLACK = #001920,
C_WHITE = #004357,
C_LIGHT = #FFC800,
C_ACCENT = #B3337C;
static final int
STARS = 50,
W = 256, H = 128,
HH = H * 3 >> 2;
PGraphics pg;
PImage im;
boolean paused;
void setup() {
size(640, 384);
noSmooth();
initGraphics();
}
void draw() {
renderGame();
}
void mousePressed() {
if (paused ^= true) noLoop();
else loop();
}
void initGraphics() {
pg = createGraphics(W, H);
pg.beginDraw();
pg.noSmooth();
pg.stroke(C_WHITE);
pg.endDraw();
im = createImage(W, HH - 10, RGB);
for (int i = 0; i < im.pixels.length; im.pixels[i++] = C_BLACK);
for (int i = 0; i < STARS; ++i)
im.pixels[(int) random(im.pixels.length)] = C_WHITE;
im.updatePixels();
}
void renderGame() {
final int c = frameCount;
pg.beginDraw();
pg.background(C_BLACK);
pg.set(0, 0, im);
pg.endDraw();
pg.loadPixels();
for (int x = 0; x < W; ++x) {
final int
y1 = round(sin(.2*x + .1*c) + sin(-.1*x - .2*c) + 3*sin(.02*(x+c))),
y2 = round(sin(-.2*x - .05*c) + sin(.1*x + .1*c) + 3*sin(.02*(x+c))),
idx1 = (y1 + HH) * W + x,
idx2 = (y2 + HH) * W + x;
pg.pixels[idx1] = C_WHITE;
pg.pixels[idx2] = C_WHITE;
}
pg.updatePixels();
image(pg, 0, 0, width, height);
}