Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Color and Styling | Getting Started with P5.js
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Generative Art with JavaScript and P5.js

bookColor and Styling

index.html

index.html

copy

Color is a fundamental part of creative coding with P5.js, allowing you to bring your sketches to life and convey emotion or meaning through visuals. In P5.js, you use the RGB color model to define colors. RGB stands for red, green, and blue—each value can range from 0 to 255. For example, fill(255, 0, 0) gives you a pure red color, while fill(0, 255, 0) makes pure green.

You can also add a fourth value for transparency, called alpha. This value also ranges from 0 (completely transparent) to 255 (fully opaque). For instance, fill(0, 255, 0, 150) creates a semi-transparent green.

The fill() function sets the interior color of shapes you draw next. When you use stroke(), you define the outline color of shapes. The strokeWeight() function lets you control how thick that outline appears. If you do not want an outline, use noStroke(). The background() function sets the canvas color, which you usually call at the start of setup() or at the beginning of each frame in draw().

By combining these tools, you can create vibrant, layered artwork with both solid and transparent shapes, outlines, and backgrounds.

RGB vs HSB Color Modes
expand arrow

P5.js supports different color modes. By default, it uses RGB, where you specify red, green, and blue values. HSB stands for hue, saturation, and brightness, which can be more intuitive for certain color manipulations.

Switching Color Modes
expand arrow

Use the colorMode() function to switch modes. For example, colorMode(HSB, 360, 100, 100) sets hue from 0–360, and both saturation and brightness from 0–100. After switching, fill() and stroke() will interpret their arguments according to the selected mode.

question mark

What does the fill() function in P5.js control?

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 3

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

bookColor and Styling

Свайпніть щоб показати меню

index.html

index.html

copy

Color is a fundamental part of creative coding with P5.js, allowing you to bring your sketches to life and convey emotion or meaning through visuals. In P5.js, you use the RGB color model to define colors. RGB stands for red, green, and blue—each value can range from 0 to 255. For example, fill(255, 0, 0) gives you a pure red color, while fill(0, 255, 0) makes pure green.

You can also add a fourth value for transparency, called alpha. This value also ranges from 0 (completely transparent) to 255 (fully opaque). For instance, fill(0, 255, 0, 150) creates a semi-transparent green.

The fill() function sets the interior color of shapes you draw next. When you use stroke(), you define the outline color of shapes. The strokeWeight() function lets you control how thick that outline appears. If you do not want an outline, use noStroke(). The background() function sets the canvas color, which you usually call at the start of setup() or at the beginning of each frame in draw().

By combining these tools, you can create vibrant, layered artwork with both solid and transparent shapes, outlines, and backgrounds.

RGB vs HSB Color Modes
expand arrow

P5.js supports different color modes. By default, it uses RGB, where you specify red, green, and blue values. HSB stands for hue, saturation, and brightness, which can be more intuitive for certain color manipulations.

Switching Color Modes
expand arrow

Use the colorMode() function to switch modes. For example, colorMode(HSB, 360, 100, 100) sets hue from 0–360, and both saturation and brightness from 0–100. After switching, fill() and stroke() will interpret their arguments according to the selected mode.

question mark

What does the fill() function in P5.js control?

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 3
some-alt