{"id":1336,"date":"2023-04-17T13:43:05","date_gmt":"2023-04-17T12:43:05","guid":{"rendered":"https:\/\/blog.univ-angers.fr\/mathsinfo\/?p=1336"},"modified":"2023-04-17T14:19:18","modified_gmt":"2023-04-17T13:19:18","slug":"art-generatif-modes-de-fusion","status":"publish","type":"post","link":"https:\/\/blog.univ-angers.fr\/mathsinfo\/2023\/04\/17\/art-generatif-modes-de-fusion\/","title":{"rendered":"Art g\u00e9n\u00e9ratif &#8211; Modes de fusion"},"content":{"rendered":"\n<p>Lien vers Basthon P5 : <a href=\"https:\/\/console.basthon.fr\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/console.basthon.fr\/<\/a><\/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=\"Art g\u00e9n\u00e9ratif : Partie 3 - Modes de fusion\" width=\"584\" height=\"329\" src=\"https:\/\/www.youtube.com\/embed\/GIPtV3KPVDs?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\n<h3 class=\"wp-block-heading\">Mode \u00e9cran avec p5<\/h3>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><a href=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-27.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-27-1024x1024.png\" alt=\"\" class=\"wp-image-1337\" width=\"394\" height=\"399\" \/><\/a><\/figure>\n<\/div>\n\n\n<pre class=\"wp-block-code\"><code>from p5 import *\nfrom random import *\n\ndef setup():\n createCanvas(600, 600)\n background(20,20,20)\n fill(10, 25, 10)\n blendMode(SCREEN)\n for x in range(30):\n   for n in range(1 + x):\n    rect(20 * x + randint(0,10), randint(-100,600), 80, 80) \n\ndef draw():\n noLoop()\n\nrun()<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Mode multiplier &#8211; NUMWORKS<\/h3>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-28.png\"><img loading=\"lazy\" decoding=\"async\" width=\"320\" height=\"240\" src=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-28.png\" alt=\"\" class=\"wp-image-1338\" srcset=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-28.png 320w, https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-28-300x225.png 300w\" sizes=\"auto, (max-width: 320px) 100vw, 320px\" \/><\/a><\/figure>\n<\/div>\n\n\n<pre class=\"wp-block-code\"><code>from kandinsky import *\nfrom random import randint\n\ndef rvb01(c): return tuple(v \/ 255 for v in c)\ndef rvb255(c): return tuple(255 * v for v in c)\ndef zip01(c1,c2): return zip(rvb01(c1), rvb01(c2))\ndef multiply(c1,c2): return rvb255(a * b for (a, b) in zip01(c1,c2))\n\ndef rect(x,y,w,h,c,mode):\n for i in range(w):\n  for j in range(h):\n   rvb = mode(c, get_pixel(x + i, y + j))\n   set_pixel(x + i, y + j, rvb)\n\nfor x in range(0,320,8):\n for y in range(0,220,3):      \n  rect(x + randint(0, 7), y + randint(0, 6), \\\n       randint(1, 320 - x), randint(1, 9), (250, 100, 250), multiply)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Mode diff\u00e9rences &#8211; NUMWORKS et P5<\/h3>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-29.png\"><img loading=\"lazy\" decoding=\"async\" width=\"320\" height=\"240\" src=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-29.png\" alt=\"\" class=\"wp-image-1340\" srcset=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-29.png 320w, https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-29-300x225.png 300w\" sizes=\"auto, (max-width: 320px) 100vw, 320px\" \/><\/a><\/figure>\n<\/div>\n\n\n<pre class=\"wp-block-code\"><code># Version - NUMWORKS\n\nfrom kandinsky import *\nfrom random import *\n\ndef rvb01(c): return tuple(v \/ 255 for v in c)\ndef rvb255(c): return tuple(int(255 * v) for v in c)\ndef zip01(c1,c2): return zip(rvb01(c1),rvb01(c2))\n\ndef diff(c1,c2):\n return rvb255(abs(a - b) for (a, b) in zip01(c1,c2))\n\ndef rect(x,y,w,h,c,mode):\n for i in range(w):\n  for j in range(h):\n    rvb = mode(c, get_pixel(x + i, y + j))\n    set_pixel(x + i, y + j, rvb)\n\nfill_rect(0,0,320,222,(250, 100, 250))\nfor _ in range(500):  \n  t = randint(20,40)   \n  rect(randint(-10, 315), randint(-10, 220), t, t, (250, 100, 250), diff)<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>\n# Version P5 - Python\n\nfrom p5 import *\nfrom random import *\n\nc = (250, 100, 250)\n\ndef setup():\n createCanvas(900, 600)\n\n background(c)\n blendMode(DIFFERENCE)\n fill(c)\n for _ in range(1000):\n    t = randint(20,80)\n    rect(randint(-20,900), randint(-20,600), t, t) \n\ndef draw():\n noLoop()\n\nrun()<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Mode addition &#8211; NUMWORKS<\/h3>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-30.png\"><img loading=\"lazy\" decoding=\"async\" width=\"320\" height=\"240\" src=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-30.png\" alt=\"\" class=\"wp-image-1342\" srcset=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-30.png 320w, https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-30-300x225.png 300w\" sizes=\"auto, (max-width: 320px) 100vw, 320px\" \/><\/a><\/figure>\n<\/div>\n\n\n<pre class=\"wp-block-code\"><code>from kandinsky import *\nfrom random import *\nfrom math import cos\n\ndef rvb01(c): return tuple(v \/ 255 for v in c)\ndef rvb255(c): return tuple(int(255 * v) for v in c)\ndef zip01(c1,c2): return zip(rvb01(c1),rvb01(c2))\n\ndef add(c1,c2):\n return rvb255(min(1,a+b) for (a, b) in zip01(c1,c2))\n\ndef rect(x,y,w,h,c,mode):\n for i in range(w):\n  for j in range(h):\n    rvb = mode(c, get_pixel(x + i, y + j))\n    set_pixel(x + i, y + j, rvb)\n\nfill_rect(0,0,320,222,(40,40,40))\nfor i in range(50):\n rect(randint(-20,300), randint(-20,200), 60, 60,\\\n      (randint(0,255), randint(0,255), randint(0,255)), add)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">TISSU \u00e9cossais &#8211; p5<\/h3>\n\n\n\n<p>Cet exemple a \u00e9t\u00e9 supprim\u00e9 au montage de la vid\u00e9o:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large is-resized\"><a href=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-31.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-31-1024x1024.png\" alt=\"\" class=\"wp-image-1345\" width=\"381\" height=\"386\" \/><\/a><\/figure>\n<\/div>\n\n\n<pre class=\"wp-block-code\"><code>from p5 import *\n\ndef setup():\n createCanvas(770, 770)\n noStroke()\n background((40,40,40))\n blendMode(SCREEN)\n fill(20, 40, 20)\n for i in range(10):\n    for j in range(10):\n      rect(60 * i, 60 * j, 50 + 20 * i, 50 + 20 * j) \n\ndef draw():\n    noLoop()\n\nrun()<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">MODE addition &#8211; p5 et NUMWORKS<\/h3>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-32.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"512\" src=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-32-1024x512.png\" alt=\"\" class=\"wp-image-1347\" srcset=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-32-1024x512.png 1024w, https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-32-300x150.png 300w, https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-32-768x384.png 768w, https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-32-1536x768.png 1536w, https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-32-500x250.png 500w, https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-32.png 1600w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n<\/div>\n\n\n<pre class=\"wp-block-code\"><code>from p5 import *\nfrom random import *\n\ndef setup():\n createCanvas(800, 400)\n noStroke()\n background((50,50,50))\n blendMode(ADD)\n fill(20, 140, 20)\n \n x, y = 200, 0\n for i in range(100):\n    textSize(1 + i)\n    x -= 2\n    y += randint(-5,11)\n    fill(20, 140, 20)\n    if random()&lt;.2: fill(255, 0, 0)\n    text('PROGRAMMATION', x, y)\n\ndef draw():\n    noLoop()\n\nrun()\n<\/code><\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-large\"><a href=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-33.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"768\" src=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-33-1024x768.png\" alt=\"\" class=\"wp-image-1349\" srcset=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-33-1024x768.png 1024w, https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-33-300x225.png 300w, https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-33-768x576.png 768w, https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-33-1536x1152.png 1536w, https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-33-400x300.png 400w, https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-33.png 1984w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><\/figure>\n<\/div>\n\n\n<pre class=\"wp-block-code\"><code>from kandinsky import *\nfrom random import *\n\nBL, WH = (0, 0, 0), (255,) * 3\n\ndef rvb01(c): return tuple(v \/ 255 for v in c)\ndef rvb255(c): return tuple(int(255 * v) for v in c)\ndef zip01(c1,c2): return zip(rvb01(c1),rvb01(c2))\n\ndef screen(c1,c2):\n  return rvb255(1 - (1 - a) * (1 - b) for (a, b) in zip01(c1,c2))\n\ndef rect(x,y,w,h,c,mode):  \n for i in range(w):\n  for j in range(h):\n   rvb = mode(c, get_pixel(x + i, y + j))\n   set_pixel(x + i, y + j, rvb)\n\ndef dot(x, y, c, fg, t):\n  draw_string(c, 0, 0, fg, (0,0,0))\n  for v in range(18):\n    for u in range(9):\n      rect(x + u * t, y + v * t, t, t, get_pixel(u, v), screen)  \n\ndef aff(txt, x, y, t):\n  coul = (255, 0, 0)if random()&lt;.3 else (20, 140, 20)    \n  for i, c in enumerate(txt):\n    dot(x + i * t * 9, y, c, coul, t)\n\nfill_rect(0,0,320,222,(50,50,50))\nx, y = 150, -30\nfor i in range(80):\n x -= 2\n y += randint(1,4)\n aff(\"PROGRAMMATION\", x, y, i\/\/20)\nfill_rect(0,0,20,20,(50,50,50))<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">D\u00e9grad\u00e9s &#8211; NUMWORKS<\/h3>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-34.png\"><img loading=\"lazy\" decoding=\"async\" width=\"320\" height=\"240\" src=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-34.png\" alt=\"\" class=\"wp-image-1351\" srcset=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-34.png 320w, https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-34-300x225.png 300w\" sizes=\"auto, (max-width: 320px) 100vw, 320px\" \/><\/a><\/figure>\n<\/div>\n\n\n<pre class=\"wp-block-code\"><code>from kandinsky import *\n\ndef rvb01(c): return tuple(v \/ 255 for v in c)\ndef rvb255(c): return tuple(int(255 * v) for v in c)\ndef zip01(c1,c2): return zip(rvb01(c1),rvb01(c2))\n\ndef alpha(c1, t, c2):\n return rvb255(a * t + b * (1 - t) for (a, b) in zip01(c1,c2))\n\ndef rect(x,y,w,h,c,d):\n (dx,dy) = d   \n for i in range(w):\n  for j in range(h):\n   t = 1   \n   if dx == 1: t = 1 - i \/ w\n   elif dx == -1: t = i \/ w \n   if dy == 1: t = 1 - j \/ h\n   elif dy == -1: t = j \/ h\n   rvb = alpha(c, t, get_pixel(x + i, y + j))\n   set_pixel(x + i, y + j, rvb)\n\nrect(0, 0, 200, 200, (255, 0, 0), (1,0))\nrect(0, 0, 200, 200, (0, 255, 0), (0,1))\nrect(0, 0, 200, 200, (0, 0, 255), (-1,0))<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Effet alpha &#8211; NUMWORKS<\/h3>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-35.png\"><img loading=\"lazy\" decoding=\"async\" width=\"320\" height=\"240\" src=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-35.png\" alt=\"\" class=\"wp-image-1353\" srcset=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-35.png 320w, https:\/\/blog.univ-angers.fr\/mathsinfo\/files\/2023\/04\/image-35-300x225.png 300w\" sizes=\"auto, (max-width: 320px) 100vw, 320px\" \/><\/a><\/figure>\n<\/div>\n\n\n<pre class=\"wp-block-code\"><code>from kandinsky import *\nfrom random import randint, choice\n\ncoul = (255,0,255), (255,255,0), (255,127,0), (255,0,127)\n\ndef rvb01(c): return tuple(v \/ 255 for v in c)\ndef rvb255(c): return tuple(int(255 * v) for v in c)\ndef zip01(c1,c2): return zip(rvb01(c1),rvb01(c2))\n\ndef alpha(c1, t, c2):\n return rvb255(a * t + b * (1 - t) for (a, b) in zip01(c1,c2))\n\ndef rect(x,y,w,h,c,t):  \n for i in range(w):\n  for j in range(h):\n   if i == 0 or j == 0 or i == w - 1 or j == h - 1: \n    rvb = (255,255,255)\n   else: \n    rvb = alpha(c, t, get_pixel(x + i, y + j))\n   set_pixel(x + i, y + j, rvb)\n\ndef effet(t):\n for _ in range(150):\n  x, y = randint(-10,300), randint(-10,200)\n  w, h = randint(10,80), randint(10,80)\n  rect(x,y,w,h,choice(coul),t)\n\neffet(0.15)\n\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Lien vers Basthon P5 : https:\/\/console.basthon.fr\/ Mode \u00e9cran avec p5 Mode multiplier &#8211; NUMWORKS Mode diff\u00e9rences &#8211; NUMWORKS et P5 Mode addition &#8211; NUMWORKS TISSU \u00e9cossais &#8211; p5 Cet exemple a \u00e9t\u00e9 supprim\u00e9 au montage de la vid\u00e9o: MODE addition &hellip; <a href=\"https:\/\/blog.univ-angers.fr\/mathsinfo\/2023\/04\/17\/art-generatif-modes-de-fusion\/\">Continuer la lecture <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":4913,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1336","post","type-post","status-publish","format-standard","hentry","category-non-classe"],"_links":{"self":[{"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/posts\/1336","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/users\/4913"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/comments?post=1336"}],"version-history":[{"count":9,"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/posts\/1336\/revisions"}],"predecessor-version":[{"id":1354,"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/posts\/1336\/revisions\/1354"}],"wp:attachment":[{"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/media?parent=1336"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/categories?post=1336"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.univ-angers.fr\/mathsinfo\/wp-json\/wp\/v2\/tags?post=1336"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}