Estoy dibujando rectángulos en una secuencia aleatoria, pero quiero dibujar líneas en la PARTE SUPERIOR de estos rectángulos, en la misma secuencia aleatoria, para crear un patrón como una capa encima de los rectángulos. ¿Por qué la última parte de mi código donde intento esto no es visible, las líneas están ubicadas después de los rectángulos, por lo que también deberían dibujarse después y, por lo tanto, en la parte superior?
<script src="https://cdn.jsdelivr.net/npm/processing-js@1.6.6/processing.min.js"></script> <script type="application/processing"> int spacing = 10; int x, y; int spacing2 = 10; int x2, y2; void setup() { size(800, 800); noStroke(); background(52, 122, 235); } void draw() { float j = random(2); if (j < 1) { if (j < 0.5) { fill(0, 0, 255); } if (j > 0.7) { fill(0, 0, 155); } rect(x, y, spacing, spacing); } x = x + spacing; if (x > width) { x = 0; y = y + spacing; } //WHY IS THE LINES NOT SHOWING UP? if (j > 1) { line(x, y, x + spacing, y + spacing); // "\" } else { line(x, y + spacing, x + spacing, y); // "/" } } </script> <canvas></canvas> <script src="https://cdn.jsdelivr.net/npm/processing-js@1.6.6/processing.min.js"></script> <script type="application/processing"> int spacing = 10; int x, y; int spacing2 = 10; int x2, y2; void setup() { size(800, 800); noStroke(); background(52, 122, 235); } void draw() { float j = random(2); if (j < 1) { noStroke(); if (j < 0.5) { fill(0, 0, 255); } if (j > 0.7) { fill(0, 0, 155); } rect(x, y, spacing, spacing); } x = x + spacing; if (x > width) { x = 0; y = y + spacing; } // This wasn't showing up because there was no stroke color specified and // you call noStroke() in setup. stroke(255, 0, 0); if (j > 1) { line(x, y, x + spacing, y + spacing); // "\" } else { line(x, y + spacing, x + spacing, y); // "/" } } </script> <canvas></canvas>