GRK TUT1 Task4

by linoskoczek

HTML

<script src="//cdnjs.cloudflare.com/ajax/libs/p5.js/0.5.7/p5.js"></script>
<script>
  function setup() {
    createCanvas(800, 600);
    fill(204, 101, 192, 127);
    noLoop();
    frameRate(25);
  }

  function draw() {
    //noprotect
    background(166, 140, 235);
    rectanglex(200, 200, 400, 260, 80, 16, 27);
    rectanglex(0, 400, 800, 200, 0, 102, 0);
    kupaOnTheGrass(0, 400, 800, 200);
    trianglex(140, 50, 515, 150, 255, 102, 102);
  }

  function rectanglex(startx, starty, width, height, r, g, b) {
    for (y = starty; y < (starty + height); y++)
      for (x = startx; x < (startx + width); x++) {
        set(x, y, color(r, g, b));
      }
    updatePixels();
  }

  function trianglex(startx, starty, width, height, r, g, b) {
    start = startx + width / 2;
    end = start;
    for (y = starty; y < (starty + height); y++) {
      for (x = startx; x < (startx + width); x++) {
        if (x > start && x <= end)
          set(x, y, color(r, g, b));
      }
      d = width / (height * 2);
      start -= d
      end += d;
    }
    updatePixels();
  }

  function kupaOnTheGrass(startx, starty, width, height) {
    for (i = 0; i < 1000; i++) {
      x = floor(random(startx, startx + width));
      y = floor(random(starty, starty + height));
      set(x, y, color(random(0,255)));
    }
  }

</script>