ICL
  • Intro to Computational Language
  • Academic Policy
  • Week 01
  • Week 02
  • Week 03
  • Week 04
  • Week 05
  • Week 06
  • Week 07
  • Week 08
  • Week 09
  • Week 10
  • Week 11
  • Week 12
  • Week 13
  • Week 14
  • Week 15
  • Portfolio
Powered by GitBook
On this page
  • 1. Multiple JS files
  • 2. DOM element and Callback Function
  • P5.dom library
  • Example
  • Example
  • Example
  • Callback function
  • Callback is simply one function is called and the other function is continuously called.
  • Example
  • Assignment

Week 07

Multiple JS, DOM, Events and Callback Function

PreviousWeek 06NextWeek 08

Last updated 6 years ago

Week6 #7

1. Multiple JS files

You can keep your file in a separate js file.

2. DOM element and Callback Function

Document Object Model (DOM)

<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.2/addons/p5.dom.min.js"></script>

P5.dom library

Example

Example

Example

Callback function

Callback function is simple that

  1. The function createButton is attached to the variable button.

  2. And when the button is pressed, I want changeColor function os called.

    button.mousePressed(changeColor);

Callback is simply one function is called and the other function is continuously called.

  var button = createButton("Color??");
  button.mousePressed(changeColor);

Example

Assignment

  1. Have multiple .js file (at least 2)

  2. Have DOM element (it can be anything, button, slider, check, wordform, etc)

https://editor.p5js.org/kdoodoo/sketches/B1yC6roi7
https://p5js.org/reference/#/libraries/p5.dom
https://editor.p5js.org/kdoodoo/sketches/rJfcgPsjm
https://editor.p5js.org/kdoodoo/sketches/rJ9XZwijm
https://editor.p5js.org/kdoodoo/sketches/SJfe7PjsX
https://editor.p5js.org/kdoodoo/sketches/rJS8rDjsm
https://goo.gl/forms/BLQxwU8giiMkDzxk2