Code organization

yes that “>” little arrow is much too small!

ok, i give up,
i print it here:


sketch.js

function setup() {
  createCanvas(400, 400);
  rectMode(CENTER);
}

function draw() {
  background(200,200,0);
  translate(width/2,height/2);
  my_rectangle();    // see file my_function.js / see index.html
}

my_function.js

/* 
 file: my_function.js
 called in index.html
 used   in sketch.js
*/

function my_rectangle() {
  push();
  fill(0, 200, 0);
  stroke(0, 0, 200);
  strokeWeight(20);
  rect(0, 0, 100, 100);
  pop();
}

index.html

<!DOCTYPE html>
<html>
  <head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.3/p5.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.3/addons/p5.dom.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.3/addons/p5.sound.min.js"></script>
    <link rel="stylesheet" type="text/css" href="style.css">
    <meta charset="utf-8" />

  </head>
  <body>
    <script src="sketch.js"></script>
    <script src="my_function.js"></script>   <!--- add --->
  </body>
</html>

1 Like