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

7.6: Clicking on Objects - p5.js Tutorial

104.3K views
•
October 9, 2015
by
The Coding Train
YouTube video player
7.6: Clicking on Objects - p5.js Tutorial

TL;DR

Learn how to handle events in JavaScript using P5.js and apply them to objects in a canvas.

Transcript

hi so uh I've been working with this same exact example in a bunch of videos now the previous one all I did was take the code for the bubble Constructor function and move it to a separate tab so we can now look at it on its own and so what I want to do in this video is figure out how do I like essentially uh uh uh uh uh handle what to do if I click... Read More

Key Insights

  • 🍵 P5.js handles events in JavaScript, such as the mousePressed event, by automatically triggering a function when the event occurs.
  • 🪡 To attach events to individual objects in P5.js, you need to manually call a function within the object when the event occurs.
  • 🍵 When handling events, you can perform various actions on objects, such as changing their color, size, shape, or movement.
  • 😥 P5.js provides useful functions like "distance" to help calculate the distance between two points, making it easier to determine if an object was clicked within a certain radius.
  • 👻 Using variables for object properties, such as color or size, allows for flexible and reusable code.
  • ⚾ Experimenting with different event-based actions can enhance the interactivity and functionality of P5.js projects.
  • 🕸️ The integration of events in P5.js is a fundamental concept that can be applied to different elements and functionalities on a web page.

Install to Summarize YouTube Videos and Get Transcripts

Explore YouTube Video Summarizer or Get YouTube Transcript Extractor

Questions & Answers

Q: How does P5.js handle events in JavaScript?

P5.js automatically triggers the "mousePressed" event in response to a mouse click, allowing you to execute specific code when the event occurs.

Q: Can I add the "mousePressed" function directly into an object in P5.js?

While you could add a function called "mousePressed" to an object, it won't automatically be triggered. Instead, you need to manually call the function in the "mousePressed" event of the object.

Q: How can I change the color of a circle when it is clicked in P5.js?

By adding a variable for the color and checking the distance between the mouse and the circle's center, you can change the color of the circle if the mouse is inside the circle.

Q: What improvements can be made to the code for handling events in P5.js?

Some possible improvements include using variables for circle size, adding randomness or specific colors for each circle, and incorporating additional actions like changing shape or stopping movement when clicked.

Summary & Key Takeaways

  • The video discusses how to handle the mouse pressed event in P5.js when clicking on circles in a canvas.

  • The event is initially registered for the whole page, but the goal is to attach it to individual circles.

  • The process involves adding a new function called "clicked" to the object and triggering it in the mouse pressed event.


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 📚

Coding Challenge #126: Toothpicks thumbnail
Coding Challenge #126: Toothpicks
The Coding Train
ITP/IMA Winter Show 2019 thumbnail
ITP/IMA Winter Show 2019
The Coding Train
Coding Challenge #116: Lissajous Curve Table thumbnail
Coding Challenge #116: Lissajous Curve Table
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
Classifying Poses with ml5.js Part 2 thumbnail
Classifying Poses with ml5.js Part 2
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.