- Multimedia Programming with Pure Data
- Bryan WC Chung
- 472字
- 2021-08-13 16:53:24
Working with digital color
We have seen how to specify the window background color and the world light color. For all the 2D and 3D graphics, we can also individually specify the color information with RGB values. The coming example will show us how to specify color for the primitives.
Create an empty patch and save it with name gem004.pd
in your folder. Put the gemwin
object, create
and destroy
messages, and the toggle box for rendering. In addition, put a gemhead
object with a sphere object.
Between the gemhead
and the sphere
objects, insert a color
object. For color specification, it will be a message of three numbers: red, green, and blue. Clicking on the message will change the color of the sphere:

We can also use another object colorRGB
to specify color for the graphical shapes. It requires three (RGB) to four (RGB and alpha) number boxes to specify the color. Remember that each number ranges from 0
to 1
. If you press the Shift key and click-and-drag a number box upward or downward, you can alter the number in decimal point, in a step of 0.01
:

Color specification is straightforward in GEM. By using color
or colorRGB
, you alter the default color (white) according to the number values. You can also use both the world_light
color and the object color together:

Some color input requires three individual numbers. Some color input requires a message list of three numbers. We can combine them together such that the user interface is consistent, that is, three number boxes:

The new object is pack
. It simply packs three numbers together. Note the parameters f f f
. Each f
represents a floating-point number. The number of f
corresponds to the number of inlets of the pack
object. In this example, three numbers are packed together to form a list for the right-hand inlet of the color
object. Nevertheless, this patch is not perfect. If you play around with the number boxes, you will notice that only the red color box (hot inlet) will send out the color list message. The rest (green, blue) will just store the new values and wait until there is a change in the red number box. If you remember how we handled the synchronization of hot and cold inlets, we make use of the trigger
object:

For the green and blue color number boxes, they send out the number to a trigger
object, trigger b f
. Each trigger
box will first send out the number to the corresponding number inlet of the pack
object and then send out a bang message to the hot inlet of the pack
object to output the color number list to the color
object. In this case, changes in the green and blue numbers will also go immediately to the sphere
object without waiting.
- 大數據戰爭:人工智能時代不能不說的事
- SCRATCH與機器人
- 計算機應用復習與練習
- 手把手教你學AutoCAD 2010
- STM32G4入門與電機控制實戰:基于X-CUBE-MCSDK的無刷直流電機與永磁同步電機控制實現
- 視覺檢測技術及智能計算
- Machine Learning with Apache Spark Quick Start Guide
- 基于Xilinx ISE的FPAG/CPLD設計與應用
- 激光選區熔化3D打印技術
- Salesforce for Beginners
- 精通數據科學:從線性回歸到深度學習
- 電子設備及系統人機工程設計(第2版)
- Ansible 2 Cloud Automation Cookbook
- Mastering OpenStack(Second Edition)
- 簡明學中文版Flash動畫制作