{"id":814,"date":"2020-03-05T21:43:47","date_gmt":"2020-03-05T21:43:47","guid":{"rendered":"http:\/\/stuartcupit.com\/wordpress\/?p=814"},"modified":"2026-01-02T21:09:54","modified_gmt":"2026-01-02T21:09:54","slug":"dynasquiggler","status":"publish","type":"post","link":"https:\/\/stuartcupit.com\/wordpress\/?p=814","title":{"rendered":"DynaSquiggler"},"content":{"rendered":"\n<p><span style=\"font-size: medium;\">Trying to create a single-line<\/span> portrait for the Processing day event in Bournemouth. I wanted a project that the public could engage with and which could be used with a plotter,<span style=\"font-size: medium;\"> which some of the others are building. Stumbled across some single-line drawings on Pinterest and thought that would be good to try and draw in realtime in response to a webcam image.<\/span><\/p>\n\n\n\n<p><span style=\"font-size: medium;\">Initially, I wrote a flocking algorithm where the boids were attracted to the darker areas of the portrait, leaving a line trail as they move. This kind of worked but struggled to capture the details and make the final line drawing very recognisable. <\/span><\/p>\n\n\n\n<p><span style=\"font-size: medium;\">Did some more research and came across <a href=\"https:\/\/www.reddit.com\/user\/LinesLab\/\">LineLabs<\/a> work using a stippling algorithm to act as the backbone for the line. <\/span><\/p>\n\n\n\n<p><span style=\"font-size: medium;\">So, using a particle simulation, each particle has a repulsive forcefield strength and pushes against its neighbours if they are close enough. The<\/span> strength of the forcefield is based on the brightness of the pixel at its<span style=\"font-size: medium;\"> position over an image, either a loaded picture or a live webcam feed. There&#8217;s a single particle in the middle with a weak attractive force and a large radius pulling all the particles in to keep them from just floating off the screen. <\/span><\/p>\n\n\n\n<p><span style=\"font-size: medium;\">Sliders let me control all the parameters to play around and find optimum values.<\/span><\/p>\n\n\n\n<p><span style=\"font-size: medium;\">More particles can be added in batches of 100, randomly scattered around the mouse position. Once 3-4 thousand are in the simulation Processing starts to struggle and the frame rate drops to ~5fps. (I&#8217;m using <a href=\"http:\/\/toxiclibs.org\/\">Toxiclibs<\/a>, perhaps writing my own particle quad-tree storage would speed up nearest neighbour searching)<\/span><\/p>\n\n\n\n<p><span style=\"font-size: medium;\">When happy with the stippling, I create a line through all the particle positions by searching for the next nearest neighbour. Processings curve function has a tightness parameter that controls the fit of the curve and with a very sloppy fit, it creates a nice squiggly line that overshoots each point like fast drawing. <\/span><\/p>\n\n\n\n<p><span style=\"font-size: medium;\">It&#8217;s nice because it reacts in a really fluid way to a changing\/moving image with the particles rippling about.<\/span><\/p>\n\n\n\n<p>I have revisited this project, coded it in multi-threading C++, so it&#8217;s hundreds of times faster and much better-looking line drawings. Click here <a href=\"https:\/\/stuartcupit.com\/wordpress\/?p=999\">https:\/\/stuartcupit.com\/wordpress\/?p=999<\/a><\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"DynaSquiggler3\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/P7yjj3GvscA?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" referrerpolicy=\"strict-origin-when-cross-origin\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter\"><a href=\"https:\/\/stuartcupit.com\/wordpress\/wp-content\/uploads\/2020\/08\/squiggler-20200305-133755.jpg\"><img loading=\"lazy\" decoding=\"async\" width=\"1200\" height=\"1600\" src=\"https:\/\/stuartcupit.com\/wordpress\/wp-content\/uploads\/2020\/08\/squiggler-20200305-133755.jpg\" alt=\"\" class=\"wp-image-818\" srcset=\"https:\/\/stuartcupit.com\/wordpress\/wp-content\/uploads\/2020\/08\/squiggler-20200305-133755.jpg 1200w, https:\/\/stuartcupit.com\/wordpress\/wp-content\/uploads\/2020\/08\/squiggler-20200305-133755-300x400.jpg 300w, https:\/\/stuartcupit.com\/wordpress\/wp-content\/uploads\/2020\/08\/squiggler-20200305-133755-768x1024.jpg 768w\" sizes=\"auto, (max-width: 1200px) 100vw, 1200px\" \/><\/a><\/figure><\/div>\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Trying to create a single-line portrait for the Processing day event in Bournemouth. I wanted a project that the public could engage with and which could be used with a plotter, which some of the others are building. Stumbled across some single-line drawings on Pinterest and thought that would be good to try and draw&#8230;<\/p>\n","protected":false},"author":1,"featured_media":817,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,5],"tags":[],"class_list":["post-814","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-interactive-media","category-programming"],"_links":{"self":[{"href":"https:\/\/stuartcupit.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/814","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/stuartcupit.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/stuartcupit.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/stuartcupit.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/stuartcupit.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=814"}],"version-history":[{"count":9,"href":"https:\/\/stuartcupit.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/814\/revisions"}],"predecessor-version":[{"id":1425,"href":"https:\/\/stuartcupit.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/814\/revisions\/1425"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/stuartcupit.com\/wordpress\/index.php?rest_route=\/wp\/v2\/media\/817"}],"wp:attachment":[{"href":"https:\/\/stuartcupit.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=814"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/stuartcupit.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=814"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/stuartcupit.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=814"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}