2.4: random() Function - p5.js Tutorial

TL;DR
Learn how to use the random function in p5JS to create dynamic and varied sketches easily.
Transcript
Welcome back to another video about variables, but not really. So in this video, I to help you use your variables in a different way. So most of the examples that you've seen, there's not a lot to them in terms of their design and their variability. This circle will always be white. It will always be the same size. Maybe, hopefully, you've been pla... Read More
Key Insights
- 👻 The random function in p5JS generates random numbers between a specified range, allowing for variability in sketches.
- 🏃 Initializing variables with random values in setup helps create dynamic visuals that change with each run of the sketch.
- 💱 Using the random function in draw can result in continuously changing visuals, suitable for creating animations with random elements.
- 🎨 The random function is essential for parametric design and creating random patterns in sketches.
- 🪟 Leveraging system variables like width, height, window width, and window height in p5JS can simplify coding and adapt to different canvas sizes.
- 👤 Combining the random function with user interactions can enhance the creative possibilities in p5JS sketches.
- 🥺 Experimenting with random colors, sizes, and positions can lead to unique and innovative visual outcomes in p5JS sketches.
Install to Summarize YouTube Videos and Get Transcripts
Explore YouTube Video Summarizer or Get YouTube Transcript Extractor
Questions & Answers
Q: What is the random function in p5JS, and how does it work?
The random function in p5JS is used to generate random numbers between a specified minimum and maximum value. It is essential for creating dynamic and varied visual elements in sketches.
Q: How can you initialize variables with random values in a p5JS sketch?
To initialize variables with random values in p5JS, you need to use the random function within the setup function. This ensures that the variables are assigned random values at the beginning of the sketch.
Q: What are some practical examples of using the random function in p5JS sketches?
Practical examples of using the random function in p5JS include varying the size, color, and position of shapes, creating dynamic patterns, and adding randomness to visual elements like circles and squares.
Q: How does using the random function in draw differ from using it in setup in p5JS?
When using the random function in draw in p5JS, the values generated by the random function change continuously, resulting in dynamic visuals that update with each frame. This can be useful for creating animations with random elements.
Summary & Key Takeaways
-
Introduces the concept of using the random function in p5JS to generate different values for variables.
-
Demonstrates how to initialize variables with random values in setup to create dynamic visuals.
-
Explores examples of using the random function to create random sizes, colors, and positions in sketches.
Read in Other Languages (beta)
Share This Summary 📚
Summarize YouTube Videos and Get Video Transcripts with 1-Click
Try YouTube Summary with ChatGPT & Claude or YouTube Transcript Generator
Explore More Summaries from The Coding Train 📚






Summarize YouTube Videos and Get Video Transcripts with 1-Click
Try YouTube Summary with ChatGPT & Claude or YouTube Transcript Generator