Products
Features
YouTube Video Summarizer
Summarize YouTube videos
Web & PDF Highlighter
Highlight web pages & PDFs
Chat with PDF
Ask any PDF questions with AI
Ask AI Clone
Chat with your highlights & memories
Audio Transcriber
Transcribe audio files to text
Glasp Reader
Read and highlight articles
Kindle Highlight Export
Export your Kindle highlights
Idea Hatch
Hatch ideas from your highlights
Integrations
Obsidian Plugin
Notion Integration
Pocket Integration
Instapaper Integration
Medium Integration
Readwise Integration
Snipd Integration
Hypothesis Integration
Apps & Extensions
Chrome Extension
Safari Extension
Edge Add-ons
Firefox Add-ons
iOS App
Android App
Discover
Discover
Ideas
Discover new ideas and insights
Articles
Curated articles and insights
Books
Book recommendations by great minds
Posts
Essays and notes from readers
Quotes
Inspiring quotes collection
Videos
Curated videos and summaries
Explore Glasp
Glasp Newsletter
Weekly insights and updates
Glasp Talk
Interview series with great minds
Glasp Blog
Latest news and articles
Glasp Use Cases
Learn how others use Glasp
Build & Support
Glasp API
Access Glasp's API for developers
MCP Connector
Connect Glasp to Claude & ChatGPT
Community
Glasp Reddit Community
Students
Student discount and benefits
FAQs
Frequently Asked Questions
AboutPricing
DashboardLog inSign up

2.1: Variables in p5.js (mouseX, mouseY) - p5.js Tutorial

99.9K views
•
May 19, 2021
by
The Coding Train
YouTube video player
2.1: Variables in p5.js (mouseX, mouseY) - p5.js Tutorial

TL;DR

Learn about the flow of an animation program in p5.js, how to use variables to create dynamic elements, and explore event functions like mousePressed.

Transcript

Welcome to another p5.js video. This one, this is a really exciting, big moment. I don't know if you're aware of this. First of all, you might be wondering, I aged about 2 and 1/2 years since the last video in this series, not to mention the fact that one of those years was 2020. Maybe you're watching this in the future where I've redone the previo... Read More

Key Insights

  • 🏃 The flow of a p5.js program consists of a setup function that runs once, followed by a draw function that loops continuously.
  • 👻 By using variables, dynamic elements can be introduced into a p5.js sketch, allowing for interactive and animated visuals.
  • 🧘 System variables like mouseX and mouseY provide access to the current position of the mouse, enabling the creation of interactive elements that respond to user input.
  • 👻 Event functions in p5.js, such as mousePressed, allow for the definition of specific behaviors and actions triggered by user actions.
  • 👨‍💻 The order of code execution in p5.js can be controlled to create various effects and animations.
  • 😒 The use of background() function can create the illusion of animation by repeatedly drawing over previous frames.
  • 🫥 The end result of a p5.js sketch is only visible to the viewer when the draw function is completed, regardless of any internal changes made within the loop.

Install to Summarize YouTube Videos and Get Transcripts

Explore YouTube Video Summarizer or Get YouTube Transcript Extractor

Questions & Answers

Q: What is the difference between the setup and draw functions in p5.js?

The setup function is executed once at the beginning of the sketch, while the draw function is continuously looped afterwards. Setup is used for initialization, while draw contains the main code that runs repeatedly.

Q: How can variables be used in p5.js sketches?

Variables in p5.js store values and can be used to create dynamic elements. They can be used to control position, size, color, and other characteristics of objects in a sketch.

Q: What are system variables in p5.js?

System variables, such as mouseX and mouseY, are predefined variables in p5.js that store the current horizontal and vertical positions of the mouse on the canvas. They can be used to create interactive elements, like moving objects with the mouse.

Q: What are event functions in p5.js?

Event functions in p5.js are predefined functions that are triggered by specific user actions, such as mouse clicks or key presses. They can be used to create specific behaviors and interactions in a p5.js sketch.

Summary & Key Takeaways

  • The flow of a p5.js program consists of a setup function that executes once, and a draw function that loops continuously.

  • Variables are named entities that store values, and can be used to create dynamic elements in a p5.js sketch.

  • System variables like mouseX and mouseY can be used to create interactive elements in a sketch.

  • Mouse events, such as mousePressed, can be defined to create specific behaviors in a p5.js program.


Read in Other Languages (beta)

English

Share This Summary 📚

Summarize YouTube Videos and Get Video Transcripts with 1-Click

Download browser extensions on:

Try YouTube Summary with ChatGPT & Claude or YouTube Transcript Generator

Explore More Summaries from The Coding Train 📚

8.1: Fractals - The Nature of Code thumbnail
8.1: Fractals - The Nature of Code
The Coding Train
9.4: Genetic Algorithm: Looking at Code - The Nature of Code thumbnail
9.4: Genetic Algorithm: Looking at Code - The Nature of Code
The Coding Train
Text Generation using Spell with Nabil Hassein thumbnail
Text Generation using Spell with Nabil Hassein
The Coding Train
ITP/IMA Winter Show 2019 thumbnail
ITP/IMA Winter Show 2019
The Coding Train
Classifying Poses with ml5.js Part 2 thumbnail
Classifying Poses with ml5.js Part 2
The Coding Train
Coding Challenge #126: Toothpicks thumbnail
Coding Challenge #126: Toothpicks
The Coding Train

Summarize YouTube Videos and Get Video Transcripts with 1-Click

Download browser extensions on:

Try YouTube Summary with ChatGPT & Claude or YouTube Transcript Generator

Apps & Extensions

  • Chrome Extension
  • Safari Extension
  • Edge Add-ons
  • Firefox Add-ons
  • iOS App
  • Android App

Key Features

  • YouTube Video Summarizer
  • Web & PDF Summarizer
  • Web & PDF Highlighter
  • Chat with PDF
  • Ask AI Clone
  • Audio Transcriber
  • Glasp Reader
  • Kindle Highlight Export
  • Idea Hatch

Integrations

  • Obsidian Plugin
  • Notion Integration
  • Pocket Integration
  • Instapaper Integration
  • Medium Integration
  • Readwise Integration
  • Snipd Integration
  • Hypothesis Integration

More Features

  • APIs
  • MCP Connector
  • Blog & Post
  • Embed Links
  • Image Highlight
  • Personality Test
  • Quote Shots

Company

  • About us
  • Blog
  • Community
  • FAQs
  • Job Board
  • Newsletter
  • Pricing
Terms

•

Privacy

•

Guidelines

© 2026 Glasp Inc. All rights reserved.