User Tools

Site Tools


programmering:breathe-js-code

Requires the p5.js library

  var thick=8;

  function setup() {
    createCanvas(windowWidth,windowHeight); 
  }

  function displayStartText() {
    var start_text="Space to start/stop";
    textFont("Courier");
    textSize(32);
    text(start_text,0.5*(width-textWidth(start_text)),0.5*(height-16))
  }

  function keyPressed() {
    if (!fullscreen()) {
      if (key == ' ') fullscreen(true);
      resizeCanvas(displayWidth,displayHeight);
      loop();
    } else {
      fullscreen(false);
      resizeCanvas(windowWidth,windowHeight);
    }
  }

  function draw() {
    background(240);
    if (!fullscreen()) {
      displayStartText();
      noLoop();
      return;
    }
    noStroke();
    fill(0);
    triangle(0,0,
             0,height,
             8,height);
    triangle(0,0,
             0,height,
             8,height);
    for (i=2*thick; i<width; i+=2*thick) {
      triangle(i+random(10),0,
               i-thick,height,
               i+thick,height);
    }
  }
programmering/breathe-js-code.txt · Last modified: 2023/10/21 19:19 by 127.0.0.1

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki