{"id":1393,"date":"2014-07-29T12:52:42","date_gmt":"2014-07-29T04:52:42","guid":{"rendered":"http:\/\/www.magicandlove.com\/blog\/?p=1393"},"modified":"2014-07-29T12:59:24","modified_gmt":"2014-07-29T04:59:24","slug":"processing-test-with-the-pgraphics","status":"publish","type":"post","link":"http:\/\/www.magicandlove.com\/blog\/2014\/07\/29\/processing-test-with-the-pgraphics\/","title":{"rendered":"Processing Test with the PGraphics"},"content":{"rendered":"<p>To simplify the use of a dynamic mask with image, I try to use the <a href=\"http:\/\/processing.org\/reference\/PGraphics.html\">PGraphics<\/a> class as an off screen buffer to store the image for a subsequent <a href=\"http:\/\/processing.org\/reference\/PImage_mask_.html\">mask<\/a> operation. The foreground image is the live video input from the webcam. The mouse drag operation will draw a dynamic mask to reveal the webcam image. It makes use of the fact that the <strong>PGraphics<\/strong> class is a subclass of <strong>PImage<\/strong>. The mask function can directly take the PGraphics instance as input. Here is a sample screen shot.<br \/>\n&nbsp;<br \/>\n<img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2014\/07\/mask001.jpg\" alt=\"\" title=\"mask001\" width=\"640\" height=\"480\" class=\"alignnone size-full wp-image-1398\" srcset=\"http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2014\/07\/mask001.jpg 640w, http:\/\/www.magicandlove.com\/blog\/wp-content\/uploads\/2014\/07\/mask001-300x225.jpg 300w\" sizes=\"auto, (max-width: 640px) 100vw, 640px\" \/><br \/>\n<!--more--><\/p>\n<pre lang=\"java\">\r\nimport processing.video.*;\r\n\r\nPGraphics pg;\r\nCapture cap;\r\n\r\nvoid setup() {\r\n  size(640, 480);\r\n\r\n  cap = new Capture(this, width, height);\r\n  cap.start();\r\n\r\n  pg = createGraphics(width, height);\r\n  pg.beginDraw();\r\n  pg.background(0);\r\n  pg.smooth();\r\n  pg.noStroke();\r\n  pg.fill(255);\r\n  pg.endDraw();\r\n}\r\n\r\nvoid draw() {\r\n  if (!cap.available()) \r\n    return;\r\n  cap.read();\r\n  background(0);\r\n  pg.beginDraw();\r\n  if (mousePressed) \r\n    pg.ellipse(mouseX, mouseY, 40, 40);\r\n  pg.endDraw();\r\n  cap.mask(pg);\r\n  image(cap, 0, 0);\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>To simplify the use of a dynamic mask with image, I try to use the PGraphics class as an off screen buffer to store the image for a subsequent mask operation. The foreground image is the live video input from the webcam. The mouse drag operation will draw a dynamic mask to reveal the webcam [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[66],"tags":[132,62],"class_list":["post-1393","post","type-post","status-publish","format-standard","hentry","category-testing","tag-pgraphics","tag-processing-org"],"_links":{"self":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1393","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/comments?post=1393"}],"version-history":[{"count":6,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1393\/revisions"}],"predecessor-version":[{"id":1400,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/posts\/1393\/revisions\/1400"}],"wp:attachment":[{"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/media?parent=1393"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/categories?post=1393"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.magicandlove.com\/blog\/wp-json\/wp\/v2\/tags?post=1393"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}