Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Working with Images and Pixels | Advanced Generative Techniques
Generative Art with JavaScript and P5.js

bookWorking with Images and Pixels

index.html

index.html

copy

When you want to use photographic or drawn images as a base for generative art, P5.js provides a powerful set of tools. The loadImage() function lets you load image files into your sketch, supporting formats such as JPG, PNG, and GIF. Once loaded, you can display the image on the canvas using the image() function, which draws your image at a specified location and size.

For deeper creative manipulation, P5.js gives you direct access to every pixel in the canvas through the pixel array. By calling loadPixels(), you can read and modify the RGBA values of each pixel. After making changes, use updatePixels() to apply your edits to the canvas. This workflow allows you to create custom filters and effects, such as inverting colors, adding noise, or generating mosaic patterns. By combining these tools, you can transform static images into dynamic, generative artworks that respond to algorithms or user interaction.

question mark

Which function is used to load an image file in P5.js?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 4. ChapterΒ 2

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

How do I use `loadImage()` and `image()` in a P5.js sketch?

Can you show an example of manipulating pixels with `loadPixels()` and `updatePixels()`?

What are some creative effects I can apply to images using P5.js?

bookWorking with Images and Pixels

Swipe to show menu

index.html

index.html

copy

When you want to use photographic or drawn images as a base for generative art, P5.js provides a powerful set of tools. The loadImage() function lets you load image files into your sketch, supporting formats such as JPG, PNG, and GIF. Once loaded, you can display the image on the canvas using the image() function, which draws your image at a specified location and size.

For deeper creative manipulation, P5.js gives you direct access to every pixel in the canvas through the pixel array. By calling loadPixels(), you can read and modify the RGBA values of each pixel. After making changes, use updatePixels() to apply your edits to the canvas. This workflow allows you to create custom filters and effects, such as inverting colors, adding noise, or generating mosaic patterns. By combining these tools, you can transform static images into dynamic, generative artworks that respond to algorithms or user interaction.

question mark

Which function is used to load an image file in P5.js?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 4. ChapterΒ 2
some-alt