{"id":1925,"date":"2020-09-15T21:25:36","date_gmt":"2020-09-15T21:25:36","guid":{"rendered":"http:\/\/mycours.es\/digitalmedia\/?page_id=1925"},"modified":"2025-03-24T12:57:00","modified_gmt":"2025-03-24T12:57:00","slug":"p5-colors","status":"publish","type":"page","link":"http:\/\/mycours.es\/digitalmedia\/p5-colors\/","title":{"rendered":"p5: colors"},"content":{"rendered":"<p><a href=\"https:\/\/p5js.org\/learn\/color.html\" target=\"_blank\" rel=\"noopener noreferrer\">This is a good introduction to colors in p5 <\/a><\/p>\n<p>Colors can be <a href=\"https:\/\/p5js.org\/reference\/#\/p5\/color\" target=\"_blank\" rel=\"noopener noreferrer\">stored as variables:<\/a><\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\">var c = color(255, 204, 0);\r\nfill(c);\r\nnoStroke();\r\nrect(30, 20, 55, 55);\r\n\r\n<\/pre>\n<p>and expressed in the HSB space<\/p>\n<p><a href=\"http:\/\/mycours.es\/digitalmedia\/files\/2020\/09\/hsb.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-1926\" src=\"http:\/\/mycours.es\/digitalmedia\/files\/2020\/09\/hsb.png\" alt=\"\" width=\"1000\" height=\"800\" srcset=\"http:\/\/mycours.es\/digitalmedia\/files\/2020\/09\/hsb.png 1000w, http:\/\/mycours.es\/digitalmedia\/files\/2020\/09\/hsb-300x240.png 300w, http:\/\/mycours.es\/digitalmedia\/files\/2020\/09\/hsb-768x614.png 768w\" sizes=\"auto, (max-width: 709px) 85vw, (max-width: 909px) 67vw, (max-width: 1362px) 62vw, 840px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\">\r\n\r\nfunction setup() {\r\n  createCanvas(400, 400);\r\n  noStroke();\r\n}\r\n\r\nfunction draw() {\r\n  background(255);\r\n  \r\n  \/\/change the color mode to Hue Saturation Brightness\r\n  \/\/and on a scale between 0 and 100\r\n  colorMode(HSB, 100);\r\n\r\n  \/\/remap the mouse coordinates from the extents of the canvas\r\n  \/\/to a 0-100 scale\r\n  var h = map(mouseX, 0, width, 0, 100);\r\n  var s = map(mouseY, 0, height, 100, 0);\r\n  \r\n  fill(h, s, 50);\r\n  rect(0, 0, width, height);\r\n  \r\n  fill(h, s, 100);\r\n  ellipse(width\/2, width\/2, width, height);\r\n  \r\n  \/\/this is just a semi transparent white circle\r\n  fill(255, 0, 100, 0.3);\r\n  ellipse(width\/2, width\/2, width\/2, width\/2);\r\n  \r\n  \r\n}\r\n\r\n<\/pre>\n<p><iframe loading=\"lazy\" title=\"RGB Color in p5.js for Beginners (1.4)\" width=\"840\" height=\"473\" src=\"https:\/\/www.youtube.com\/embed\/riiJTF5-N7c?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen><\/iframe><\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is a good introduction to colors in p5 Colors can be stored as variables: var c = color(255, 204, 0); fill(c); noStroke(); rect(30, 20, 55, 55); and expressed in the HSB space &nbsp; function setup() { createCanvas(400, 400); noStroke(); } function draw() { background(255); \/\/change the color mode to Hue Saturation Brightness \/\/and on &hellip; <a href=\"http:\/\/mycours.es\/digitalmedia\/p5-colors\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;p5: colors&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":31,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1925","page","type-page","status-publish","hentry"],"_links":{"self":[{"href":"http:\/\/mycours.es\/digitalmedia\/wp-json\/wp\/v2\/pages\/1925","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/mycours.es\/digitalmedia\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/mycours.es\/digitalmedia\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/mycours.es\/digitalmedia\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/mycours.es\/digitalmedia\/wp-json\/wp\/v2\/comments?post=1925"}],"version-history":[{"count":3,"href":"http:\/\/mycours.es\/digitalmedia\/wp-json\/wp\/v2\/pages\/1925\/revisions"}],"predecessor-version":[{"id":3845,"href":"http:\/\/mycours.es\/digitalmedia\/wp-json\/wp\/v2\/pages\/1925\/revisions\/3845"}],"wp:attachment":[{"href":"http:\/\/mycours.es\/digitalmedia\/wp-json\/wp\/v2\/media?parent=1925"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}