can anyone make the code shorter?
in
Programming Questions
•
2 years ago
just a newbie practice of translation and rotation with bad expandability...
i believe there're better ways...
- void setup() {
- size(400, 400);
- }
-
- void draw() {
- rect2();
- translate(200, 0);
- rect2();
- translate(0, 200);
- rect2();
- translate(-200, 0);
- rect2();
- }
-
- void rect1() {
- // make two rects
- rect(0, 0, 100, 100);
- line(0, 50, 100, 50);
- line(50, 0, 50, 100);
- rect(25, 25, 50, 50);
-
- rect(100, 0, 100, 100);
- for (int b=100; b<167;b+=33) {
- line(b, 0, b, 100);
- }
- }
-
- void rect2() {
- // make 2 pairs of rects
- pushMatrix();
- rect1();
- translate(200, 200);
- rotate(PI);
- rect1();
- popMatrix();
- }
1