compositor for 2d glitch effects
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

effects.pde 153KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077
  1. /*
  2. iPhone
  3. */
  4. class IPHONE extends Shader {
  5. boolean webcamRunning;
  6. PImage img;
  7. int rw, rh, x, y, w, h, croptop, cropbottom, cropleft, cropright, contrast, brightness, hue, saturation, camSelected, camSelectedPrev;
  8. final int[] blends = {BLEND, ADD, SUBTRACT, DARKEST, LIGHTEST, DIFFERENCE, EXCLUSION, MULTIPLY, SCREEN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, DODGE, BURN};
  9. IPHONE() {
  10. rw = canvas.width;
  11. rh = canvas.height;
  12. name = "Webcam";
  13. println(Capture.list().length);
  14. img = createImage(rw, rh, ARGB);
  15. if (!webcamRunning) startWebcam();
  16. //params.add(new Param("mode", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
  17. params.add(new Param("x", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN, }));
  18. params.add(new Param("y", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  19. params.add(new Param("w", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  20. params.add(new Param("h", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  21. params.add(new Param("croptop", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  22. params.add(new Param("cropbottom", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  23. params.add(new Param("cropleft", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  24. params.add(new Param("cropright", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  25. params.add(new Param("contrast", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  26. params.add(new Param("brightness", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  27. params.add(new Param("hue", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  28. params.add(new Param("saturation", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  29. params.add(new Param("blend mode", INTVAL, 0, this.blends.length-1, new int[]{RANDOM }));
  30. params.add(new Param("webcam", INTVAL, 0, Capture.list().length-1, new int[]{TRIANG, SINE, RAMPUPDOWN, }));
  31. camSelected = (int)params.get(13).getValue();
  32. camSelectedPrev = (int)params.get(13).getValue();
  33. }
  34. void startWebcam() {
  35. String[] cameras = Capture.list();
  36. println("Hi");
  37. for (int i = 0; i < cameras.length; i++) {
  38. println(cameras[i]);
  39. }
  40. //println(cameras);
  41. cam2.start();
  42. webcamRunning = true;
  43. }
  44. void stopWebcam() { //gets never called lmao
  45. cam2.stop();
  46. webcamRunning = false;
  47. }
  48. void apply() {
  49. rw = canvas.width;
  50. rh = canvas.height;
  51. x = int(params.get(0).getValue()*rw);
  52. y = int(params.get(1).getValue()*rh);
  53. w = int(params.get(2).getValue()*(rw*2));
  54. h = int(params.get(3).getValue()*(rh*2));
  55. camSelected = (int)params.get(13).getValue();
  56. /*
  57. if (camSelected != camSelectedPrev) {
  58. currentCam = camSelected;
  59. camSelectedPrev = camSelected;
  60. stopWebcam();
  61. startWebcam();
  62. //new Capture(this, 1920,1080, Capture.list()[camSelected]);
  63. }*/
  64. //params.get(13) //camera id
  65. //if (cam.available()) img = cam.get();
  66. img = iPhoneImg.get();
  67. canvas.beginDraw();
  68. canvas.image(img, x, y, w, h);
  69. //for ( int i = 0, l = canvas.pixels.length; i<l; i++) {
  70. //}
  71. canvas.endDraw();
  72. }
  73. void getParams() {
  74. }
  75. }
  76. /*
  77. Webcam
  78. */
  79. /*
  80. boolean webcamRunning;
  81. void startWebcam() {
  82. String[] cameras = Capture.list();
  83. println("Hi");
  84. for (int i = 0; i < cameras.length; i++) {
  85. println(cameras[i]);
  86. }
  87. //println(cameras);
  88. cam.start();
  89. webcamRunning = true;
  90. }
  91. void stopWebcam() {
  92. cam.stop();
  93. webcamRunning = false;
  94. }
  95. */
  96. class WEBCAM extends Shader {
  97. boolean webcamRunning;
  98. PImage img;
  99. int rw, rh, x, y, w, h, croptop, cropbottom, cropleft, cropright, contrast, brightness, hue, saturation, camSelected, camSelectedPrev;
  100. final int[] blends = {BLEND, ADD, SUBTRACT, DARKEST, LIGHTEST, DIFFERENCE, EXCLUSION, MULTIPLY, SCREEN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, DODGE, BURN};
  101. WEBCAM() {
  102. rw = canvas.width;
  103. rh = canvas.height;
  104. name = "Webcam";
  105. println(Capture.list().length);
  106. img = createImage(rw, rh, ARGB);
  107. if (!webcamRunning) startWebcam();
  108. //params.add(new Param("mode", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
  109. params.add(new Param("x", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN, }));
  110. params.add(new Param("y", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  111. params.add(new Param("w", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  112. params.add(new Param("h", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  113. params.add(new Param("croptop", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  114. params.add(new Param("cropbottom", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  115. params.add(new Param("cropleft", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  116. params.add(new Param("cropright", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  117. params.add(new Param("contrast", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  118. params.add(new Param("brightness", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  119. params.add(new Param("hue", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  120. params.add(new Param("saturation", FLOATVAL, 0.0, 1.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  121. params.add(new Param("blend mode", INTVAL, 0, this.blends.length-1, new int[]{RANDOM }));
  122. params.add(new Param("webcam", INTVAL, 0, Capture.list().length-1, new int[]{TRIANG, SINE, RAMPUPDOWN, }));
  123. camSelected = (int)params.get(13).getValue();
  124. camSelectedPrev = (int)params.get(13).getValue();
  125. }
  126. void startWebcam() {
  127. String[] cameras = Capture.list();
  128. println("Hi");
  129. for (int i = 0; i < cameras.length; i++) {
  130. println(cameras[i]);
  131. }
  132. //println(cameras);
  133. cam.start();
  134. webcamRunning = true;
  135. }
  136. void stopWebcam() { //gets never called lmao
  137. cam.stop();
  138. webcamRunning = false;
  139. }
  140. void apply() {
  141. rw = canvas.width;
  142. rh = canvas.height;
  143. x = int(params.get(0).getValue()*rw);
  144. y = int(params.get(1).getValue()*rh);
  145. w = int(params.get(2).getValue()*(rw*2));
  146. h = int(params.get(3).getValue()*(rh*2));
  147. camSelected = (int)params.get(13).getValue();
  148. /*
  149. if (camSelected != camSelectedPrev) {
  150. currentCam = camSelected;
  151. camSelectedPrev = camSelected;
  152. stopWebcam();
  153. startWebcam();
  154. //new Capture(this, 1920,1080, Capture.list()[camSelected]);
  155. }*/
  156. //params.get(13) //camera id
  157. //if (cam.available()) img = cam.get();
  158. img = webcamImg.get();
  159. canvas.beginDraw();
  160. canvas.image(img, x, y, w, h);
  161. //for ( int i = 0, l = canvas.pixels.length; i<l; i++) {
  162. //}
  163. canvas.endDraw();
  164. }
  165. void getParams() {
  166. }
  167. }
  168. /*
  169. ASDFPIXELSORT
  170. by Kim Asendorf
  171. */
  172. class ASDFPIXELSORT extends Shader {
  173. ASDFPIXELSORT() {
  174. name = "fxASDFPixelSort";
  175. params.add(new Param("black", INTVAL, -17000000, -2000000, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
  176. params.add(new Param("target", INTVAL, 0, 2, new int[]{RANDOM}));
  177. params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM}));
  178. directionParamIndex = 2;
  179. }
  180. int previousMode;
  181. void apply() {
  182. if (previousMode != int(params.get(1).getValue())) {
  183. if (params.get(1).getValue() == 0) changeParam(0, new Param("black", INTVAL, -17000000, -2000000, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
  184. if (params.get(1).getValue() == 1) changeParam(0, new Param("brightness", INTVAL, 0, 200, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
  185. if (params.get(1).getValue() == 2) changeParam(0, new Param("white", INTVAL, -15000000, -700000, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
  186. }
  187. previousMode = (int)params.get(1).getValue();
  188. row = 0;
  189. column = 0;
  190. colorMode(RGB);
  191. canvas.beginDraw();
  192. while (column < canvas.width-1) {
  193. canvas.loadPixels();
  194. sortColumn();
  195. column++;
  196. canvas.updatePixels();
  197. }
  198. while (row < canvas.height-1) {
  199. canvas.loadPixels();
  200. sortRow();
  201. row++;
  202. canvas.updatePixels();
  203. }
  204. canvas.endDraw();
  205. }
  206. int row = 0;
  207. int column = 0;
  208. void sortRow() {
  209. int x = 0;
  210. int y = row;
  211. int xend = 0;
  212. while (xend < canvas.width-1) {
  213. switch((int)params.get(1).getValue()) {
  214. case 0:
  215. x = getFirstNotBlackX(x, y);
  216. xend = getNextBlackX(x, y);
  217. break;
  218. case 1:
  219. x = getFirstBrightX(x, y);
  220. xend = getNextDarkX(x, y);
  221. break;
  222. case 2:
  223. x = getFirstNotWhiteX(x, y);
  224. xend = getNextWhiteX(x, y);
  225. break;
  226. default:
  227. break;
  228. }
  229. if (x < 0) break;
  230. int sortLength = xend-x;
  231. color[] unsorted = new color[sortLength];
  232. color[] sorted = new color[sortLength];
  233. for (int i=0; i<sortLength; i++) {
  234. unsorted[i] = canvas.pixels[x + i + y * canvas.width];
  235. }
  236. sorted = sort(unsorted);
  237. for (int i=0; i<sortLength; i++) {
  238. canvas.pixels[x + i + y * canvas.width] = sorted[i];
  239. }
  240. x = xend+1;
  241. }
  242. }
  243. void sortColumn() {
  244. int x = column;
  245. int y = 0;
  246. int yend = 0;
  247. while (yend < canvas.height-1) {
  248. switch((int)params.get(1).getValue()) {
  249. case 0:
  250. y = getFirstNotBlackY(x, y);
  251. yend = getNextBlackY(x, y);
  252. break;
  253. case 1:
  254. y = getFirstBrightY(x, y);
  255. yend = getNextDarkY(x, y);
  256. break;
  257. case 2:
  258. y = getFirstNotWhiteY(x, y);
  259. yend = getNextWhiteY(x, y);
  260. break;
  261. default:
  262. break;
  263. }
  264. if (y < 0) break;
  265. int sortLength = yend-y;
  266. color[] unsorted = new color[sortLength];
  267. color[] sorted = new color[sortLength];
  268. for (int i=0; i<sortLength; i++) {
  269. unsorted[i] = canvas.pixels[x + (y+i) * canvas.width];
  270. }
  271. sorted = sort(unsorted);
  272. for (int i=0; i<sortLength; i++) {
  273. canvas.pixels[x + (y+i) * canvas.width] = sorted[i];
  274. }
  275. y = yend+1;
  276. }
  277. }
  278. //BLACK
  279. int getFirstNotBlackX(int _x, int _y) {
  280. int x = _x;
  281. int y = _y;
  282. color c;
  283. while ( (c = canvas.pixels[x + y * canvas.width]) < params.get(0).getValue()) {
  284. x++;
  285. if (x >= canvas.width) return -1;
  286. }
  287. return x;
  288. }
  289. int getNextBlackX(int _x, int _y) {
  290. int x = _x+1;
  291. int y = _y;
  292. color c;
  293. while ( (c = canvas.pixels[x + y * canvas.width]) > params.get(0).getValue()) {
  294. x++;
  295. if (x >= canvas.width) return canvas.width-1;
  296. }
  297. return x-1;
  298. }
  299. //BRIGHTNESS
  300. int getFirstBrightX(int _x, int _y) {
  301. int x = _x;
  302. int y = _y;
  303. color c;
  304. while (brightness (c = canvas.pixels[x + y * canvas.width]) < params.get(0).getValue()) {
  305. x++;
  306. if (x >= canvas.width) return -1;
  307. }
  308. return x;
  309. }
  310. int getNextDarkX(int _x, int _y) {
  311. int x = _x+1;
  312. int y = _y;
  313. color c;
  314. while (brightness (c = canvas.pixels[x + y * canvas.width]) > params.get(0).getValue()) {
  315. x++;
  316. if (x >= canvas.width) return canvas.width-1;
  317. }
  318. return x-1;
  319. }
  320. //WHITE
  321. int getFirstNotWhiteX(int _x, int _y) {
  322. int x = _x;
  323. int y = _y;
  324. color c;
  325. while ( (c = canvas.pixels[x + y * canvas.width]) > params.get(0).getValue()) {
  326. x++;
  327. if (x >= canvas.width) return -1;
  328. }
  329. return x;
  330. }
  331. int getNextWhiteX(int _x, int _y) {
  332. int x = _x+1;
  333. int y = _y;
  334. color c;
  335. while ( (c = canvas.pixels[x + y * canvas.width]) < params.get(0).getValue()) {
  336. x++;
  337. if (x >= canvas.width) return canvas.width-1;
  338. }
  339. return x-1;
  340. }
  341. //BLACK
  342. int getFirstNotBlackY(int _x, int _y) {
  343. int x = _x;
  344. int y = _y;
  345. color c;
  346. if (y < canvas.height) {
  347. while ( (c = canvas.pixels[x + y * canvas.width]) < params.get(0).getValue()) {
  348. y++;
  349. if (y >= canvas.height) return -1;
  350. }
  351. }
  352. return y;
  353. }
  354. int getNextBlackY(int _x, int _y) {
  355. int x = _x;
  356. int y = _y+1;
  357. color c;
  358. if (y < canvas.height) {
  359. while ( (c = canvas.pixels[x + y * canvas.width]) > params.get(0).getValue()) {
  360. y++;
  361. if (y >= canvas.height) return canvas.height-1;
  362. }
  363. }
  364. return y-1;
  365. }
  366. //BRIGHTNESS
  367. int getFirstBrightY(int _x, int _y) {
  368. int x = _x;
  369. int y = _y;
  370. color c;
  371. if (y < canvas.height) {
  372. while (brightness (c = canvas.pixels[x + y * canvas.width]) < params.get(0).getValue()) {
  373. y++;
  374. if (y >= canvas.height) return -1;
  375. }
  376. }
  377. return y;
  378. }
  379. int getNextDarkY(int _x, int _y) {
  380. int x = _x;
  381. int y = _y+1;
  382. color c;
  383. if (y < canvas.height) {
  384. while (brightness (c = canvas.pixels[x + y * canvas.width]) > params.get(0).getValue()) {
  385. y++;
  386. if (y >= canvas.height) return canvas.height-1;
  387. }
  388. }
  389. return y-1;
  390. }
  391. //WHITE
  392. int getFirstNotWhiteY(int _x, int _y) {
  393. int x = _x;
  394. int y = _y;
  395. color c;
  396. if (y < canvas.height) {
  397. while ( (c = canvas.pixels[x + y * canvas.width]) > params.get(0).getValue()) {
  398. y++;
  399. if (y >= canvas.height) return -1;
  400. }
  401. }
  402. return y;
  403. }
  404. int getNextWhiteY(int _x, int _y) {
  405. int x = _x;
  406. int y = _y+1;
  407. color c;
  408. if (y < canvas.height) {
  409. while ( (c = canvas.pixels[x + y * canvas.width]) < params.get(0).getValue()) {
  410. y++;
  411. if (y >= canvas.height) return canvas.height-1;
  412. }
  413. }
  414. return y-1;
  415. }
  416. }
  417. /*
  418. DISTORTER
  419. by Tomasz Sulej
  420. */
  421. class DISTORTER extends Shader {
  422. boolean do_blend = false; // blend image after process
  423. int blend_mode = OVERLAY; // blend type
  424. int channel = BRIGHTNESS; // channel used in processing (R,G,B) or (H,S,B)
  425. float scalex = 0.05; // from 0.01 to 1
  426. float scaley = 0.1; // from 0.01 to 1
  427. boolean shift_hue = true;
  428. float shift_amt = 0.1; // from 0 to 1
  429. PImage buffer;
  430. final static int distortionMatrixSize = 512; //doesnt really make a difference, it's more or less "noise variety".. only kinda different if real low, like 2 or so
  431. int[][] distort = new int[2][distortionMatrixSize];
  432. final static float tick = 1.0/distortionMatrixSize;
  433. int mode = 0;
  434. int initBufferW, initBufferH;
  435. DISTORTER() {
  436. buffer = createImage(canvas.width, canvas.height, ARGB);
  437. initBufferW = buffer.width;
  438. initBufferH = buffer.height;
  439. name = "fxDistorter";
  440. params.add(new Param("width", FLOATVAL, 2, buffer.width/4-1, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
  441. params.add(new Param("height", FLOATVAL, 2, buffer.height/4-1, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
  442. params.add(new Param("do blend", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
  443. params.add(new Param("shift hue amount", FLOATVAL, 0, 1, new int[]{SAWTOOTH, SAWTOOTHINVERSE, TAN, TANINVERSE, RAMP, RAMPINVERSE}));
  444. params.add(new Param("scale x", FLOATVAL, 0.01, 1, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
  445. params.add(new Param("scale y", FLOATVAL, 0.01, 1, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
  446. params.add(new Param("blend mode", INTVAL, 0, blends.length-1, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
  447. params.add(new Param("channel", INTVAL, 0, 12, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
  448. params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM}));
  449. directionParamIndex = 8;
  450. //params.add(new Param(DIRECTION));
  451. // channel, blend_mode
  452. //params.add(new Param("height", FLOATVAL, 1, buffer.height/4-1, new int[]{SINE, SAWTOOTH, RAMPUPDOWN, TAN, TANINVERSE, TRIANG}));
  453. // prepare distortion pattern
  454. for (int i=0; i<distortionMatrixSize; i++) {
  455. distort[0][i] = (int)random(-128, 128);
  456. distort[1][i] = (int)random(-128, 128);
  457. }
  458. }
  459. // ALL Channels, Nxxx stand for negative (255-value)
  460. // channels to work with
  461. final static int RED = 0;
  462. final static int GREEN = 1;
  463. final static int BLUE = 2;
  464. final static int HUE = 3;
  465. final static int SATURATION = 4;
  466. final static int BRIGHTNESS = 5;
  467. final static int NRED = 6;
  468. final static int NGREEN = 7;
  469. final static int NBLUE = 8;
  470. final static int NHUE = 9;
  471. final static int NSATURATION = 10;
  472. final static int NBRIGHTNESS = 11;
  473. void apply() {
  474. buffer = canvas.get();
  475. buffer.resize(canvas.width, canvas.height);
  476. float neww = map(params.get(0).getValue(), 2, initBufferW-2, 2, buffer.width/4-2);
  477. float newh = map(params.get(1).getValue(), 2, initBufferH-2, 2, buffer.height/4-2);
  478. /*
  479. do_blend = boolean(int(params.get(2).getValue()));
  480. shift_amt = params.get(3).getValue();
  481. scalex = params.get(4).getValue();
  482. scaley = params.get(5).getValue();
  483. blend_mode = blends[(int)params.get(6).getValue()];
  484. channel = (int)params.get(7).getValue();
  485. */
  486. do_blend = boolean(int(params.get(2).getValue()));
  487. shift_amt = params.get(3).getValue();
  488. scalex = params.get(4).getValue();
  489. scaley = params.get(5).getValue();
  490. blend_mode = blends[(int)params.get(6).getValue()];
  491. channel = (int)params.get(7).getValue();
  492. float totalnum = neww+newh;
  493. float times = (totalnum/floor(totalnum/neww));
  494. float offx = (totalnum%neww)/times;
  495. float ratiox = neww/buffer.width;
  496. //println(ratiox);
  497. canvas.beginDraw();
  498. canvas.noStroke();
  499. for (int y=0; y<buffer.height; y++) {
  500. float yy = y/(float)buffer.height;
  501. for (int x=0; x<buffer.width; x++) {
  502. float xx = x/(float)buffer.width;
  503. float offy = floor(newh*yy);
  504. float fx = xx*ratiox+offx*offy;
  505. float shift = fx%1.0;
  506. float st = shift/tick;
  507. int no1 = floor(st)%distortionMatrixSize;
  508. int no2 = ceil(st)%distortionMatrixSize ;
  509. float l = st-(float)no1;
  510. float cx = lerp(distort[0][no1], distort[0][no2], l);
  511. float cy = lerp(distort[1][no1], distort[1][no2], l);
  512. float rx =getChannel(buffer.get(x, y), channel);
  513. int sx = (int)((buffer.width+x+cx*rx*scalex*0.1)%buffer.width);
  514. int sy = (int)((buffer.height+y+cy*scaley)%buffer.height);
  515. color c=buffer.get(sx, sy);
  516. if (shift_hue) {
  517. colorMode(HSB, 255);
  518. c = color((hue(c)+shift_amt*255*noise(newh+y))%255.0, constrain(saturation(c)*1.2, 0, 255), constrain(brightness(c), 0, 255));
  519. colorMode(RGB, 255);
  520. }
  521. // buffer.fill(lerpColor(c,img.get(x,y),0.2));
  522. canvas.fill(c); //wärs nich effizienter die pixelmatrix zu ändern ?
  523. canvas.rect(x, y, 1, 1);
  524. }
  525. }
  526. if (do_blend)
  527. canvas.blend(buffer, 0, 0, buffer.width, buffer.height, 0, 0, canvas.width, canvas.height, blend_mode);
  528. canvas.endDraw();
  529. }
  530. float getChannel(color c, int channel) {
  531. int ch = channel>5?channel-6:channel;
  532. float cc;
  533. switch(ch) {
  534. case RED:
  535. cc = red(c);
  536. break;
  537. case GREEN:
  538. cc = green(c);
  539. break;
  540. case BLUE:
  541. cc = blue(c);
  542. break;
  543. case HUE:
  544. cc = hue(c);
  545. break;
  546. case SATURATION:
  547. cc = saturation(c);
  548. break;
  549. default:
  550. cc= brightness(c);
  551. break;
  552. }
  553. return channel>5?255-cc:cc;
  554. }
  555. }
  556. /*
  557. FM
  558. */
  559. class FM extends Shader {
  560. // configuration
  561. int colorspace = RGB;
  562. int quantval = 30; // 0 - off, less - more glitch, more - more precision
  563. boolean do_blend = true; // blend image after process
  564. int blend_mode = OVERLAY; // blend type
  565. //unused parameters (giers):
  566. final static boolean first_channel_only = false; // for L.. or Y.. colorspaces set true to modulate only luma;
  567. final static boolean lowpass1_on = true; // on/off of first low pass filter
  568. final static boolean lowpass2_on = true; // on/off of second low pass filter
  569. final static boolean lowpass3_on = true; // on/off of third low pass filter
  570. // better don't touch it, lowpass filters are run in cascade
  571. float lowpass1_cutoff = 0.25; // percentage of rate
  572. float lowpass2_cutoff = 0.1;
  573. float lowpass3_cutoff = 0.05;
  574. // working buffer
  575. PGraphics buffer;
  576. // local variables
  577. float min_omega, max_omega;
  578. float min_phase_mult=0.05;
  579. float max_phase_mult=50.0;
  580. LowpassFilter lpf1, lpf2, lpf3;
  581. int[][] pxls;
  582. boolean negate = false;
  583. FM() {
  584. name = "fxFM";
  585. params.add(new Param ("do blend", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
  586. params.add(new Param ("blend_mode", INTVAL, 0, blends.length-1, new int[]{RANDOM}));
  587. params.add(new Param ("omega", FLOATVAL, 0, 1, new int[]{SINE, SAWTOOTH, TRIANG}));
  588. params.add(new Param ("phase", FLOATVAL, 0, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  589. params.add(new Param ("colorspace", INTVAL, 0, 16, new int[]{RANDOM}));
  590. params.add(new Param ("quant", INTVAL, 0, 40, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  591. params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM}));
  592. directionParamIndex = 6;
  593. buffer = createGraphics(canvas.width, canvas.height);
  594. buffer.beginDraw();
  595. buffer.noStroke();
  596. //buffer.smooth(8);
  597. //buffer.background(0);
  598. // buffer.image(canvas, 0, 0);
  599. buffer.endDraw();
  600. float rate = 100000.0;
  601. lpf1 = new LowpassFilter(rate, lowpass1_cutoff*rate);
  602. lpf2 = new LowpassFilter(rate, lowpass2_cutoff*rate);
  603. lpf3 = new LowpassFilter(rate, lowpass3_cutoff*rate);
  604. //img.loadPixels();
  605. }
  606. void prepareData() {
  607. pxls = new int[3][canvas.pixels.length];
  608. for (int i=0; i<canvas.pixels.length; i++) {
  609. int cl = toColorspace(canvas.pixels[i], colorspace);
  610. pxls[0][i] = (cl >> 16) & 0xff;
  611. pxls[1][i] = (cl >> 8) & 0xff;
  612. pxls[2][i] = (cl) & 0xff;
  613. }
  614. }
  615. float omega, min_phase, max_phase;
  616. int rw, rh;
  617. void apply() {
  618. buffer.setSize(canvas.width, canvas.height);
  619. min_omega = TWO_PI/(0.05*canvas.width);
  620. max_omega = TWO_PI/(300.0*canvas.width);
  621. rw = canvas.width;
  622. do_blend = boolean(int(params.get(0).getValue()));
  623. blend_mode = blends[(int)params.get(1).getValue()];
  624. omega = map(sqrt(params.get(2).getValue()), 0, 1, min_omega, max_omega);
  625. float phase = map(sq(params.get(3).getValue()), 0, 1, min_phase_mult, max_phase_mult);
  626. colorspace = (int)params.get(4).getValue();
  627. quantval = (int) params.get(5).getValue();
  628. if (rw != canvas.width || rh != canvas.height) {
  629. rw = canvas.width;
  630. rh = canvas.height;
  631. min_omega = TWO_PI/(0.05*canvas.width);
  632. max_omega = TWO_PI/(300.0*canvas.width);
  633. }
  634. prepareData();
  635. //buffer = canvas.get(0, 0, canvas.width, canvas.height);
  636. max_phase = phase * omega;
  637. min_phase = -max_phase;
  638. processImage();
  639. }
  640. void processImage() {
  641. buffer.beginDraw();
  642. buffer.loadPixels();
  643. int [][] dest_pxls = new int[3][canvas.pixels.length];
  644. if (first_channel_only) {
  645. arrayCopy(pxls[1], dest_pxls[1]);
  646. arrayCopy(pxls[2], dest_pxls[2]);
  647. }
  648. for (int i=0; i< (first_channel_only?1:3); i++) {
  649. for (int y=0; y<canvas.height; y++) {
  650. int off = y * canvas.width;
  651. //reset filters each line
  652. lpf1.resetFilter(map(pxls[i][off], 0, 255, min_phase, max_phase));
  653. lpf2.resetFilter(map(pxls[i][off], 0, 255, min_phase, max_phase));
  654. lpf3.resetFilter(map(pxls[i][off], 0, 255, min_phase, max_phase));
  655. float sig_int = 0; // integral of the signal
  656. float pre_m = 0; // previous value of modulated signal
  657. for (int x=0; x<canvas.width; x++) {
  658. /////////////////////////
  659. // FM part starts here
  660. /////////////////////////
  661. float sig = map(pxls[i][x+off], 0, 255, min_phase, max_phase); // current signal value
  662. sig_int += sig; // current value of signal integral
  663. float m = cos(omega * x + sig_int); // modulate signal
  664. if ( quantval > 0) {
  665. m = map((int)map(m, -1, 1, 0, quantval), 0, quantval, -1, 1); // quantize
  666. }
  667. float dem = abs(m-pre_m); // demodulate signal, derivative
  668. pre_m = m; // remember current value
  669. // lowpass filter chain
  670. if (lowpass1_on) dem = lpf1.lowpass(dem);
  671. if (lowpass2_on) dem = lpf2.lowpass(dem);
  672. if (lowpass3_on) dem = lpf3.lowpass(dem);
  673. // remap signal back to channel value
  674. int v = constrain( (int)map(2*(dem-omega), min_phase, max_phase, 0, 255), 0, 255);
  675. //////////////////////
  676. // FM part ends here
  677. //////////////////////
  678. dest_pxls[i][x+off] = negate?255-v:v;
  679. }
  680. }
  681. }
  682. for (int i=0; i<buffer.pixels.length; i++) {
  683. buffer.pixels[i] = fromColorspace(0xff000000 | (dest_pxls[0][i] << 16) | (dest_pxls[1][i] << 8) | (dest_pxls[2][i]), colorspace);
  684. }
  685. buffer.updatePixels();
  686. if (do_blend)
  687. buffer.blend(canvas, 0, 0, canvas.width, canvas.height, 0, 0, buffer.width, buffer.height, blend_mode);
  688. buffer.endDraw();
  689. canvas.beginDraw();
  690. canvas.image(buffer, canvas.width/2, canvas.height/2, canvas.width, canvas.height);
  691. canvas.endDraw();
  692. }
  693. class LowpassFilter {
  694. float alpha;
  695. float prev;
  696. public LowpassFilter(float rate, float hz) {
  697. alpha = 0.0;
  698. prev = 0.0;
  699. setFilter(rate, hz);
  700. }
  701. void setFilter(float rate, float hz) {
  702. float timeInterval = 1.0/rate;
  703. float tau = 1.0 / (hz * TWO_PI);
  704. alpha = timeInterval / (tau + timeInterval);
  705. }
  706. void resetFilter(float val) {
  707. prev = val;
  708. }
  709. void resetFilter() {
  710. resetFilter(0);
  711. }
  712. float lowpass(float sample) {
  713. float stage1 = sample * alpha;
  714. float stage2 = prev - (prev * alpha);
  715. prev = (stage1 + stage2);
  716. return prev;
  717. }
  718. float highpass(float sample) {
  719. return sample - lowpass(sample);
  720. }
  721. }
  722. }
  723. /*
  724. WZIP
  725. */
  726. class WZIP extends Shader {
  727. final float sqrt05 = sqrt(0.5);
  728. float[] raw, raw1, raw2, raw3;
  729. float[] in, w, out;
  730. float[] in1, in2, in3, out1, out2, out3;
  731. int n, n2, s;
  732. float scalingfactorin, scalingfactorout;
  733. PImage img;
  734. String sessionid;
  735. WZIP() {
  736. name = "fxWZIP";
  737. params.add(new Param ("scale", FLOATVAL, 0.1, 1000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  738. params.add(new Param ("factor in", FLOATVAL, 0.01, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  739. params.add(new Param ("factor out", FLOATVAL, 0.01, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  740. params.add(new Param("hsb/rgb", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
  741. params.add(new Param("mode", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
  742. params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM}));
  743. directionParamIndex = 5;
  744. sessionid = hex((int)random(0xffff), 4);
  745. img = createImage(canvas.width, canvas.height, ARGB);
  746. img = canvas.get(0, 0, canvas.width, canvas.height);
  747. }
  748. void apply() {
  749. // img = createImage(canvas.width, canvas.height, ARGB);
  750. img.resize(canvas.width, canvas.height);
  751. img = canvas.get(0, 0, canvas.width, canvas.height);
  752. s = img.width*img.height;
  753. raw = new float[s*3];
  754. raw1 = new float[s];
  755. raw2 = new float[s];
  756. raw3 = new float[s];
  757. canvas.beginDraw();
  758. canvas.background(0);
  759. canvas.noStroke();
  760. if (boolean((int)params.get(3).getValue())) { /////////////////////
  761. canvas.colorMode(HSB, 255);
  762. colorMode(HSB, 255);
  763. } else {
  764. canvas.colorMode(RGB, 255);
  765. colorMode(RGB, 255);
  766. }
  767. scalingfactorin = map(params.get(1).getValue(), 0, 1, 0, params.get(0).getValue()); /////////////////////
  768. scalingfactorout = map(params.get(2).getValue(), 0, 1, 0, params.get(0).getValue()); /////////////////////
  769. int iter=0;
  770. int iter2 = 0;
  771. for (int y=0; y<img.height; y++) {
  772. for (int x=0; x<img.width; x++) {
  773. color c = img.get(x, y);
  774. float r, g, b;
  775. if (boolean((int)params.get(3).getValue())) { /////////////////////
  776. r = hue(c)>127?hue(c)-256:hue(c);
  777. g = saturation(c)>127?saturation(c)-256:saturation(c);
  778. b = brightness(c)>127?brightness(c)-256:brightness(c);
  779. } else {
  780. r = red(c)>127?red(c)-256:red(c);
  781. g = green(c)>127?green(c)-256:green(c);
  782. b = blue(c)>127?blue(c)-256:blue(c);
  783. }
  784. raw[iter++] = r;
  785. raw[iter++] = g;
  786. raw[iter++] = b;
  787. raw1[iter2] = r;
  788. raw2[iter2] = g;
  789. raw3[iter2] = b;
  790. iter2++;
  791. }
  792. }
  793. n = (int)pow(2, ceil(log(s*3)/log(2)));
  794. n2 = (int)pow(2, ceil(log(s)/log(2)));
  795. in = new float[n];
  796. w = new float[n];
  797. out = new float[n];
  798. out1 = new float[n2];
  799. out2 = new float[n2];
  800. out3 = new float[n2];
  801. in1 = new float[n2];
  802. in2 = new float[n2];
  803. in3 = new float[n2];
  804. arrayCopy(raw, 0, in, 0, raw.length);
  805. for (int i=raw.length; i<n; i++) in[i] = raw[raw.length-1];
  806. arrayCopy(raw1, 0, in1, 0, s);
  807. arrayCopy(raw2, 0, in2, 0, s);
  808. arrayCopy(raw3, 0, in3, 0, s);
  809. for (int i=s; i<n2; i++) {
  810. in1[i] = raw1[s-1];
  811. in2[i] = raw2[s-1];
  812. in3[i] = raw3[s-1];
  813. }
  814. if (boolean((int)params.get(4).getValue())) option1(); /////////////////////
  815. else option2();
  816. canvas.colorMode(RGB);
  817. colorMode(RGB);
  818. canvas.endDraw();
  819. }
  820. float clamp(float c) {
  821. return(abs(c<0?256+c:c)%255.0);
  822. }
  823. void option2() {
  824. wtrafo(in1, n2);
  825. wbtrafo(out1, n2);
  826. wtrafo(in2, n2);
  827. wbtrafo(out2, n2);
  828. wtrafo(in3, n2);
  829. wbtrafo(out3, n2);
  830. for (int i=0; i<s; i++) {
  831. float r = clamp(out1[i]);
  832. float g = clamp(out2[i]);
  833. float b = clamp(out3[i]);
  834. canvas.fill(r, g, b);
  835. canvas.rect(i%canvas.width, i/canvas.width, 1, 1);
  836. }
  837. }
  838. void option1() {
  839. wtrafo(in, n);
  840. wbtrafo(out, n);
  841. float r=0, g=0, b=0;
  842. int state = 0;
  843. for (int i=0; i<raw.length; i++) {
  844. float c = clamp(out[i]);
  845. switch(state) {
  846. case 0:
  847. r = c;
  848. break;
  849. case 1:
  850. g = c;
  851. break;
  852. case 2:
  853. b = c;
  854. break;
  855. default:
  856. {
  857. r = c;
  858. canvas.fill(r, g, b);
  859. canvas.rect(floor(i/3.0)%canvas.width, floor(i/3.0)/canvas.width, 1, 1);
  860. state = 0;
  861. }
  862. }
  863. state++;
  864. }
  865. }
  866. void wbtrafo(float[] y, int n) {
  867. float[] d = new float[n];
  868. d[n-2] = w[n-1];
  869. int b1 = n-4;
  870. int b2 = n-2;
  871. int a=1;
  872. while (a<n/2) {
  873. for (int i=0; i<a; i++) {
  874. d[2*i+b1]=(d[i+b2]+w[i+b2])*sqrt05;
  875. d[2*i+1+b1]=(d[i+b2]-w[i+b2])*sqrt05;
  876. }
  877. b2=b1;
  878. b1=b1-4*a;
  879. a*=2;
  880. }
  881. for (int i=0; i<a; i++) {
  882. y[2*i]=(d[i]+w[i])*sqrt05;
  883. y[2*i+1]=(d[i]-w[i])*sqrt05;
  884. }
  885. for (int i=0; i<n; i++) y[i] *= scalingfactorout;
  886. }
  887. void wtrafo(float[] y, int n) {
  888. float[] d = new float[n];
  889. int a = n/2;
  890. for (int i=0; i<a; i++) {
  891. w[i] = (y[2*i]-y[2*i+1])*sqrt05;
  892. d[i] = (y[2*i]+y[2*i+1])*sqrt05;
  893. }
  894. int b1 = 0;
  895. int b2 = a;
  896. a/=2;
  897. while (a>0) {
  898. for (int i=0; i<a; i++) {
  899. w[i+b2]=(d[2*i+b1]-d[2*i+1+b1])*sqrt05;
  900. d[i+b2]=(d[2*i+b1]+d[2*i+1+b1])*sqrt05;
  901. }
  902. b1=b2;
  903. b2=b2+a;
  904. a/=2;
  905. }
  906. w[b2] = d[b1];
  907. for (int i=0; i<n-1; i++) w[i] = (int)(w[i]/scalingfactorin);
  908. if (w[n-1]>0) w[n-1] = (int)(w[n-1]/scalingfactorin+0.5);
  909. else w[n-1] = (int)(w[n-1]/scalingfactorin-0.5);
  910. }
  911. }
  912. /*
  913. AUECHO
  914. */
  915. class AUECHO extends Shader {
  916. final int[] blends = {BLEND, ADD, SUBTRACT, DARKEST, LIGHTEST, DIFFERENCE, EXCLUSION, MULTIPLY, SCREEN, OVERLAY, HARD_LIGHT, SOFT_LIGHT, DODGE, BURN};
  917. AUECHO() {
  918. name = "fxAUecho";
  919. params.add(new Param("mode", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
  920. params.add(new Param ("echo", FLOATVAL, 0.001, 1, new int[]{TRIANG, SINE, RAMPUPDOWN, }));
  921. params.add(new Param ("decay", FLOATVAL, 0.001, 1, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  922. params.add(new Param ("blend mode", INTVAL, 0, this.blends.length-1, new int[]{RANDOM }));
  923. params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM}));
  924. directionParamIndex = 4;
  925. }
  926. void apply() {
  927. canvas.beginDraw();
  928. if (boolean((int)params.get(0).getValue())) {
  929. canvas.colorMode(HSB);
  930. colorMode(HSB);
  931. } else {
  932. canvas.colorMode(RGB);
  933. colorMode(RGB);
  934. }
  935. canvas.loadPixels();
  936. float _delay = params.get(1).getValue();
  937. float decay = params.get(2).getValue();
  938. int delay = (int)(canvas.pixels.length * _delay);
  939. color[] history = new color[canvas.pixels.length];
  940. int blendMode =this.blends[(int)params.get(3).getValue()];
  941. for ( int i = 0, l = canvas.pixels.length; i<l; i++) {
  942. history[i] = canvas.pixels[i];
  943. }
  944. for ( int i = 0, l = canvas.pixels.length; i<l; i++) {
  945. int fromPos = i-delay < 0 ? l-abs(i-delay) : i-delay;
  946. color fromColor = history[fromPos];
  947. float r = red(fromColor) * decay;
  948. float g = green(fromColor) * decay;
  949. float b = blue(fromColor) * decay;
  950. color origColor = history[i];
  951. color toColor = color(
  952. r = r + red(origColor) > 255 ? r + red(origColor) - 255 : r + red(origColor), // simulate overflow ;)
  953. g = g + green(origColor) > 255 ? g + green(origColor) - 255 : g + green(origColor),
  954. b = b + blue(origColor) > 255 ? b + blue(origColor) - 255 : b + blue(origColor) );
  955. //canvas.pixels[i] = history[i] = toColor;
  956. canvas.pixels[i] = history[i] = blendColor(origColor, toColor, blendMode);
  957. }
  958. canvas.updatePixels();
  959. if (boolean((int)params.get(0).getValue())) {
  960. canvas.colorMode(RGB);
  961. colorMode(RGB);
  962. }
  963. canvas.endDraw();
  964. }
  965. }
  966. /*
  967. SLITSCAN
  968. */
  969. class SLITSCAN extends Shader {
  970. int[] fx;
  971. int[] fy;
  972. float[] phx;
  973. float[] phy;
  974. int[] sx, sy;
  975. boolean[] skipfx;
  976. boolean[] skipfy;
  977. boolean dox, doy;
  978. PImage buffer;
  979. float[][] ft = new float[2][32];
  980. //int depth; // number of octaves
  981. int fxnum;
  982. int fynum;
  983. SLITSCAN() {
  984. name = "fxSlitSscan";
  985. buffer = createImage(canvas.width, canvas.height, ARGB);
  986. params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM}));
  987. directionParamIndex = 0;
  988. int s = (int)(log(min(buffer.width, buffer.height))/log(2));
  989. olds = s;
  990. params.add(new Param("x num", INTVAL, 1, s, new int[]{RANDOM}));
  991. params.add(new Param("y num", INTVAL, 1, s, new int[]{RANDOM}));
  992. for (int i=0; i<32; i++) {
  993. ft[0][i] = pow(2.0, i);
  994. ft[1][i] = 0.5*1.0/ft[0][i];
  995. }
  996. }
  997. int olds, oldfxnum, oldfynum;
  998. void apply() {
  999. canvas.beginDraw();
  1000. canvas.colorMode(RGB);
  1001. canvas.noStroke();
  1002. colorMode(RGB);
  1003. canvas.fill(255);
  1004. buffer.resize(canvas.width, canvas.height);
  1005. buffer = canvas.get(0, 0, canvas.width, canvas.height);
  1006. //int s = buffer.width>buffer.height?buffer.height:buffer.width;
  1007. //int s = min(buffer.width, buffer.height);
  1008. //depth = (int)(log(s)/log(2));
  1009. int s = (int)(log(min(buffer.width, buffer.height))/log(2));
  1010. if (olds != s) {
  1011. olds = s;
  1012. changeParam(1, new Param("x num", INTVAL, 1, s, new int[]{RANDOM}));
  1013. changeParam(2, new Param("y num", INTVAL, 1, s, new int[]{RANDOM}));
  1014. }
  1015. //depth = (int)params.get(1).getValue();
  1016. //println(depth);
  1017. fxnum = (int)random(params.get(1).getValue());
  1018. fynum = (int)random(params.get(2).getValue());
  1019. fx = new int[fxnum+1];
  1020. fy = new int[fynum+1];
  1021. sx = new int[fxnum+1];
  1022. sy = new int[fynum+1];
  1023. phx = new float[fxnum+1];
  1024. phy = new float[fynum+1];
  1025. skipfx = new boolean[fxnum+1];
  1026. skipfy = new boolean[fynum+1];
  1027. for (int i=0; i<fxnum; i++) {
  1028. fx[i]=(int)random(6);
  1029. phx[i] = random(1);
  1030. skipfx[i] = random(1)<0.2;
  1031. sx[i] = random(1)<0.2?-1:1;
  1032. }
  1033. for (int i=0; i<fynum; i++) {
  1034. fy[i]=(int)random(6);
  1035. phy[i] = random(1);
  1036. skipfy[i] = random(1)<0.2;
  1037. sy[i] = random(1)<0.2?-1:1;
  1038. }
  1039. //dox = random(1)<0.8;
  1040. //doy = dox?random(1)<0.8:true;
  1041. dox = true;
  1042. doy = true;
  1043. float v=0;
  1044. for (int y=0; y<buffer.height; y++)
  1045. for (int x=0; x<buffer.width; x++) {
  1046. float iy = map(y, 0, buffer.height, 0, 1);
  1047. v=0;
  1048. if (doy) for (int i=0; i<fy.length; i++)
  1049. if (!skipfy[i]) v+=sy[i]*getValue(fy[i], iy, i, phy[i]);
  1050. float ry = 2*iy+v;
  1051. float y2 = (3*buffer.height+ry * buffer.height/2)%buffer.height;
  1052. float ix = map(x, 0, buffer.width, 0, 1);
  1053. v=0;
  1054. if (dox) for (int i=0; i<fx.length; i++)
  1055. if (!skipfx[i]) v+=sx[i]*getValue(fx[i], ix, i, phx[i]);
  1056. float rx = 2*ix+v;
  1057. float x2 = (3*buffer.width+rx * buffer.width/2)%buffer.width;
  1058. canvas.fill(buffer.get((int)x2, (int)y2));
  1059. canvas.rect(x, y, 1, 1);
  1060. }
  1061. canvas.endDraw();
  1062. }
  1063. float getValue(int fun, float idx, int freq, float phase) {
  1064. switch(fun) {
  1065. case 0:
  1066. return getSin(idx, freq, phase);
  1067. case 1:
  1068. return getSaw(idx, freq, phase);
  1069. case 2:
  1070. return getTriangle(idx, freq, phase);
  1071. case 3:
  1072. return getCutTriangle(idx, freq, phase);
  1073. case 4:
  1074. return getSquare(idx, freq, phase);
  1075. case 5:
  1076. return getNoise(idx, freq, phase);
  1077. default:
  1078. return getSin(idx, freq, phase);
  1079. }
  1080. }
  1081. float getNoise(float idx, int freq, float phase) {
  1082. return 2*ft[1][freq]*(noise((idx+phase)*ft[0][freq])-0.5);
  1083. }
  1084. float getSin(float idx, int freq, float phase) {
  1085. float p = ft[0][freq];
  1086. return ft[1][freq] * sin(idx*TWO_PI*p+phase*TWO_PI);
  1087. }
  1088. float getSaw(float idx, int freq, float phase) {
  1089. float p = ft[0][freq];
  1090. float rp = 2.0*ft[1][freq];
  1091. float p2 = p*((idx+phase+ft[1][freq])%1.0);
  1092. return rp*(p2-floor(p2)-0.5);
  1093. }
  1094. float getSquare(float idx, int freq, float phase) {
  1095. float p = ft[0][freq];
  1096. float rp = ft[1][freq];
  1097. return (((idx*p)+phase)%1.0)<0.5?rp:-rp;
  1098. }
  1099. float getTriangle(float idx, int freq, float phase) {
  1100. return 2*abs(getSaw(idx, freq, phase+0.5*ft[1][freq]))-ft[1][freq];
  1101. }
  1102. float getCutTriangle(float idx, int freq, float phase) {
  1103. return constrain(getTriangle(idx, freq, phase), -ft[1][freq+1], ft[1][freq+1]);
  1104. }
  1105. }
  1106. /*
  1107. WAHWAH
  1108. */
  1109. class WAHWAH extends Shader {
  1110. float sequence, lfoskip, xn1, xn2, yn1, yn2, b0, b1, b2, a0, a1, a2, freqofs, freq, freqoff, startsequence, res, depth;
  1111. float mCurRate = 0.4, skipcount = 0;
  1112. int lfoskipsamples = 0;
  1113. float frequency, omega, sn, cs, alpha;
  1114. float in, out;
  1115. float val;
  1116. WAHWAH() {
  1117. name = "fxWahWah";
  1118. //params.add(new Param("mode", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
  1119. params.add(new Param ("resolution", FLOATVAL, 1, 100, new int[]{TRIANG, SINE, RAMPUPDOWN, }));
  1120. params.add(new Param ("depth", FLOATVAL, 0.0001, 1, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  1121. params.add(new Param ("frequency offset", FLOATVAL, 0, 0.9, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  1122. params.add(new Param ("mCurRate", FLOATVAL, 0, 1, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  1123. params.add(new Param ("direction", INTVAL, 0, 3, new int[]{RANDOM}));
  1124. directionParamIndex = 4;
  1125. // params.add(new Param ("blend mode", INTVAL, 0, this.blends.length-1, new int[]{RANDOM }));
  1126. }
  1127. void apply() {
  1128. res = params.get(0).getValue();
  1129. depth = params.get(1).getValue();
  1130. freqofs = params.get(2).getValue();
  1131. //res = 12.5
  1132. //depth = 0.8;
  1133. //freqofs = 0.9;
  1134. freq = 1.5;
  1135. startsequence = 0.2;
  1136. lfoskip = freq * 2 * PI / mCurRate;
  1137. skipcount = xn1 = xn2 = yn1 = yn2 = b0 = b1 = b2 = a0 = a1 = a2 = 0;
  1138. sequence = startsequence;
  1139. canvas.beginDraw();
  1140. canvas.colorMode(RGB);
  1141. canvas.loadPixels();
  1142. float[] rgb = new float[3];
  1143. for ( int i = 0, len = canvas.pixels.length; i < len; i++) {
  1144. rgb[0] = red(canvas.pixels[i]);
  1145. rgb[1] = green(canvas.pixels[i]);
  1146. rgb[2] = blue(canvas.pixels[i]);
  1147. for ( int ri = 0; ri < 3; ri++ ) {
  1148. in = map(rgb[ri], 0, 255, 0, 1);
  1149. frequency = (1+cos(skipcount * lfoskip + sequence ))/2;
  1150. frequency = frequency * depth * (1-freqofs) + freqofs;
  1151. frequency = exp((frequency - 1) * 6 );
  1152. omega = PI * frequency;
  1153. sn = sin(omega);
  1154. cs = cos(omega);
  1155. alpha = sn/(2*res);
  1156. b0 = (1-cs) /2;
  1157. b1 = 1 - cs;
  1158. b2 = (1-cs)/2;
  1159. a0 = 1 + alpha;
  1160. a1 = -2 * cs;
  1161. a2 = 1 - alpha;
  1162. out = ( b0 * in + b1 * xn1 + b2 * xn2 - a1 * yn1 - a2 * yn2 ) / a0;
  1163. xn2 = xn1;
  1164. xn1 = in;
  1165. yn2 = yn1;
  1166. yn1 = out;
  1167. rgb[ri] = map(out, 0, 1, 0, 255);
  1168. }
  1169. canvas.pixels[i] = color(rgb[0], rgb[1], rgb[2]);
  1170. }
  1171. canvas.updatePixels();
  1172. canvas.endDraw();
  1173. }
  1174. }
  1175. /*
  1176. PHASER
  1177. */
  1178. class PHASER extends Shader {
  1179. //float samplerate = 92230.0; // try setting this to 44100.0 or 2048.5 for kicks
  1180. float samplerate = 44100; // try setting this to 44100.0 or 2048.5 for kicks
  1181. int mode;
  1182. PHASER() {
  1183. name ="fxPhaser";
  1184. params.add(new Param("mode", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
  1185. params.add(new Param ("frequency", FLOATVAL, 0.1, 40.0, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  1186. params.add(new Param ("depth", INTVAL, 1, 255, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  1187. params.add(new Param ("feedback", INTVAL, -100, 100, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  1188. params.add(new Param ("phase", FLOATVAL, 0, TWO_PI, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  1189. params.add(new Param ("stages", INTVAL, 1, 24, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  1190. params.add(new Param ("sample rate", FLOATVAL, 512, 92230, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  1191. params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM}));
  1192. directionParamIndex = 7;
  1193. //params.add(new Param ("frequency offset", FLOATVAL, 0, 1, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  1194. }
  1195. /*
  1196. mDepth = (int) map(knobZero, 0, 255, 255, 0);
  1197. mFeedback = (int) map(knobOne, 0, 255, -100, 100);
  1198. // enable these for some more fun :)
  1199. if (mode == 1) {
  1200. mSampleRate = map(knobTwo, 0, 255, 1, 512);
  1201. mStages = (int) ( 2*map(knobThree, 0, 255, 1, 12));
  1202. }
  1203. */
  1204. void apply() {
  1205. mode = (int)params.get(0).getValue();
  1206. float mFreq = params.get(1).getValue();
  1207. int mDryWet = 255;
  1208. int mDepth = (int)params.get(2).getValue();
  1209. int mFeedback = (int)params.get(3).getValue();
  1210. float mPhase = params.get(4).getValue();
  1211. //these two are only changed if mode = 1
  1212. int mStages = 2;
  1213. float mSampleRate = samplerate;
  1214. canvas.beginDraw();
  1215. canvas.loadPixels();
  1216. //constants
  1217. float phaserlfoshape = 4.0;
  1218. int lfoskipsamples = 20; //how many samples are processed before recomputing lfo
  1219. int numStages = 24;
  1220. //getParams
  1221. /*
  1222. Phaser Parameters
  1223. mFreq - Phaser's LFO frequency
  1224. mPhase - Phaser's LFO startsequence (radians), needed for stereo Phasers
  1225. mDepth - Phaser depth (0 - no depth, 255 - max depth)
  1226. mStages - Phaser stages (recomanded from 2 to 16-24, and EVEN NUMBER)
  1227. mDryWet - Dry/wet mix, (0 - dry, 128 - dry=wet, 255 - wet)
  1228. mFeedback - Phaser FeedBack (0 - no feedback, 100 = 100% Feedback,
  1229. -100 = -100% FeedBack)
  1230. */
  1231. // enable these for some more fun :)
  1232. if (mode == 1) {
  1233. mStages = (int)params.get(5).getValue();
  1234. mSampleRate = params.get(6).getValue();
  1235. }
  1236. //init
  1237. float gain = 0, fbout = 0;
  1238. float lfoskip = mFreq * 2 * PI / mSampleRate;
  1239. float sequence = mPhase * PI / 180;
  1240. float[] old = new float[mStages];
  1241. for ( int j = 0; j < mStages; j++) {
  1242. old[j] = 0.0;
  1243. }
  1244. /* EffectPhaser::ProcessBlock */
  1245. int skipcount = 0;
  1246. float[] rgb = new float[3];
  1247. for ( int i = 0, l = canvas.pixels.length; i<l; i++ ) {
  1248. color c = canvas.pixels[i];
  1249. rgb[0] = map(red(c), 0, 255, 0, 1);
  1250. rgb[1] = map(green(c), 0, 255, 0, 1);
  1251. rgb[2] = map(blue(c), 0, 255, 0, 1);
  1252. for ( int ci = 0; ci < 3; ci++) {
  1253. float in = rgb[ci];
  1254. float m = in + fbout * mFeedback / 100;
  1255. if ( (( skipcount++) % lfoskipsamples ) == 0 ) { //recomopute lfo
  1256. gain = (1.0 + cos(skipcount * lfoskip + sequence)) / 2.0; //compute sine between 0 and 1
  1257. gain = exp(gain * phaserlfoshape) / exp(phaserlfoshape); // change lfo shape
  1258. gain = 1.0 - gain / 255.0 * mDepth; // attenuate the lfo
  1259. }
  1260. //phasing routine
  1261. for ( int j = 0; j<mStages; j++) {
  1262. float tmp = old[j];
  1263. old[j] = gain * tmp + m;
  1264. m = tmp - gain * old[j];
  1265. }
  1266. fbout = m;
  1267. rgb[ci] = (float) (( m * mDryWet + in * (255-mDryWet)) / 255);
  1268. }
  1269. color rc = color(
  1270. map(rgb[0], 0, 1, 0, 255),
  1271. map(rgb[1], 0, 1, 0, 255),
  1272. map(rgb[2], 0, 1, 0, 255));
  1273. canvas.pixels[i] = rc;
  1274. }
  1275. canvas.updatePixels();
  1276. canvas.endDraw();
  1277. }
  1278. }
  1279. /*
  1280. ECHO
  1281. */
  1282. class ECHO extends Shader {
  1283. int mode = 0;
  1284. PImage result;
  1285. ECHO() {
  1286. name = "fxEcho";
  1287. params.add(new Param("mode", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
  1288. params.add(new Param ("xp", INTVAL, 0, 100, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  1289. params.add(new Param ("yp", INTVAL, 0, 100, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  1290. params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM}));
  1291. directionParamIndex = 3;
  1292. result = createImage(canvas.width, canvas.height, RGB);
  1293. }
  1294. void apply() {
  1295. mode = (int)params.get(0).getValue();
  1296. int xp = (int)params.get(1).getValue();
  1297. int yp = (int)params.get(2).getValue();
  1298. canvas.beginDraw();
  1299. canvas.colorMode(RGB);
  1300. colorMode(RGB);
  1301. canvas.imageMode(CORNER);
  1302. if (mode == 0) {
  1303. canvas.image(auEcho(canvas, xp, yp), 0, 0);
  1304. } else if (mode == 1) {
  1305. canvas.image(auEchoWTF(canvas, xp, yp), 0, 0);
  1306. }
  1307. canvas.endDraw();
  1308. }
  1309. PImage auEcho(PImage img, int xp, int yp) {
  1310. result.resize(img.width, img.height);
  1311. float _delay = map(xp, 0, 100, 0.001, 1.0);
  1312. float decay = map(yp, 0, 100, 0.0, 1.0);
  1313. int delay = (int)(img.pixels.length * _delay);
  1314. color[] history = new color[img.pixels.length];
  1315. int blendMode = BLEND;
  1316. img.loadPixels();
  1317. result.loadPixels();
  1318. for ( int i = 0, l = img.pixels.length; i<l; i++) {
  1319. history[i] = img.pixels[i];
  1320. }
  1321. for ( int i = 0, l = img.pixels.length; i<l; i++) {
  1322. int fromPos = i-delay < 0 ? l-abs(i-delay) : i-delay;
  1323. color fromColor = history[fromPos];
  1324. float r = red(fromColor) * decay;
  1325. float g = green(fromColor) * decay;
  1326. float b = blue(fromColor) * decay;
  1327. color origColor = history[i];
  1328. color toColor = color(
  1329. r + red(origColor),
  1330. g + green(origColor),
  1331. b + blue(origColor) );
  1332. result.pixels[i] = history[i] = blendColor(origColor, toColor, blendMode);
  1333. }
  1334. return result;
  1335. }
  1336. PImage auEchoWTF(PImage img, int xp, int yp) {
  1337. result.resize(img.width, img.height);
  1338. float delay = map(xp, 0, 100, 0.001, 5);
  1339. float decay = map(yp, 0, 100, 0.0, 5.0);
  1340. int histPos = 0;
  1341. int histLen = img.pixels.length*3;
  1342. float[] history = new float[histLen*3];
  1343. img.loadPixels();
  1344. result.loadPixels();
  1345. float ibuf = 0.0, obuf = 0.0;
  1346. float[] rgb = new float[3];
  1347. for ( int i = 0, l = img.pixels.length; i<l; i++, histPos++) {
  1348. color c = img.pixels[i];
  1349. rgb[0] = map(red(c), 0, 255, 0, 1);
  1350. rgb[1] = map(green(c), 0, 255, 0, 1);
  1351. rgb[2] = map(blue(c), 0, 255, 0, 1);
  1352. history[i] = rgb[0];
  1353. history[i+1] = rgb[1];
  1354. history[i+2] = rgb[2];
  1355. }
  1356. for ( int i = 0, l = img.pixels.length; i<l; i++, histPos++) {
  1357. color c = img.pixels[i];
  1358. rgb[0] = map(red(c), 0, 255, 0, 1);
  1359. rgb[1] = map(green(c), 0, 255, 0, 1);
  1360. rgb[2] = map(blue(c), 0, 255, 0, 1);
  1361. if ( histPos == histLen ) histPos = 0;
  1362. for ( int ri = 0; ri < 3; ri++ ) {
  1363. history[histPos+ri] = rgb[ri] = rgb[ri] + history[histPos+ri] * decay;
  1364. }
  1365. color out = color(
  1366. (int)map(rgb[0], 0, 1, 0, 255),
  1367. (int)map(rgb[1], 0, 1, 0, 255),
  1368. (int)map(rgb[2], 0, 1, 0, 255));
  1369. result.pixels[i] = out;
  1370. }
  1371. return result;
  1372. }
  1373. }
  1374. /*
  1375. DARKER
  1376. */
  1377. class DARKER extends Shader {
  1378. float thresh = 127;
  1379. float darken = 150;
  1380. int mode = 1;
  1381. int bangCount = 0;
  1382. DARKER() {
  1383. name = "fxDarker";
  1384. params.add(new Param("count", INTVAL, 1, 4, new int[]{TRIANG, SINE, RAMPUPDOWN, TAN, TANINVERSE}));
  1385. params.add(new Param("threshold", INTVAL, 60, 180, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  1386. params.add(new Param("darken", INTVAL, 140, 220, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  1387. params.add(new Param("mode", INTVAL, 0, 1, new int[]{SQUAR, RANDOM}));
  1388. //thresh = int(random(60, 180));
  1389. //darken = int(random(140, 220));
  1390. }
  1391. void apply() {
  1392. // bright = knobZero;
  1393. int count = int(params.get(0).getValue());
  1394. darken = int(params.get(1).getValue());
  1395. thresh = int(params.get(2).getValue());
  1396. mode = int(params.get(3).getValue());
  1397. canvas.beginDraw();
  1398. canvas.colorMode(HSB);
  1399. colorMode(HSB);
  1400. canvas.loadPixels();
  1401. if (mode == 0) {
  1402. for (int h = 1; h < count+1; h++) {
  1403. for (int i = 0; i < canvas.width*canvas.height; i++) {
  1404. float hue = hue(canvas.pixels[i]);
  1405. float sat = saturation(canvas.pixels[i]);
  1406. float bright = brightness(canvas.pixels[i]);
  1407. if (bright > thresh/h) {
  1408. bright -= darken/h;
  1409. constrain(bright, 0, 255);
  1410. }
  1411. color c = color(hue, sat, bright);
  1412. canvas.pixels[i] = c;
  1413. }
  1414. }
  1415. } else if (mode == 1) {
  1416. for (int h = 1; h < count+1; h++) {
  1417. for (int i = 0; i < canvas.width*canvas.height; i++) {
  1418. float hue = hue(canvas.pixels[i]);
  1419. float sat = saturation(canvas.pixels[i]);
  1420. float bright = brightness(canvas.pixels[i]);
  1421. if (bright < thresh/h) {
  1422. bright -= darken/h;
  1423. constrain(bright, 0, 255);
  1424. }
  1425. color c = color(hue, sat, bright);
  1426. canvas.pixels[i] = c;
  1427. }
  1428. }
  1429. }
  1430. canvas.updatePixels();
  1431. canvas.endDraw();
  1432. colorMode(RGB);
  1433. }
  1434. }
  1435. /*
  1436. BRIGHTER
  1437. */
  1438. class BRIGHTER extends Shader {
  1439. float thresh = 120;
  1440. float thresh2 = 150;
  1441. float brighten = 180;
  1442. float speed;
  1443. BRIGHTER() {
  1444. name = "fxBrighter";
  1445. params.add(new Param("threshold", INTVAL, 0, 255, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  1446. params.add(new Param("threshold 2", INTVAL, 0, 255, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  1447. params.add(new Param("brighten", INTVAL, 0, 255, new int[]{TRIANG, SINE, RAMPUPDOWN }));
  1448. }
  1449. void apply() {
  1450. brighten = int(params.get(2).getValue());
  1451. thresh2 = int(params.get(1).getValue());
  1452. thresh = int(params.get(0).getValue());
  1453. canvas.beginDraw();
  1454. canvas.colorMode(HSB);
  1455. colorMode(HSB);
  1456. canvas.loadPixels();
  1457. for (int i = 0; i < canvas.width*canvas.height; i++) {
  1458. float hue = hue(canvas.pixels[i]);
  1459. float sat = saturation(canvas.pixels[i]);
  1460. float bright = brightness(canvas.pixels[i]);
  1461. if (bright < thresh && bright > thresh2) {
  1462. bright += brighten;
  1463. constrain(bright, 0, 255);
  1464. }
  1465. color c = color(hue, sat, bright);
  1466. canvas.pixels[i] = c;
  1467. }
  1468. canvas.colorMode(RGB);
  1469. canvas.updatePixels();
  1470. canvas.endDraw();
  1471. colorMode(RGB);
  1472. }
  1473. }
  1474. /*
  1475. AMPLIFY
  1476. */
  1477. //13
  1478. class AMPLIFY extends Shader {
  1479. int spawnT;
  1480. float h, s, b;
  1481. AMPLIFY() {
  1482. name = "fxAmplify";
  1483. params.add(new Param("hue / red", FLOATVAL, -255, 255, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  1484. params.add(new Param("saturation / green", FLOATVAL, -255, 255, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  1485. params.add(new Param("brightness / blue", FLOATVAL, -255, 255, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  1486. params.add(new Param("RGB / HSB", INTVAL, 0, 1, new int[]{SQUAR, RANDOM}));
  1487. }
  1488. void apply() {
  1489. canvas.beginDraw();
  1490. if (params.get(3).getValue() > 0) colorMode(HSB);
  1491. else {
  1492. colorMode(RGB);
  1493. }
  1494. canvas.loadPixels();
  1495. for (int i = 0; i < canvas.width*canvas.height; i++) {
  1496. float h = hue(canvas.pixels[i]);
  1497. float s = saturation(canvas.pixels[i]);
  1498. float b = brightness(canvas.pixels[i]);
  1499. canvas.pixels[i] = color(h+params.get(0).getValue(), s+params.get(1).getValue(), b+params.get(2).getValue());
  1500. }
  1501. canvas.updatePixels();
  1502. canvas.endDraw();
  1503. colorMode(RGB);
  1504. }
  1505. }
  1506. /*
  1507. BROKENCOLORROT
  1508. */
  1509. class BROKENCOLORROT extends Shader {
  1510. int spawnT;
  1511. float h, s, b;
  1512. BROKENCOLORROT() {
  1513. name = "fxBrokenColorRot";
  1514. params.add(new Param("hue", INTVAL, 0, 255, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  1515. params.add(new Param("saturation", INTVAL, 0, 255, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  1516. params.add(new Param("brightness", INTVAL, 0, 255, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  1517. params.add(new Param("mode", INTVAL, 0, 1, new int[]{SQUAR, RANDOM}));
  1518. params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM}));
  1519. directionParamIndex = 4;
  1520. }
  1521. void apply() {
  1522. canvas.beginDraw();
  1523. if (params.get(3).getValue() > 0) colorMode(HSB);
  1524. else {
  1525. colorMode(RGB);
  1526. }
  1527. canvas.loadPixels();
  1528. float h = params.get(0).getValue();
  1529. float s = params.get(1).getValue();
  1530. float b = params.get(2).getValue();
  1531. for (int i = 0; i < canvas.width*canvas.height; i++) {
  1532. h = hue(canvas.pixels[i])+h;
  1533. if (h > 255) h -= 255;
  1534. s = saturation(canvas.pixels[i])+s;
  1535. if (s > 255) s -= 255;
  1536. b = brightness(canvas.pixels[i])+b;
  1537. if (b > 255) b -= 255;
  1538. canvas.pixels[i] = color(h, s, b);
  1539. }
  1540. canvas.updatePixels();
  1541. canvas.endDraw();
  1542. colorMode(RGB);
  1543. }
  1544. }
  1545. /*
  1546. POSTERIZE
  1547. */
  1548. class POSTER extends Shader {
  1549. int levels = 2;
  1550. POSTER() {
  1551. name = "fxPosterize";
  1552. params.add(new Param("levels", INTVAL, 2, 10, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  1553. }
  1554. void apply() {
  1555. levels = (int)params.get(0).getValue();
  1556. canvas.beginDraw();
  1557. canvas.filter(POSTERIZE, levels);
  1558. canvas.endDraw();
  1559. }
  1560. }
  1561. /*
  1562. DUAL
  1563. */
  1564. class DUAL extends Shader {
  1565. PImage buffer;
  1566. int dualColor;
  1567. int dirx = 1;
  1568. int diry = 1;
  1569. DUAL() {
  1570. name = "fxDual";
  1571. params.add(new Param("dual color", INTVAL, 2000000, 15000000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  1572. params.add(new Param("flip direction", INTVAL, 0, 3, new int[]{RANDOM}));
  1573. params.add(new Param("mode", INTVAL, 0, 1, new int[]{SQUAR, RANDOM}));
  1574. params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM}));
  1575. directionParamIndex = 3;
  1576. buffer = createImage(canvas.width, canvas.height, ARGB);
  1577. }
  1578. void apply() {
  1579. switch((int)params.get(1).getValue()) {
  1580. case(0):
  1581. dirx = 1;
  1582. diry = 1;
  1583. break;
  1584. case(1):
  1585. dirx = -1;
  1586. diry = 1;
  1587. break;
  1588. case(2):
  1589. dirx = 1;
  1590. diry = -1;
  1591. break;
  1592. case(3):
  1593. dirx = -1;
  1594. diry = -1;
  1595. break;
  1596. }
  1597. dualColor = (int)params.get(0).getValue();
  1598. buffer.resize(canvas.width, canvas.height);
  1599. canvas.beginDraw();
  1600. canvas.imageMode(CORNER);
  1601. canvas.loadPixels();
  1602. buffer.loadPixels();
  1603. if ((int)params.get(2).getValue() > 0) {
  1604. for (int i = 0; i < canvas.width*canvas.height; i++) {
  1605. buffer.pixels[i] = canvas.pixels[i]+dualColor;
  1606. }
  1607. } else {
  1608. for (int i = 0; i < canvas.width*canvas.height; i++) {
  1609. buffer.pixels[i] = canvas.pixels[i]+dualColor;
  1610. buffer.pixels[i] = buffer.pixels[i]+i/10;
  1611. }
  1612. }
  1613. buffer.updatePixels();
  1614. canvas.updatePixels();
  1615. canvas.pushMatrix();
  1616. canvas.scale(dirx, diry);
  1617. canvas.image(buffer, 0, 0, dirx * canvas.width, diry * canvas.height);
  1618. canvas.popMatrix();
  1619. canvas.endDraw();
  1620. }
  1621. }
  1622. /*
  1623. GRAUZONE
  1624. */
  1625. class GRAUZONE extends Shader {
  1626. int nFrames = 20;
  1627. int iWrite = 0, iRead = 1;
  1628. PImage[] buffer;
  1629. PGraphics grauz;
  1630. GRAUZONE() {
  1631. name = "fxGrauzone";
  1632. params.add(new Param("delay (in frames)", INTVAL, 3, 100, new int[]{RANDOM}));
  1633. nFrames = (int)params.get(0).getValue();
  1634. buffer = new PImage[nFrames];
  1635. }
  1636. int nFramesPrev;
  1637. void apply() {
  1638. nFramesPrev = nFrames;
  1639. if (nFramesPrev != (int)params.get(0).getValue()) {
  1640. iWrite = 0;
  1641. iRead = 1;
  1642. int nFramesOld = nFrames;
  1643. nFrames = (int)params.get(0).getValue();
  1644. if (nFrames > nFramesOld) {
  1645. buffer = new PImage[nFrames];
  1646. }
  1647. }
  1648. buffer[iWrite] = canvas.get();
  1649. grauz = createGraphics(canvas.width, canvas.height);
  1650. grauz.beginDraw();
  1651. // grauz.resize(canvas.width, canvas.height);
  1652. buffer[iWrite] = canvas.get();
  1653. if (buffer[iRead] != null) {
  1654. grauz.tint(255, 127);
  1655. buffer[iRead].filter(INVERT);
  1656. grauz.image(buffer[iRead], 0, 0, canvas.width, canvas.height);
  1657. grauz.tint(255, 255);
  1658. }
  1659. grauz.endDraw();
  1660. canvas.beginDraw();
  1661. canvas.imageMode(CORNER);
  1662. canvas.image(grauz, 0, 0, canvas.width, canvas.height);
  1663. canvas.endDraw();
  1664. iWrite++;
  1665. iRead++;
  1666. if (iRead >= nFrames-1) {
  1667. iRead = 0;
  1668. }
  1669. if (iWrite >= nFrames-1) {
  1670. iWrite = 0;
  1671. }
  1672. }
  1673. }
  1674. /*
  1675. COPYZOOM
  1676. */
  1677. class COPYZOOM extends Shader {
  1678. int coprx, copry, coprw, coprh;
  1679. PImage buffer;
  1680. COPYZOOM() {
  1681. name = "fxCopyZoom";
  1682. params.add(new Param("w", FLOATVAL, 0, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  1683. params.add(new Param("h", FLOATVAL, 0, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  1684. params.add(new Param("x", FLOATVAL, 0, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  1685. params.add(new Param("y", FLOATVAL, 0, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  1686. buffer = createImage(canvas.width, canvas.height, ARGB);
  1687. }
  1688. void apply() {
  1689. canvas.imageMode(CORNER);
  1690. if (buffer.width != canvas.width || buffer.height != canvas.height) buffer.resize(canvas.width, canvas.height);
  1691. buffer = canvas.get();
  1692. coprw = int(map(params.get(0).getValue(), 0, 1, 1, canvas.width));
  1693. coprh = int(map(params.get(1).getValue(), 0, 1, 1, canvas.height));
  1694. coprx = int(map(params.get(2).getValue(), 0, 1, 0, canvas.width-coprw));
  1695. copry = int(map(params.get(3).getValue(), 0, 1, 0, canvas.height-coprh));
  1696. canvas.beginDraw();
  1697. buffer.copy(coprx, copry, coprw, coprh, 0, 0, canvas.width, canvas.height);
  1698. canvas.image(buffer, 0, 0, canvas.width, canvas.height);
  1699. canvas.endDraw();
  1700. }
  1701. }
  1702. /*
  1703. SUBTLESORT
  1704. */
  1705. class SUBTLESORT extends Shader {
  1706. int direction = 0;
  1707. int mode = 0;
  1708. int c;
  1709. //int count = int(random(777));
  1710. color col;
  1711. final static int RED = 0;
  1712. final static int GREEN = 1;
  1713. final static int BLUE = 2;
  1714. final static int HUE = 3;
  1715. final static int SATURATION = 4;
  1716. final static int BRIGHTNESS = 5;
  1717. final static int NRED = 6;
  1718. final static int NGREEN = 7;
  1719. final static int NBLUE = 8;
  1720. final static int NHUE = 9;
  1721. final static int NSATURATION = 10;
  1722. final static int NBRIGHTNESS = 11;
  1723. // channels for depth: RED, GREEN, BLUE, HUE, SATURATION, BRIGHTNESS, NRED, NGREEN, NBLUE, NHUE, NSATURATION, NBRIGHTNESS.
  1724. int channel = BRIGHTNESS;
  1725. // channel weight.
  1726. float channel_weight = .2;
  1727. //
  1728. SUBTLESORT() {
  1729. name ="fxSubtleSort";
  1730. params.add(new Param ("channel weight", FLOATVAL, 0.001, 20, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  1731. params.add(new Param ("channel", INTVAL, 0, 6, new int[]{RANDOM}));
  1732. //params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM}));
  1733. params.add(new Param("mode", INTVAL, 0, 1, new int[]{SQUARE, RANDOM}));
  1734. params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM}));
  1735. directionParamIndex = 3;
  1736. }
  1737. void apply() {
  1738. channel_weight = map(renderSize, 4, 15000, 0, 1.5)*params.get(0).getValue();
  1739. channel = (int)params.get(1).getValue();
  1740. direction = (int)params.get(2).getValue();
  1741. mode = (int)params.get(3).getValue();
  1742. canvas.beginDraw();
  1743. canvas.noStroke();
  1744. //if (direction == 0) {
  1745. for (int i = 0; i < canvas.width; i++) {
  1746. for (int j = 0; j < canvas.height; j++) {
  1747. c = i+(j*canvas.width);
  1748. col = canvas.pixels[c];
  1749. canvas.fill(col);
  1750. canvas.rect(i, j+(getChannel(col)), 1, getChannel(col));
  1751. }
  1752. }
  1753. //}
  1754. /*else if (direction == 1) {
  1755. for (int i = 0; i < canvas.width; i++) {
  1756. for (int j = 0; j < canvas.height; j++) {
  1757. c = i+(j*canvas.width);
  1758. col = canvas.pixels[c];
  1759. canvas.fill(col);
  1760. canvas.rect(i, j-(getChannel(col)*mode), 1, -getChannel(col));
  1761. }
  1762. }
  1763. } else if (direction == 2) {
  1764. for (int i = 0; i < canvas.width; i++) {
  1765. for (int j = 0; j < canvas.height; j++) {
  1766. c = i+(j*canvas.width);
  1767. col = canvas.pixels[c];
  1768. canvas.fill(col);
  1769. canvas.rect(i-(getChannel(col)*mode), j, -getChannel(col), 1);
  1770. }
  1771. }
  1772. } else if (direction == 3) {
  1773. for (int i = 0; i < canvas.width; i++) {
  1774. for (int j = 0; j < canvas.height; j++) {
  1775. c = i+(j*canvas.width);
  1776. col = canvas.pixels[c];
  1777. canvas.fill(col);
  1778. canvas.rect(i+(getChannel(col)), j, getChannel(col), 1);
  1779. }
  1780. }
  1781. }*/
  1782. canvas.endDraw();
  1783. }
  1784. float getChannel(color c) {
  1785. int ch = channel;
  1786. float cc;
  1787. switch(ch) {
  1788. case RED:
  1789. cc = red(c);
  1790. break;
  1791. case GREEN:
  1792. cc = green(c);
  1793. break;
  1794. case BLUE:
  1795. cc = blue(c);
  1796. break;
  1797. case HUE:
  1798. cc = hue(c);
  1799. break;
  1800. case SATURATION:
  1801. cc = saturation(c);
  1802. break;
  1803. default:
  1804. cc= brightness(c);
  1805. break;
  1806. }
  1807. return channel_weight * (channel>5?255-cc:cc);
  1808. }
  1809. }
  1810. /*
  1811. SCANKER
  1812. */
  1813. class SCANKER extends Shader {
  1814. int mode;
  1815. SCANKER() {
  1816. name = "fxScanker";
  1817. params.add(new Param ("detail level 1", FLOATVAL, 0.001, 1000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  1818. params.add(new Param ("detail level 2", FLOATVAL, -50, 50, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  1819. params.add(new Param ("detail level 3", FLOATVAL, -5, 5, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  1820. params.add(new Param ("mode", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
  1821. params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM}));
  1822. directionParamIndex = 4;
  1823. }
  1824. void apply() {
  1825. mode = (int)params.get(3).getValue();
  1826. canvas.beginDraw();
  1827. canvas.loadPixels();
  1828. float factor = params.get(0).getValue() + params.get(1).getValue() + params.get(2).getValue();
  1829. if (mode == 0) {
  1830. for (int i = 0; i < canvas.width*canvas.height; i++) {
  1831. // canvas.pixels[i] = canvas.pixels[i]+((i/1000)*scankMulti);
  1832. canvas.pixels[i] = canvas.pixels[i]-int(map(i, 0, canvas.width*canvas.height, 0, source.width*source.height)/10*factor);
  1833. }
  1834. } else if (mode == 1) {
  1835. for (int i = 0; i < canvas.width*canvas.height; i++) {
  1836. // canvas.pixels[i] = canvas.pixels[i]+((i/1000)*scankMulti);
  1837. canvas.pixels[i] = canvas.pixels[i]+int(map(i, 0, canvas.width*canvas.height, 0, source.width*source.height)/10*factor);
  1838. }
  1839. }
  1840. canvas.updatePixels();
  1841. canvas.endDraw();
  1842. }
  1843. }
  1844. /*
  1845. MASK
  1846. */
  1847. class MASK extends Shader {
  1848. int backgroundLayer, maskLayer, bandwidth, val, chan, shaderListLength, invert, blend_mode;
  1849. boolean do_blend;
  1850. PImage mask;
  1851. PImage background;
  1852. PImage foreground;
  1853. MASK() {
  1854. name = "mask";
  1855. shaderListLength = gui.shaderList.size();
  1856. params.add(new Param("target layer", INTVAL, 0, shaderListLength-2, new int[]{RANDOM}));
  1857. params.add(new Param("mask layer", INTVAL, 0, shaderListLength-1, new int[]{RANDOM}));
  1858. params.add(new Param("invert", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
  1859. params.add(new Param("bandwidth", INTVAL, 0, 255, new int[]{TRIANG, SINE}));
  1860. params.add(new Param("value", INTVAL, 1, 255, new int[]{TRIANG, SINE}));
  1861. params.add(new Param("channel (R/G/B/H/S/V", INTVAL, 0, 5, new int[]{RANDOM}));
  1862. params.add(new Param("do blend", INTVAL, 0, 1, new int[]{RANDOM}));
  1863. params.add(new Param("blend mode", INTVAL, 0, blends.length-1, new int[]{RANDOM}));
  1864. background = createImage(canvas.width, canvas.height, ARGB);
  1865. mask = createImage(canvas.width, canvas.height, ARGB);
  1866. foreground = createImage(canvas.width, canvas.height, ARGB);
  1867. }
  1868. void apply() {
  1869. if (shaderListLength != gui.shaderList.size()) {
  1870. shaderListLength = gui.shaderList.size();
  1871. changeParam(0, new Param("target layer", INTVAL, 0, shaderListLength-2, new int[]{RANDOM}));
  1872. changeParam(1, new Param("mask layer", INTVAL, 0, shaderListLength-1, new int[]{RANDOM}));
  1873. }
  1874. if (mask.width != canvas.width || mask.height != canvas.height) mask.resize(canvas.width, canvas.height);
  1875. if (background.width != canvas.width || background.height != canvas.height) background.resize(canvas.width, canvas.height);
  1876. if (foreground.width != canvas.width || foreground.height != canvas.height) foreground.resize(canvas.width, canvas.height);
  1877. backgroundLayer = (int)params.get(0).getValue();
  1878. maskLayer = (int)params.get(1).getValue();
  1879. invert = (int)params.get(2).getValue();
  1880. bandwidth = (int)params.get(3).getValue();
  1881. val = (int)params.get(4).getValue();
  1882. chan = (int)params.get(5).getValue();
  1883. do_blend = boolean((int)params.get(6).getValue());
  1884. blend_mode = blends[(int)params.get(7).getValue()];
  1885. if (backgroundLayer <= 0) {
  1886. background.resize(source.width, source.height);
  1887. background = source.get();
  1888. background.resize(canvas.width, canvas.height);
  1889. } else background = gui.shaderList.get(backgroundLayer-1).result.get();
  1890. if (maskLayer <= 0) {
  1891. mask.resize(source.width, source.height);
  1892. mask = source.get();
  1893. mask.resize(canvas.width, canvas.height);
  1894. } else mask = gui.shaderList.get(maskLayer-1).result.get();
  1895. canvas.beginDraw();
  1896. canvas.imageMode(CORNER);
  1897. mask.loadPixels();
  1898. foreground.loadPixels();
  1899. canvas.loadPixels();
  1900. if (boolean(invert)) {
  1901. for (int i = 0; i < canvas.width * canvas.height; i++) {
  1902. if (!thresh(color(mask.pixels[i])))
  1903. foreground.pixels[i] = canvas.pixels[i];
  1904. else
  1905. foreground.pixels[i] = background.pixels[i];
  1906. }
  1907. } else {
  1908. for (int i = 0; i < canvas.width * canvas.height; i++) {
  1909. if (thresh(color(mask.pixels[i])))
  1910. foreground.pixels[i] = canvas.pixels[i];
  1911. else
  1912. foreground.pixels[i] = background.pixels[i];
  1913. }
  1914. }
  1915. canvas.updatePixels();
  1916. foreground.updatePixels();
  1917. mask.updatePixels();
  1918. if (do_blend)
  1919. canvas.blend(foreground, 0, 0, foreground.width, foreground.height, 0, 0, canvas.width, canvas.height, blend_mode);
  1920. else
  1921. canvas.image(foreground, 0, 0, canvas.width, canvas.height);
  1922. canvas.endDraw();
  1923. }
  1924. boolean thresh(color c) {
  1925. switch(chan) {
  1926. case(0):
  1927. if (red(c) > val - bandwidth && red(c) < val + bandwidth)
  1928. return(true);
  1929. else
  1930. return(false);
  1931. case(1):
  1932. if (green(c) > val - bandwidth && green(c) < val + bandwidth)
  1933. return(true);
  1934. else
  1935. return(false);
  1936. case(2):
  1937. if (blue(c) > val - bandwidth && blue(c) < val + bandwidth)
  1938. return(true);
  1939. else
  1940. return(false);
  1941. case(3):
  1942. if (hue(c) > val - bandwidth && hue(c) < val + bandwidth)
  1943. return(true);
  1944. else
  1945. return(false);
  1946. case(4):
  1947. if (saturation(c) > val - bandwidth && saturation(c) < val + bandwidth)
  1948. return(true);
  1949. else
  1950. return(false);
  1951. case(5):
  1952. if (brightness(c) > val - bandwidth && brightness(c) < val + bandwidth)
  1953. return(true);
  1954. else
  1955. return(false);
  1956. }
  1957. return(false);
  1958. }
  1959. }
  1960. class DRAWSTROKES extends Shader {
  1961. int stat_type = ABSDIST2; // type of diff calculation: fast: ABSDIST, DIST, slow: HUE, SATURATION, BRIGHTNESS
  1962. int stroke_len = 3; // length of the stroke, values: 1 and above
  1963. int angles_no = 30; // number of directions stroke can be drew, 2 and above
  1964. int segments = 500; // number of segments of single thread
  1965. float stroke_width = 1; // width of the stroke, 0.5 - 3
  1966. int stroke_alpha = 100; // alpha channel of the stroke: 30 - 200
  1967. color background_color = color(255, 255, 255); // RGB
  1968. boolean interactive = false;
  1969. int max_display_size = 800; // viewing window size (regardless image size)
  1970. int len;
  1971. // working buffer
  1972. PGraphics buffer;
  1973. int currx, curry;
  1974. int[] sintab, costab;
  1975. int sqwidth;
  1976. int iterations;
  1977. int calcDiff(PImage img1, PImage img2) {
  1978. int err = 0;
  1979. for (int i=0; i<img1.pixels.length; i++)
  1980. err += getStat(img1.pixels[i], img2.pixels[i]);
  1981. return err;
  1982. }
  1983. DRAWSTROKES() {
  1984. name = "fxDrawStrokes";
  1985. params.add(new Param ("stat type", INTVAL, 0, 5, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); // 4 und 5 sind mit abstand die schnellsten
  1986. params.add(new Param ("stroke length", INTVAL, 1, 10, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  1987. params.add(new Param ("amount of angles", INTVAL, 2, 30, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  1988. params.add(new Param ("amount of segments", INTVAL, 50, 1500, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  1989. params.add(new Param ("stroke width", FLOATVAL, 0.5, 5, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  1990. params.add(new Param ("stroke transparency", INTVAL, 30, 220, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  1991. params.add(new Param ("iterations", INTVAL, 1, 500, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  1992. len = (renderer.width<renderer.height?renderer.width:renderer.height)/3;
  1993. buffer = createGraphics(renderer.width, renderer.height);
  1994. buffer.smooth(2);
  1995. buffer.beginDraw();
  1996. buffer.strokeWeight(stroke_width);
  1997. buffer.noFill();
  1998. buffer.endDraw();
  1999. rw = renderer.width;
  2000. rh = renderer.height;
  2001. }
  2002. int rw, rh;
  2003. void apply() {
  2004. stat_type = (int)params.get(0).getValue();
  2005. stroke_len = (int)params.get(1).getValue();
  2006. angles_no = (int)params.get(2).getValue();
  2007. segments = (int)params.get(3).getValue();
  2008. stroke_width = params.get(4).getValue();
  2009. stroke_alpha = (int)params.get(5).getValue();
  2010. iterations = (int)params.get(6).getValue();
  2011. if (rw != canvas.width || rh != canvas.height) { //doesnt account image swap
  2012. len = (canvas.width<canvas.height?canvas.width:canvas.height)/3;
  2013. rw = canvas.width;
  2014. rh = canvas.height;
  2015. PGraphics save = createGraphics(canvas.width, canvas.height);
  2016. save.beginDraw();
  2017. save.image(buffer, 0, 0, save.width, save.height);
  2018. save.endDraw();
  2019. buffer.setSize(canvas.width, canvas.height);
  2020. buffer.beginDraw();
  2021. buffer.image(save, 0, 0, buffer.width, buffer.height); // ????
  2022. buffer.endDraw();
  2023. }
  2024. for (int j = 0; j < iterations; j++) {
  2025. currx = (int)random(canvas.width);
  2026. curry = (int)random(canvas.height);
  2027. sintab = new int[angles_no];
  2028. costab = new int[angles_no];
  2029. for (int i=0; i<angles_no; i++) {
  2030. sintab[i] = (int)(stroke_len * sin(TWO_PI*i/(float)angles_no));
  2031. costab[i] = (int)(stroke_len * cos(TWO_PI*i/(float)angles_no));
  2032. }
  2033. sqwidth = stroke_len * 2 + 4;
  2034. buffer.beginDraw();
  2035. buffer.strokeWeight(stroke_width);
  2036. //draw whole segment using current color
  2037. buffer.stroke(canvas.get(currx, curry), stroke_alpha);
  2038. for (int iter=0; iter<segments; iter++) {
  2039. // corners of square containing new strokes
  2040. int corx = currx-stroke_len-2;
  2041. int cory = curry-stroke_len-2;
  2042. // take square from image and current screen
  2043. PImage imgpart = canvas.get(corx, cory, sqwidth, sqwidth);
  2044. PImage mypart = buffer.get(corx, cory, sqwidth, sqwidth);
  2045. imgpart.loadPixels();
  2046. mypart.loadPixels();
  2047. // calc current diff
  2048. float localerr = calcDiff(imgpart, mypart);
  2049. // chosen stroke will be here
  2050. PImage destpart = null;
  2051. int _nx=currx, _ny=curry;
  2052. // start with random angle
  2053. int i = (int)random(angles_no);
  2054. int iterangles = angles_no;
  2055. while (iterangles-- > 0) {
  2056. // take end points
  2057. int nx = currx + costab[i];
  2058. int ny = curry + sintab[i];
  2059. // if not out of the screen
  2060. if (nx>=0 && nx<canvas.width-1 && ny>=0 && ny<canvas.height-1) {
  2061. // clean region and draw line
  2062. buffer.image(mypart, corx, cory);
  2063. buffer.line(currx, curry, nx, ny);
  2064. // take region with line and calc diff
  2065. PImage curr = buffer.get(corx, cory, sqwidth, sqwidth);
  2066. curr.loadPixels();
  2067. int currerr = calcDiff(imgpart, curr);
  2068. // if better, remember this region and line endpoint
  2069. if (currerr < localerr) {
  2070. destpart = curr;
  2071. _nx = nx;
  2072. _ny = ny;
  2073. localerr = currerr;
  2074. }
  2075. }
  2076. // next angle
  2077. i = (i+1)%angles_no;
  2078. }
  2079. // if we have new stroke, draw it
  2080. if (destpart != null) {
  2081. buffer.image(destpart, corx, cory);
  2082. currx = _nx;
  2083. curry = _ny;
  2084. } else {
  2085. break; // skip
  2086. }
  2087. }
  2088. buffer.endDraw();
  2089. }
  2090. canvas.beginDraw();
  2091. canvas.image(buffer, canvas.width/2, canvas.height/2);
  2092. canvas.endDraw();
  2093. }
  2094. final static int DIST = 0;
  2095. final static int HUE = 1;
  2096. final static int BRIGHTNESS = 2;
  2097. final static int SATURATION = 3;
  2098. final static int ABSDIST = 4;
  2099. final static int ABSDIST2 = 5;
  2100. final float getStat(color c1, color c2) {
  2101. switch(stat_type) {
  2102. case HUE:
  2103. abs(hue(c1)-hue(c2));
  2104. case BRIGHTNESS:
  2105. abs(brightness(c1)-brightness(c2));
  2106. case SATURATION:
  2107. abs(saturation(c1)-saturation(c2));
  2108. case ABSDIST:
  2109. return abs(red(c1)-red(c2))+abs(green(c1)-green(c2))+abs(blue(c1)-blue(c2));
  2110. case ABSDIST2:
  2111. return abs( (red(c1)+blue(c1)+green(c1)) - (red(c2)+blue(c2)+green(c2)) );
  2112. default:
  2113. return sq(red(c1)-red(c2)) + sq(green(c1)-green(c2)) + sq(blue(c1)-blue(c2));
  2114. }
  2115. }
  2116. }
  2117. /*
  2118. DRAWGENERATIVE
  2119. */
  2120. class DRAWGENERATIVE extends Shader {
  2121. // choose channel
  2122. int channel = HUE;
  2123. // run, after 30 iterations result will be saved automatically
  2124. // or press SPACE
  2125. // channels to work with
  2126. final static int RED = 0;
  2127. final static int GREEN = 1;
  2128. final static int BLUE = 2;
  2129. final static int HUE = 3;
  2130. final static int SATURATION = 4;
  2131. final static int BRIGHTNESS = 5;
  2132. final static int NRED = 6;
  2133. final static int NGREEN = 7;
  2134. final static int NBLUE = 8;
  2135. final static int NHUE = 9;
  2136. final static int NSATURATION = 10;
  2137. final static int NBRIGHTNESS = 11;
  2138. int n=2000;
  2139. float [] cx=new float[n];
  2140. float [] cy=new float[n];
  2141. int len;
  2142. // working buffer
  2143. PGraphics buffer;
  2144. int tick = 0;
  2145. DRAWGENERATIVE() {
  2146. name = "fxDrawGenerative";
  2147. params.add(new Param ("stroke width", FLOATVAL, 0.3, 5, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE})); // 4 und 5 sind mit abstand die schnellsten
  2148. buffer = createGraphics(renderer.width, renderer.height);
  2149. buffer.noFill();
  2150. buffer.beginDraw();
  2151. //buffer.background(0); //ENABLE THIS TO DRAW FROM BLANK
  2152. buffer.endDraw();
  2153. rw = canvas.width;
  2154. rh = canvas.height;
  2155. len = (canvas.width<canvas.height?canvas.width:canvas.height)/6;
  2156. for (int i=0; i<n; i++) {
  2157. cx[i]=random(canvas.width);
  2158. cy[i]=random(canvas.height);
  2159. }
  2160. }
  2161. int rw, rh;
  2162. void apply() {
  2163. if (rw != canvas.width || rh != canvas.height) {
  2164. rw = canvas.width;
  2165. rh = canvas.height;
  2166. PGraphics save = createGraphics(canvas.width, canvas.height);
  2167. save.beginDraw();
  2168. save.image(buffer, 0, 0, save.width, save.height);
  2169. save.endDraw();
  2170. buffer.setSize(canvas.width, canvas.height);
  2171. buffer.beginDraw();
  2172. buffer.image(save, 0, 0, buffer.width, buffer.height);
  2173. buffer.endDraw();
  2174. }
  2175. buffer.beginDraw();
  2176. buffer.strokeWeight(params.get(0).getValue());
  2177. for (int i=1; i<n; i++) {
  2178. color c = canvas.get((int)cx[i], (int)cy[i]);
  2179. buffer.stroke(c);
  2180. buffer.point(cx[i], cy[i]);
  2181. // you can choose channels: red(c), blue(c), green(c), hue(c), saturation(c) or brightness(c)
  2182. cy[i]+=sin(map(getChannel(c), 0, 255, 0, TWO_PI));
  2183. cx[i]+=cos(map(getChannel(c), 0, 255, 0, TWO_PI));
  2184. }
  2185. if (frameCount>len) {
  2186. frameCount=0;
  2187. //println("iteration: " + tick++);
  2188. for (int i=0; i<n; i++) {
  2189. cx[i]=random(canvas.width); //same problem as in slitscan here
  2190. cy[i]=random(canvas.height);
  2191. }
  2192. }
  2193. buffer.endDraw();
  2194. canvas.beginDraw();
  2195. canvas.image(buffer, canvas.width/2, canvas.height/2);
  2196. canvas.endDraw();
  2197. }
  2198. float getChannel(color c) {
  2199. int ch = channel>5?channel-6:channel;
  2200. float cc;
  2201. switch(ch) {
  2202. case RED:
  2203. cc = red(c);
  2204. break;
  2205. case GREEN:
  2206. cc = green(c);
  2207. break;
  2208. case BLUE:
  2209. cc = blue(c);
  2210. break;
  2211. case HUE:
  2212. cc = hue(c);
  2213. break;
  2214. case SATURATION:
  2215. cc = saturation(c);
  2216. break;
  2217. default:
  2218. cc= brightness(c);
  2219. break;
  2220. }
  2221. return channel>5?255-cc:cc;
  2222. }
  2223. }
  2224. /*
  2225. PIXELDRIFTER
  2226. */
  2227. class PIXELDRIFTER extends Shader {
  2228. int channel = HUE; // channel data used for shift
  2229. float channel_off = 60; // channel value offset
  2230. int iteration_no = 50; // number of iterations 1-100
  2231. int max_iter = iteration_no;
  2232. int direction = UP; // UP, DOWN, LEFT, RIGHT
  2233. boolean automate_channel_offset = false; // if true, change channel_offset every iteration
  2234. float scale = 0.03; // 0.01 - 0.1, step size (0.01: 2px, 0.1:25px)
  2235. float feedback = 0.9; // 0.9 - 0.999 ; blend ratio with original image
  2236. boolean do_blend = false; // blend image after process
  2237. int blend_mode = OVERLAY; // blend type
  2238. // working buffer
  2239. PGraphics buffer;
  2240. // image
  2241. PImage imgb;
  2242. PImage img;
  2243. String sessionid;
  2244. float acho_step;
  2245. int rw, rh;
  2246. PIXELDRIFTER() {
  2247. name = "fxPixelDrifter";
  2248. params.add(new Param ("channel offset", FLOATVAL, 0, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2249. params.add(new Param ("iterations", INTVAL, 1, 100, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2250. params.add(new Param ("step size", FLOATVAL, 0.01, 0.1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2251. params.add(new Param ("feedback", FLOATVAL, 0.1, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2252. params.add(new Param ("direction", INTVAL, 37, 40, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2253. params.add(new Param ("do blend", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
  2254. params.add(new Param ("blend mode", INTVAL, 0, blends.length-1, new int[]{RANDOM}));
  2255. params.add(new Param ("channel", INTVAL, 0, 1, new int[]{SQUAR, RANDOM}));
  2256. params.add(new Param ("automate channel offset", INTVAL, 0, 1, new int[]{SQUAR, RANDOM}));
  2257. rw = canvas.width;
  2258. rh = canvas.height;
  2259. img = createImage(rw, rh, ARGB);
  2260. buffer = createGraphics(rw, rh);
  2261. buffer.beginDraw();
  2262. buffer.noStroke();
  2263. buffer.smooth(8);
  2264. buffer.background(0);
  2265. buffer.image(img, 0, 0);
  2266. buffer.endDraw();
  2267. scale = abs(scale);
  2268. }
  2269. void apply() {
  2270. if (rw != canvas.width || rh != canvas.height) {
  2271. rw = canvas.width;
  2272. rh = canvas.height;
  2273. img.resize(rw, rh);
  2274. buffer = createGraphics(rw, rh);
  2275. }
  2276. channel_off = map(params.get(0).getValue(), 0, 1, 10, max(rw, rh));
  2277. iteration_no = (int)params.get(1).getValue();
  2278. scale = params.get(2).getValue();
  2279. feedback = params.get(3).getValue();
  2280. direction = (int)params.get(4).getValue();
  2281. do_blend = boolean((int)params.get(5).getValue());
  2282. blend_mode = blends[(int)params.get(6).getValue()];
  2283. channel = (int)params.get(7).getValue() == 1 ? HUE : RGB;
  2284. automate_channel_offset = boolean((int)params.get(8).getValue());
  2285. acho_step = 256.0 / iteration_no;
  2286. img = canvas.get();
  2287. // if (iteration_no>0) {
  2288. for (int i = 0; i < iteration_no; i++) {
  2289. processImage();
  2290. }
  2291. //iteration_no--;
  2292. //iteration_no=(iteration_no==0)?max_iter:iteration_no;
  2293. // if (iteration_no == 0)
  2294. // iteration_no = 50;
  2295. // }
  2296. // } else {
  2297. canvas.beginDraw();
  2298. if (do_blend) {
  2299. canvas.blend(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height, blend_mode);
  2300. } else {
  2301. canvas.image(buffer, canvas.width/2, canvas.height/2, canvas.width, canvas.height);
  2302. }
  2303. canvas.endDraw();
  2304. // canvas.image(img, 0, 0, renderer.width, renderer.height);
  2305. // noLoop();
  2306. // }
  2307. }
  2308. void processImage() {
  2309. buffer.beginDraw();
  2310. for (int x=0; x<img.width; x++) {
  2311. for (int y=0; y<img.height; y++) {
  2312. color c = img.get(x, y);
  2313. color c2;
  2314. if (direction == UP || direction == DOWN) {
  2315. c2 = img.get(x, ((int)(y+img.height+( (channel_off+getChannel(c, channel))%255 )*(direction==DOWN?-1.0:1.0)*scale))%img.height);
  2316. } else {
  2317. c2 = img.get(((int)(x+img.width+( (channel_off+getChannel(c, channel))%255)*(direction==RIGHT?-1.0:1.0)*scale))%img.width, y);
  2318. }
  2319. buffer.set(x, y, lerpColor(c, c2, feedback) );
  2320. }
  2321. }
  2322. buffer.endDraw();
  2323. //canvas.image(buffer, 0, 0, width, height);
  2324. img = buffer.get();
  2325. if (automate_channel_offset) channel_off += acho_step;
  2326. }
  2327. // ALL Channels, Nxxx stand for negative (255-value)
  2328. // channels to work with
  2329. final static int RED = 0;
  2330. final static int GREEN = 1;
  2331. final static int BLUE = 2;
  2332. final static int HUE = 3;
  2333. final static int SATURATION = 4;
  2334. final static int BRIGHTNESS = 5;
  2335. final static int NRED = 6;
  2336. final static int NGREEN = 7;
  2337. final static int NBLUE = 8;
  2338. final static int NHUE = 9;
  2339. final static int NSATURATION = 10;
  2340. final static int NBRIGHTNESS = 11;
  2341. float getChannel(color c, int channel) {
  2342. int ch = channel>5?channel-6:channel;
  2343. float cc;
  2344. switch(ch) {
  2345. case RED:
  2346. cc = red(c);
  2347. break;
  2348. case GREEN:
  2349. cc = green(c);
  2350. break;
  2351. case BLUE:
  2352. cc = blue(c);
  2353. break;
  2354. case HUE:
  2355. cc = hue(c);
  2356. break;
  2357. case SATURATION:
  2358. cc = saturation(c);
  2359. break;
  2360. default:
  2361. cc= brightness(c);
  2362. break;
  2363. }
  2364. return channel>5?255-cc:cc;
  2365. }
  2366. }
  2367. /*
  2368. DRIPDRIP
  2369. */
  2370. class DRIPDRIP extends Shader {
  2371. int maxsteps = 50; //maximum fade length in px
  2372. int minsteps = 2; //minimum fade length in px
  2373. Boolean brightmode = false; //if enabled will fade light over dark
  2374. Boolean autotoggle = true; //switch brightmode at pivot point
  2375. float autoPivot = 0.58; //where on the y axis (0-1) to switch
  2376. int steps[];
  2377. int rw, rh;
  2378. DRIPDRIP() {
  2379. name = "fxDripDrip";
  2380. params.add(new Param ("max steps", FLOATVAL, 0, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2381. params.add(new Param ("min steps", FLOATVAL, 0, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2382. params.add(new Param ("bright breakpoint", FLOATVAL, 0, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2383. //params.add(new Param ("auto toggle", INTVAL, 0, 1, new int[]{SQUAR, RANDOM}));
  2384. params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM}));
  2385. directionParamIndex = 3;
  2386. rw = canvas.width;
  2387. rh = canvas.height;
  2388. steps = new int[canvas.width*canvas.height];
  2389. for (int i = 0; i < canvas.width*canvas.height; i++) {
  2390. steps[i] = (int)map(random(1), 0, 1, minsteps, maxsteps);
  2391. }
  2392. }
  2393. void apply() {
  2394. minsteps = (int)map(params.get(1).getValue(), 0, 1, 1, max(canvas.width, canvas.height)/10);
  2395. maxsteps = (int)map(params.get(0).getValue(), 0, 1, minsteps, max(canvas.width, canvas.height)/10);
  2396. autoPivot = params.get(2).getValue();
  2397. //brightmode = boolean((int)params.get(3).getValue());
  2398. //autotoggle = boolean((int)params.get(4).getValue());
  2399. if (rw != canvas.width || rh != canvas.height) {
  2400. rw = canvas.width;
  2401. rh = canvas.height;
  2402. steps = new int[canvas.width*canvas.height];
  2403. }
  2404. for (int i = 0; i < steps.length; i++) {
  2405. steps[i] = (int)map(random(1), 0, 1, minsteps, maxsteps);
  2406. }
  2407. canvas.beginDraw();
  2408. canvas.loadPixels();
  2409. for ( int x = 0, w = canvas.width; x<w; x++) {
  2410. for ( int h = canvas.height, y = h-1; y>-1; y--) {
  2411. /*
  2412. if ( alternatetoggle ) {
  2413. brightmode = !brightmode;
  2414. } else {
  2415. if ( autotoggle ) {
  2416. brightmode = y > (h*autoPivot);
  2417. }
  2418. }
  2419. */
  2420. //if (autotoggle) {
  2421. brightmode = y > (h*autoPivot);
  2422. //}
  2423. float rat = 1.0;
  2424. int pos = x + y * w;
  2425. color c = canvas.pixels[pos];
  2426. int ty = y;
  2427. while ( rat > 1.0/steps[x*y]*2 ) {
  2428. ty++;
  2429. if ( ty >= h ) break;
  2430. int tpos = x + ty * w;
  2431. color tc = canvas.pixels[tpos];
  2432. if (
  2433. ( !brightmode && brightness(tc) < brightness(c) )
  2434. || ( brightmode && brightness(tc) > brightness(c) )
  2435. ) break;
  2436. canvas.pixels[tpos] = blendC(tc, c, rat);
  2437. rat-= rat/steps[x*y];
  2438. }
  2439. }
  2440. }
  2441. canvas.updatePixels();
  2442. canvas.endDraw();
  2443. }
  2444. color blendC(color tc, color sc, float rat) {
  2445. return color(
  2446. (red(tc)*(1.0-rat))+(red(sc)*rat),
  2447. (green(tc)*(1.0-rat))+(green(sc)*rat),
  2448. (blue(tc)*(1.0-rat))+(blue(sc)*rat)
  2449. );
  2450. }
  2451. }
  2452. /*
  2453. WRONGQSORT
  2454. */
  2455. class WRONGQSORT extends Shader {
  2456. boolean mode = L; // L or R, which sort part is broken
  2457. boolean do_blend = false; // blend image after process
  2458. int blend_mode = OVERLAY; // blend type
  2459. static final boolean L = true;
  2460. static final boolean R = false;
  2461. // working buffer
  2462. PGraphics buffer;
  2463. // image
  2464. PImage img;
  2465. float random_point = 0.5;
  2466. int len;
  2467. int rw, rh;
  2468. WRONGQSORT() {
  2469. name = "fxWrongQSort";
  2470. params.add(new Param ("v", FLOATVAL, 0.1, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2471. params.add(new Param ("randomize", FLOATVAL, 0.1, 0.9, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2472. params.add(new Param ("mode", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
  2473. params.add(new Param ("do blend", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
  2474. params.add(new Param ("blend mode", INTVAL, 0, blends.length-1, new int[]{RANDOM}));
  2475. params.add(new Param ("direction", INTVAL, 0, 3, new int[]{RANDOM}));
  2476. directionParamIndex = 5;
  2477. img = createImage(canvas.width, canvas.height, ARGB);
  2478. img = canvas.get();
  2479. buffer = createGraphics(canvas.width, canvas.height);
  2480. buffer.beginDraw();
  2481. buffer.noStroke();
  2482. buffer.smooth(8);
  2483. buffer.background(0);
  2484. buffer.image(img, 0, 0);
  2485. buffer.endDraw();
  2486. }
  2487. void apply() {
  2488. random_point = params.get(1).getValue();
  2489. mode = boolean((int)params.get(2).getValue());
  2490. do_blend = boolean((int)params.get(3).getValue());
  2491. blend_mode = blends[(int)params.get(4).getValue()];
  2492. if (rw != canvas.width || rh != canvas.height) {
  2493. rw = canvas.width;
  2494. rh = canvas.height;
  2495. img.resize(rw, rh);
  2496. buffer = createGraphics(rw, rh);
  2497. }
  2498. img = canvas.get();
  2499. len = rw * rh;
  2500. int v = (int)map(params.get(0).getValue(), 0, 1, 1, len-1);
  2501. buffer.beginDraw();
  2502. buffer.image(img, 0, 0);
  2503. buffer.endDraw();
  2504. buffer.loadPixels();
  2505. int x = 0;
  2506. while (x<len) {
  2507. if (x+v<len) quicksort(buffer.pixels, x, x+v);
  2508. else quicksort(buffer.pixels, x, len-1);
  2509. x+=v;
  2510. }
  2511. buffer.updatePixels();
  2512. buffer.beginDraw();
  2513. if (do_blend) {
  2514. buffer.blend(img, 0, 0, img.width, img.height, 0, 0, buffer.width, buffer.height, blend_mode);
  2515. }
  2516. buffer.endDraw();
  2517. canvas.beginDraw();
  2518. canvas.image(buffer, canvas.width/2, canvas.height/2);
  2519. canvas.endDraw();
  2520. }
  2521. int partition(int x[], int left, int right) {
  2522. int i = left;
  2523. int j = right;
  2524. int temp;
  2525. int pivot = x [(int)map(random_point, 0, 1, left, right)];
  2526. while (i<= j) {
  2527. while (x[i] < pivot) {
  2528. i++;
  2529. }
  2530. while (x[j] > pivot) {
  2531. j--;
  2532. }
  2533. if (i <= j) {
  2534. temp = x[i];
  2535. x[i] = x [j];
  2536. x[j] = temp;
  2537. i++;
  2538. j--;
  2539. }
  2540. }
  2541. return i;
  2542. }
  2543. void quicksort(int x[], int left, int right) {
  2544. if (left<right) {
  2545. int index = partition(x, left, right);
  2546. if (mode) {
  2547. if (left < index-1) quicksort(x, left, index-1);
  2548. if (right < index) quicksort(x, index, right);
  2549. } else {
  2550. if (left > index-1) quicksort(x, left, index-1);
  2551. if (right > index) quicksort(x, index, right);
  2552. }
  2553. }
  2554. }
  2555. }
  2556. /*
  2557. VHS
  2558. */
  2559. class VHS extends Shader {
  2560. PImage timg;
  2561. int bass, treble, sxl, syl;
  2562. VHS () {
  2563. name = "fxVHS";
  2564. params.add(new Param ("sine x length", INTVAL, 1, 100, new int[]{TRIANG, SINE}));
  2565. params.add(new Param ("sine y length", INTVAL, 1, 100, new int[]{TRIANG, SINE}));
  2566. params.add(new Param ("bass", INTVAL, -15, 15, new int[]{TRIANG, SINE}));
  2567. params.add(new Param ("treble", INTVAL, -15, 15, new int[]{TRIANG, SINE}));
  2568. params.add(new Param ("direction", INTVAL, 0, 3, new int[]{RANDOM}));
  2569. directionParamIndex = 4;
  2570. }
  2571. void apply() {
  2572. sxl = (int)params.get(0).getValue();
  2573. syl = (int)params.get(1).getValue();
  2574. bass = (int)params.get(2).getValue();
  2575. treble = (int)params.get(3).getValue();
  2576. int virtw = canvas.width;
  2577. int virth = canvas.height;
  2578. PImage timg = createImage(canvas.width, canvas.height, RGB);
  2579. timg = canvas.get();
  2580. PImage hay = sinwav(timg, sxl, syl);
  2581. PImage result = createImage(timg.width, timg.height, RGB);
  2582. result.copy(hay, 0, 0, virtw, virth, 0, 0, result.width, result.height);
  2583. canvas.beginDraw();
  2584. canvas.image(basstreble(result, bass, treble), canvas.width/2, canvas.height/2, canvas.width, canvas.height); //0 to 100
  2585. canvas.endDraw();
  2586. }
  2587. PImage sinwav(PImage img, int xp, int yp) {
  2588. int ctr = 0;
  2589. img.loadPixels();
  2590. float ylength = xp;
  2591. float xlength = yp; // was map (yp, 0,100, 1, 100);
  2592. PImage result = createImage(img.width, img.height, RGB);
  2593. for ( int y =0, h = img.height; y<h; y++) {
  2594. for ( int x = 0, w = img.width; x<w; x++, ctr++) {
  2595. int pos = x + y * w;
  2596. color c = img.pixels[pos];
  2597. int epos = (int)(( x + sin(y/ylength)*xlength)+ y * w);
  2598. if ( epos < result.pixels.length )
  2599. result.pixels[epos] = c;
  2600. else
  2601. result.pixels[pos] = c;
  2602. }
  2603. }
  2604. result.updatePixels();
  2605. return result;
  2606. }
  2607. PImage basstreble(PImage img, int xp, int yp) {
  2608. float dB_bass = xp;
  2609. float dB_treble = yp;
  2610. PImage result = createImage(img.width, img.height, RGB);
  2611. float slope = 0.4;
  2612. double hzBass = 250.0;
  2613. double hzTreble = 4000.0;
  2614. float b0, b1, b2, a0, a1, a2, xn2Bass, xn1Bass, yn2Bass, yn1Bass, b0Bass, b1Bass, b2Bass, xn1Treble, xn2Treble, yn1Treble, yn2Treble, a0Bass, a1Bass, a2Bass, a0Treble, a1Treble, a2Treble, b0Treble, b1Treble, b2Treble;
  2615. double mMax = 0.0;
  2616. double mSampleRate = 44000;
  2617. xn1Bass = xn2Bass = yn1Bass = yn2Bass = 0.0;
  2618. xn1Treble = xn2Treble = yn1Treble = yn2Treble = 0.0;
  2619. float w = (float)(2 * PI * hzBass / mSampleRate);
  2620. float a = exp((float)(log(10.0) * dB_bass / 40));
  2621. float b = sqrt((float)((a * a + 1) / slope - (pow((float)(a - 1), 2))));
  2622. b0Bass = a * ((a + 1) - (a - 1) * cos(w) + b * sin(w));
  2623. b1Bass = 2 * a * ((a - 1) - (a + 1) * cos(w));
  2624. b2Bass = a * ((a + 1) - (a - 1) * cos(w) - b * sin(w));
  2625. a0Bass = ((a + 1) + (a - 1) * cos(w) + b * sin(w));
  2626. a1Bass = -2 * ((a - 1) + (a + 1) * cos(w));
  2627. a2Bass = (a + 1) + (a - 1) * cos(w) - b * sin(w);
  2628. w = (float)(2 * PI * hzTreble / mSampleRate);
  2629. a = exp((float)(log(10.0) * dB_treble / 40));
  2630. b = sqrt((float)((a * a + 1) / slope - (pow((float)(a - 1), 2))));
  2631. b0Treble = a * ((a + 1) + (a - 1) * cos(w) + b * sin(w));
  2632. b1Treble = -2 * a * ((a - 1) + (a + 1) * cos(w));
  2633. b2Treble = a * ((a + 1) + (a - 1) * cos(w) - b * sin(w));
  2634. a0Treble = ((a + 1) - (a - 1) * cos(w) + b * sin(w));
  2635. a1Treble = 2 * ((a - 1) - (a + 1) * cos(w));
  2636. a2Treble = (a + 1) - (a - 1) * cos(w) - b * sin(w);
  2637. img.loadPixels();
  2638. result.loadPixels();
  2639. for ( int i = 0, l = img.pixels.length; i<l; i++) {
  2640. int[] rgb = new int[3];
  2641. rgb[0] = (int)red(img.pixels[i]);
  2642. rgb[1] = (int)green(img.pixels[i]);
  2643. rgb[2] = (int)blue(img.pixels[i]);
  2644. for ( int ri = 0; ri<3; ri++ ) {
  2645. float in = map(rgb[ri], 0, 255, 0, 1);
  2646. float out = (b0Bass * in + b1Bass * xn1Bass + b2Bass * xn2Bass - a1Bass * yn1Bass - a2Bass * yn2Bass ) / a0Bass;
  2647. //println(a0Bass);
  2648. xn2Bass = xn1Bass;
  2649. xn1Bass = in;
  2650. yn2Bass = yn1Bass;
  2651. yn1Bass = out;
  2652. //treble filter
  2653. in = out;
  2654. out = (b0Treble * in + b1Treble * xn1Treble + b2Treble * xn2Treble - a1Treble * yn1Treble - a2Treble * yn2Treble) / a0Treble;
  2655. xn2Treble = xn1Treble;
  2656. xn1Treble = in;
  2657. yn2Treble = yn1Treble;
  2658. yn1Treble = out;
  2659. //retain max value for use in normalization
  2660. if ( mMax < abs(out))
  2661. mMax = abs(out);
  2662. rgb[ri] = (int)map(out, 0, 1, 0, 255);
  2663. }
  2664. result.pixels[i] = color(rgb[0], rgb[1], rgb[2]);
  2665. }
  2666. result.updatePixels();
  2667. return result;
  2668. }
  2669. }
  2670. /*
  2671. LZ7
  2672. */
  2673. class LZ7 extends Shader {
  2674. // choose colorspace
  2675. int colorspace = HSB; // HSB or RGB
  2676. // set compressor attributes for each channel in chosen colorspace
  2677. // first number is length of dictionary in LZ77 - values 100 - 4000
  2678. // second number is length of word (ahead buffer) in LZ77 - about 5% - 50% of dictionary size
  2679. int[][] compressor_attributes = { {2000, 250}, // channel 1 (H or R)
  2680. {50, 10}, // channel 2 (S or G)
  2681. {100, 100} }; // channel 3 (B or B)
  2682. // set number of glitches made for each channel
  2683. // first number is actual number of random change in compressed channel
  2684. // second number is amount of change (values from 0.01 to 4)
  2685. float[][] number_of_glitches = { {5000, 2}, // channel 1
  2686. {500, 1}, // channel 2
  2687. {50, 0.1} }; // channel 3
  2688. // working buffer
  2689. PGraphics buffer;
  2690. // image
  2691. PImage img;
  2692. boolean do_blend = false; // blend image after process
  2693. int blend_mode = OVERLAY; // blend type
  2694. LZ77 comp1, comp2, comp3;
  2695. byte[] cr, cb, cg;
  2696. //red channel dictionary size
  2697. //red channel word size
  2698. //red channel randomness
  2699. //red channel amount of change
  2700. LZ7() {
  2701. name = "fxLZ77";
  2702. params.add(new Param("dictionary size (red/hue)", INTVAL, 100, 3000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2703. params.add(new Param("word length (red/hue)", FLOATVAL, 0.05, 0.5, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2704. params.add(new Param("randomness (red/hue)", INTVAL, 20, 5000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2705. params.add(new Param("amount of change (red/hue)", FLOATVAL, 0.01, 4, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2706. params.add(new Param("dictionary size (green/saturation)", INTVAL, 100, 3000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2707. params.add(new Param("word length (green/saturation)", FLOATVAL, 0.05, 0.5, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2708. params.add(new Param("randomness (green/saturation)", INTVAL, 20, 5000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2709. params.add(new Param("amount of change (green/saturation)", FLOATVAL, 0.01, 4, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2710. params.add(new Param("dictionary size (blue/brightness)", INTVAL, 100, 3000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2711. params.add(new Param("word length (blue/brightness)", FLOATVAL, 0.05, 0.5, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2712. params.add(new Param("randomness (blue/brightness)", INTVAL, 20, 5000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2713. params.add(new Param("amount of change (blue/brightness)", FLOATVAL, 0.01, 4, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2714. params.add(new Param("colorspace (rgb / hsb)", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
  2715. params.add(new Param("do blend", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
  2716. params.add(new Param("blend mode", INTVAL, 0, blends.length-1, new int[]{RANDOM}));
  2717. params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM}));
  2718. directionParamIndex = 15;
  2719. rw = canvas.width;
  2720. rh = canvas.height;
  2721. buffer = createGraphics(rw, rh);
  2722. buffer.beginDraw();
  2723. buffer.noStroke();
  2724. //buffer.smooth(8);
  2725. buffer.background(0);
  2726. buffer.endDraw();
  2727. img = createImage(canvas.width, canvas.height, RGB);
  2728. cr = new byte[rw*rh];
  2729. cb = new byte[rw*rh];
  2730. cg = new byte[rw*rh];
  2731. }
  2732. int rw, rh;
  2733. void apply() {
  2734. if (rw != canvas.width || rh != canvas.height) {
  2735. rw = canvas.width;
  2736. rh = canvas.height;
  2737. cr = new byte[rw*rh];
  2738. cb = new byte[rw*rh];
  2739. cg = new byte[rw*rh];
  2740. buffer = createGraphics(rw, rh);
  2741. img.resize(rw, rh);
  2742. }
  2743. img = canvas.get();
  2744. colorspace = (int)params.get(12).getValue() == 0 ?RGB:HSB;
  2745. do_blend = boolean((int)params.get(13).getValue());
  2746. blend_mode = blends[(int)params.get(14).getValue()];
  2747. //red
  2748. compressor_attributes[0][0] = (int)params.get(0).getValue();
  2749. compressor_attributes[0][1] = (int)(params.get(1).getValue()*compressor_attributes[0][0]);
  2750. number_of_glitches[0][0] = (int)params.get(2).getValue();
  2751. number_of_glitches[0][1] = params.get(3).getValue();
  2752. //green
  2753. compressor_attributes[1][0] = (int)params.get(4).getValue();
  2754. compressor_attributes[1][1] = (int)(params.get(5).getValue()*compressor_attributes[1][0]);
  2755. number_of_glitches[1][0] = (int)params.get(6).getValue();
  2756. number_of_glitches[1][1] = params.get(7).getValue();
  2757. //blue
  2758. compressor_attributes[2][0] = (int)params.get(8).getValue();
  2759. compressor_attributes[2][1] = (int)(params.get(9).getValue()*compressor_attributes[2][0]);
  2760. number_of_glitches[2][0] = (int)params.get(10).getValue();
  2761. number_of_glitches[2][1] = params.get(11).getValue();
  2762. comp1 = new LZ77( compressor_attributes[0][0], compressor_attributes[0][1] );
  2763. comp2 = new LZ77( compressor_attributes[1][0], compressor_attributes[1][1] );
  2764. comp3 = new LZ77( compressor_attributes[2][0], compressor_attributes[2][1] );
  2765. buffer.beginDraw();
  2766. //print("Preparing... ");
  2767. img.loadPixels();
  2768. int iter=0;
  2769. for (int i=0; i<img.pixels.length; i++) {
  2770. color c = img.pixels[i];
  2771. if (colorspace == HSB) {
  2772. cr[iter]= (byte)hue(c);
  2773. cg[iter]= (byte)saturation(c);
  2774. cb[iter]= (byte)brightness(c);
  2775. } else {
  2776. cr[iter]= (byte)red(c);
  2777. cg[iter]= (byte)green(c);
  2778. cb[iter]= (byte)blue(c);
  2779. }
  2780. iter++;
  2781. }
  2782. //println("done");
  2783. //print("Glitching channel 1... ");
  2784. comp1.doCompress(cr);
  2785. comp1.glitch( (int)number_of_glitches[0][0], number_of_glitches[0][1] );
  2786. comp1.doDecompress(cr);
  2787. //println("done");
  2788. //print("Glitching channel 2... ");
  2789. comp2.doCompress(cg);
  2790. comp2.glitch( (int)number_of_glitches[1][0], number_of_glitches[1][1] );
  2791. comp2.doDecompress(cg);
  2792. //println("done");
  2793. //print("Glitching channel 3... ");
  2794. comp3.doCompress(cb);
  2795. comp3.glitch( (int)number_of_glitches[2][0], number_of_glitches[2][1] );
  2796. comp3.doDecompress(cb);
  2797. //println("done");
  2798. for (int i = 0; i < 3; i++) {
  2799. //println("Channel "+(i+1)+" = ("+compressor_attributes[i][0]+","+compressor_attributes[i][1]+")" + ", glitches = ("+number_of_glitches[i][0]+","+number_of_glitches[i][1]+")");
  2800. }
  2801. buffer.loadPixels();
  2802. if (colorspace == HSB) colorMode(HSB);
  2803. else colorMode(RGB);
  2804. iter=0;
  2805. for (int i=0; i<buffer.pixels.length; i++) {
  2806. float r = cr[iter];
  2807. r = r>=0?r:r+256;
  2808. float g = cg[iter];
  2809. g = g>=0?g:g+256;
  2810. float b = cb[iter];
  2811. b = b>=0?b:b+256;
  2812. buffer.pixels[i] = color(r, g, b);
  2813. iter++;
  2814. }
  2815. buffer.updatePixels();
  2816. if (do_blend)
  2817. buffer.blend(img, 0, 0, img.width, img.height, 0, 0, buffer.width, buffer.height, blend_mode);
  2818. buffer.endDraw();
  2819. canvas.beginDraw();
  2820. canvas.image(buffer, canvas.width/2, canvas.height/2);
  2821. canvas.endDraw();
  2822. }
  2823. }
  2824. class Tuple {
  2825. public int offset, len;
  2826. byte chr;
  2827. public Tuple(int o, int l, byte c) {
  2828. offset = o;
  2829. len = l;
  2830. chr = c;
  2831. }
  2832. }
  2833. class LZ77 {
  2834. int windowWidth;
  2835. int lookAheadWidht;
  2836. public LZ77(int ww, int law) {
  2837. windowWidth = ww;
  2838. lookAheadWidht = law;
  2839. }
  2840. ArrayList<Tuple> clist = new ArrayList<Tuple>();
  2841. public void glitch(int no, float fac) {
  2842. for (int i=0; i<no; i++) {
  2843. Tuple r = clist.get( (int)random(clist.size()));
  2844. int what = (int)random(3);
  2845. switch(what) {
  2846. case 0:
  2847. r.chr = (byte)random(256);
  2848. break;
  2849. case 1:
  2850. r.offset = (int)random(2*windowWidth*fac);
  2851. break;
  2852. default:
  2853. r.len = (int)random(2*lookAheadWidht*fac);
  2854. }
  2855. }
  2856. }
  2857. public void doCompress(byte[] buff) {
  2858. int currByte = 1;
  2859. // first is always byte
  2860. clist.add( new Tuple(0, 0, buff[0]) );
  2861. while (currByte < buff.length) {
  2862. int bend = constrain(currByte-windowWidth, 0, buff.length);
  2863. int boff = 0;
  2864. int blen = 0;
  2865. if (currByte<buff.length-1)
  2866. for (int i = currByte-1; i>=bend; i--) {
  2867. if (buff[currByte] == buff[i]) {
  2868. int tboff = abs(i-currByte);
  2869. int tblen = 1;
  2870. int laEnd = constrain(currByte+lookAheadWidht, 0, buff.length-1);
  2871. int mi = currByte+1;
  2872. while (mi<laEnd && (i+mi-currByte)<currByte) {
  2873. if (buff[mi] == buff[i+mi-currByte]) {
  2874. mi++;
  2875. tblen++;
  2876. } else {
  2877. break;
  2878. }
  2879. }
  2880. if (tblen>blen) {
  2881. blen = tblen;
  2882. boff = tboff;
  2883. }
  2884. }
  2885. }
  2886. currByte +=blen+1;
  2887. // println("currchar = " + (currByte-1)+",blen = " + blen);
  2888. clist.add( new Tuple(boff, blen, buff[currByte-1]) );
  2889. // println(boff + ", " + blen + ", " + buff[currByte-1]);
  2890. }
  2891. //println("clist " + clist.size()*2);
  2892. }
  2893. void doDecompress(byte[] buff) {
  2894. int i = 0;
  2895. for (Tuple t : clist) {
  2896. if (i>=buff.length) break;
  2897. if (t.offset == 0) {
  2898. buff[i++] = t.chr;
  2899. } else {
  2900. int start = i-t.offset;
  2901. int end = start + t.len;
  2902. for (int c = start; c<end; c++) {
  2903. int pos = constrain(c, 0, buff.length-1);
  2904. buff[constrain(i++, 0, buff.length-1)] = buff[pos];
  2905. if (i>=buff.length) break;
  2906. }
  2907. if (i>=buff.length) break;
  2908. buff[i++] = t.chr;
  2909. }
  2910. }
  2911. }
  2912. }
  2913. /*
  2914. LENS
  2915. */
  2916. class LENS extends Shader {
  2917. // parameters
  2918. float bendx = 0.1; // from 0 to 1
  2919. float bendy = 0.1; // from 0 to 1
  2920. float[] power_vals = { 2, 0.5 }; // two values of power from 0.1 to 10, one for x and second for y
  2921. int[] types = { LINEAR, POWER }; // always to types one for x second for y
  2922. int[] channels = { BRIGHTNESS, SATURATION }; // as above
  2923. float[] facts = new float[2];
  2924. //////////////
  2925. PImage img;
  2926. PImage limg;
  2927. int shaderListLength;
  2928. // working buffer
  2929. PGraphics buffer;
  2930. LENS() {
  2931. name = "fxLens";
  2932. shaderListLength = gui.shaderList.size();
  2933. params.add(new Param("lens image layer", INTVAL, 0, shaderListLength-1, new int[]{RANDOM}));
  2934. params.add(new Param("power x", FLOATVAL, 0.1, 10, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2935. params.add(new Param("power y", FLOATVAL, 0.1, 10, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2936. params.add(new Param("lens type x", INTVAL, 0, 3, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2937. params.add(new Param("lens type y", INTVAL, 0, 3, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2938. params.add(new Param("channel x", INTVAL, 0, 11, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2939. params.add(new Param("channel y", INTVAL, 0, 11, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2940. params.add(new Param("curvature factor x", FLOATVAL, 0.01, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2941. params.add(new Param("curvature factor y", FLOATVAL, 0.01, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  2942. params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM}));
  2943. directionParamIndex = 9;
  2944. rw = canvas.width;
  2945. rh = canvas.height;
  2946. img = createImage(rw, rh, ARGB);
  2947. limg = createImage(rw, rh, ARGB);
  2948. buffer = createGraphics(rw, rh);
  2949. buffer.beginDraw();
  2950. buffer.noStroke();
  2951. buffer.endDraw();
  2952. }
  2953. int rw, rh;
  2954. void apply() {
  2955. if (rw != canvas.width || rh != canvas.height) {
  2956. rw = canvas.width;
  2957. rh = canvas.height;
  2958. buffer = createGraphics(rw, rh);
  2959. buffer.beginDraw();
  2960. buffer.noStroke();
  2961. buffer.endDraw();
  2962. img.resize(rw, rh);
  2963. limg.resize(rw, rh);
  2964. }
  2965. if (shaderListLength != gui.shaderList.size()) {
  2966. shaderListLength = gui.shaderList.size();
  2967. changeParam(0, new Param("lens image layer", INTVAL, 0, shaderListLength-1, new int[]{RANDOM}));
  2968. }
  2969. img = canvas.get();
  2970. if ((int)params.get(0).getValue() == pos) {
  2971. limg = canvas.get();
  2972. } else {
  2973. limg = gui.shaderList.get((int)params.get(0).getValue()).result.get();
  2974. }
  2975. power_vals[0] = params.get(1).getValue();
  2976. power_vals[1] = params.get(2).getValue();
  2977. types[0] = (int)params.get(3).getValue();
  2978. types[1] = (int)params.get(4).getValue();
  2979. channels[0] = (int)params.get(5).getValue();
  2980. channels[1] = (int)params.get(6).getValue();
  2981. bendx = params.get(7).getValue();
  2982. bendy = params.get(8).getValue();
  2983. facts[0] = bendx * img.width;
  2984. facts[1] = bendy * img.height;
  2985. img.loadPixels();
  2986. limg.loadPixels();
  2987. buffer.beginDraw();
  2988. buffer.background(0);
  2989. for (int x=0; x<img.width; x++) {
  2990. int lx = (int)map(x, 0, img.width-1, 0, limg.width-1);
  2991. for (int y=0; y<img.height; y++) {
  2992. int ly = (int)map(y, 0, img.height-1, 0, limg.height-1);
  2993. color c = limg.pixels[lx+ly*limg.width];
  2994. int posx = (x+getShift(c, 0)+2*img.width)%img.width;
  2995. int posy = (y+getShift(c, 1)+2*img.height)%img.height;
  2996. color n = img.pixels[posx+posy*img.width];
  2997. buffer.fill(n);
  2998. // fill(red(c),green(c),blue(n)); // work only on blue channel
  2999. // fill(red(n), abs(green(c)-green(n)), blue(n)); // green channel is blended using difference method
  3000. buffer.rect(x, y, 1, 1);
  3001. }
  3002. }
  3003. buffer.endDraw();
  3004. img.updatePixels();
  3005. limg.updatePixels();
  3006. canvas.beginDraw();
  3007. canvas.image(buffer, canvas.width/2, canvas.height/2);
  3008. canvas.endDraw();
  3009. }
  3010. float getChannel(color c, int channel) {
  3011. int ch = channel>5?channel-6:channel;
  3012. float cc;
  3013. switch(ch) {
  3014. case RED:
  3015. cc = red(c);
  3016. break;
  3017. case GREEN:
  3018. cc = green(c);
  3019. break;
  3020. case BLUE:
  3021. cc = blue(c);
  3022. break;
  3023. case HUE:
  3024. cc = hue(c);
  3025. break;
  3026. case SATURATION:
  3027. cc = saturation(c);
  3028. break;
  3029. default:
  3030. cc= brightness(c);
  3031. break;
  3032. }
  3033. return channel>5?255-cc:cc;
  3034. }
  3035. int getShift(color c, int idx) {
  3036. float cc = getChannel(c, channels[idx]);
  3037. switch(types[idx]) {
  3038. case LINEAR:
  3039. return (int)(facts[idx] * cc/255.0);
  3040. case POWER:
  3041. return (int)(facts[idx]*map(pow(cc/255.0, power_vals[idx]), 0, 1, -1, 1));
  3042. case SINUSOIDAL:
  3043. return (int)(facts[idx]*sin(map(cc, 0, 255, -PI, PI)));
  3044. default:
  3045. { // POLAR
  3046. float c1 = idx==0?cc:getChannel(c, channels[1]);
  3047. float c2 = idx==1?cc:getChannel(c, channels[0]);
  3048. float ang = map(c1, 0, 255, 0, TWO_PI);
  3049. float r = map(c2, 0, 255, 0, facts[0]);
  3050. return (int)(idx==0?r*cos(ang):r*sin(ang));
  3051. }
  3052. }
  3053. }
  3054. }
  3055. /*
  3056. SLICER
  3057. */
  3058. class SLICER extends Shader {
  3059. ArrayList<Edge> edges = new ArrayList<Edge>();
  3060. SegmentNode[] elements;
  3061. Map<Integer, S> m = new HashMap<Integer, S>();
  3062. int max_patterns = 20; // CAN I KILL THIS?
  3063. float max_rotation = TWO_PI; // random or fixed rotation up to specified angle, 0 - TWO_PI, 0 - no rotation
  3064. boolean fixed_rotation = true; // fixed or random rotation
  3065. int thr_min = -1; // you can change color of segment for specified brightness threshold
  3066. int thr_max = -1; // set to -1 if you don't want to use it, values from 0 to 255
  3067. color[] palette = { #000000, #E7CBB3, #CEC6AF, #A0C3BC, #7C7F84, #ffffff }; // choose colors for palette you want to use with threshold, colors will be choosen randomly
  3068. // SEPARATE config
  3069. float max_shift = 2; // max expected shift, using gaussian random, so bigger number, more distortion
  3070. int type = ROTATE; // choose type of distortion: PATTERNS, SEPARATE, ROTATE, SHIFTCOPY, SORT
  3071. boolean do_blend = false; // blend result with original?
  3072. int blend_type = SUBTRACT; // list here: https://processing.org/reference/blend_.html
  3073. // segmentation config START
  3074. float threshold = 500.0; // higher number - bigger segments
  3075. int min_comp_size = 200; // minimal segment size (in pixels), minimum 10
  3076. int blur = 0; // sometimes it's good to blur image to have less sharp segment edges, 0 = off, blur > 0 - blur kernel size
  3077. int stat_type = DIST; // edge calculation method
  3078. final static int DIST = 0;
  3079. final static int HUE = 1;
  3080. final static int BRIGHTNESS = 2;
  3081. final static int SATURATION = 3;
  3082. final static int ABSDIST = 4;
  3083. // do not touch it
  3084. PImage img, mimg; // load image to this variable
  3085. int num;
  3086. // segmentation config END
  3087. // do not touch, list of types
  3088. final static int PATTERNS = 0; // fill segments with patterns
  3089. final static int SEPARATE = 1; // separate segments (black background visible)
  3090. final static int ROTATE = 2; // rotate content of the segments
  3091. final static int SHIFTCOPY = 3; // copy content from shifted image
  3092. final static int SORT = 4; // sort segments by color value
  3093. // working buffer
  3094. PGraphics buffer;
  3095. SLICER() {
  3096. name = "fxSlicer";
  3097. params.add(new Param("mask layer", INTVAL, 0, shaderListLength-1, new int[]{RANDOM}));
  3098. params.add(new Param("max rotation", FLOATVAL, 0, TWO_PI, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  3099. params.add(new Param("min threshold", INTVAL, -1, 255, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  3100. params.add(new Param("max threshold", INTVAL, -1, 255, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  3101. params.add(new Param("max shift", FLOATVAL, 0, 5, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  3102. params.add(new Param("type", INTVAL, 0, 5, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  3103. params.add(new Param("do blend", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
  3104. params.add(new Param("blend type", INTVAL, 0, blends.length-1, new int[]{RANDOM}));
  3105. params.add(new Param("threshold", FLOATVAL, 100, 2000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  3106. params.add(new Param("min comp size", INTVAL, 10, 500, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  3107. params.add(new Param("blur", INTVAL, 0, 6, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  3108. params.add(new Param("stat type", INTVAL, 0, 6, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  3109. params.add(new Param("fixed rotation", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
  3110. params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM}));
  3111. directionParamIndex = 13;
  3112. shaderListLength = gui.shaderList.size();
  3113. img = createImage(canvas.width, canvas.height, ARGB);
  3114. mimg = createImage(canvas.width, canvas.height, ARGB);
  3115. buffer = createGraphics(img.width, img.height);
  3116. buffer.beginDraw();
  3117. buffer.noStroke();
  3118. buffer.smooth(8);
  3119. buffer.background(0);
  3120. buffer.endDraw();
  3121. }
  3122. int rw, rh, shaderListLength;
  3123. void apply() {
  3124. if (canvas.width != rw || canvas.height != rh) {
  3125. rw = canvas.width;
  3126. rh = canvas.height;
  3127. buffer = createGraphics(rw, rh);
  3128. buffer.beginDraw();
  3129. buffer.noStroke();
  3130. buffer.endDraw();
  3131. img.resize(rw, rh);
  3132. mimg.resize(rw, rh);
  3133. }
  3134. if (shaderListLength != gui.shaderList.size()) {
  3135. shaderListLength = gui.shaderList.size();
  3136. changeParam(0, new Param("mask layer", INTVAL, 0, shaderListLength-1, new int[]{RANDOM}));
  3137. }
  3138. img = canvas.get();
  3139. if ((int)params.get(0).getValue() == pos) {
  3140. mimg = canvas.get();
  3141. } else {
  3142. mimg = gui.shaderList.get((int)params.get(0).getValue()).result.get();
  3143. }
  3144. max_rotation = params.get(1).getValue();
  3145. thr_min = (int)params.get(2).getValue();
  3146. thr_max = (int)params.get(3).getValue();
  3147. max_shift = params.get(4).getValue();
  3148. type = (int)params.get(5).getValue();
  3149. do_blend = boolean((int)params.get(6).getValue());
  3150. blend_type = blends[(int)params.get(7).getValue()];
  3151. threshold = params.get(8).getValue();
  3152. min_comp_size = (int)params.get(9).getValue();
  3153. blur = (int)params.get(10).getValue();
  3154. stat_type = (int)params.get(11).getValue();
  3155. fixed_rotation = boolean((int)params.get(12).getValue());
  3156. //println("");
  3157. //println("Processing...");
  3158. edges.clear();
  3159. makeEdges();
  3160. calculateSegmentation();
  3161. buffer.beginDraw();
  3162. m.clear();
  3163. if (type == PATTERNS) preparePatterns();
  3164. for (int x=0; x<img.width; x++)
  3165. for (int y=0; y<img.height; y++) {
  3166. Integer segment = findEnd(y*img.width+x);
  3167. S segm;
  3168. if (m.containsKey(segment)) {
  3169. segm = m.get(segment);
  3170. if (type == SORT) sortHelper(segm, x, y);
  3171. } else {
  3172. segm = new S();
  3173. segm.rots = sin(fixed_rotation?max_rotation:random(max_rotation));
  3174. segm.rotc = cos(fixed_rotation?max_rotation:random(max_rotation));
  3175. segm.c = img.get(x, y);
  3176. segm.dx = (int)(max_shift*randomGaussian());
  3177. segm.dy = (int)(max_shift*randomGaussian());
  3178. segm.x = x;
  3179. segm.y = y;
  3180. if (brightness(segm.c)>=thr_min && brightness(segm.c)<=thr_max) segm.c = palette[(int)random(palette.length)];
  3181. if (type == PATTERNS) {
  3182. segm.pat = patterns[(int)random(max_patterns)];
  3183. segm.pats = random(0.5, 10);
  3184. }
  3185. if (type == SORT) {
  3186. segm.xy = random(1)<0.5;
  3187. int size = elements[segment].size;
  3188. segm.clrs = new color[size];
  3189. segm.positions = new int[size];
  3190. segm.iters = 0;
  3191. sortHelper(segm, x, y);
  3192. }
  3193. m.put(segment, segm);
  3194. }
  3195. if (type == PATTERNS) {
  3196. int vx = segm.x-x;
  3197. int vy = segm.y-y;
  3198. float sinr = segm.rots;
  3199. float cosr = segm.rotc;
  3200. int imgx = int(segm.pat.width+x+(cosr*vx-sinr*vy))%segm.pat.width;
  3201. int imgy = int(segm.pat.height+x+(sinr*vx+cosr*vy))%segm.pat.height;
  3202. buffer.fill(segm.pat.get(imgx, imgy));
  3203. buffer.rect(x, y, 1, 1);
  3204. } else if (type == SEPARATE) {
  3205. buffer.fill(segm.c);
  3206. buffer.rect(x+segm.dx, y+segm.dy, 1, 1);
  3207. } else if (type == SHIFTCOPY) {
  3208. int imgx = (2*x-segm.x)%img.width;
  3209. int imgy = (2*y-segm.y)%img.height;
  3210. buffer.fill(img.get(imgx, imgy));
  3211. buffer.rect(x, y, 1, 1);
  3212. } else if (type == ROTATE) {
  3213. int vx = segm.x-x;
  3214. int vy = segm.y-y;
  3215. float sinr = segm.rots;
  3216. float cosr = segm.rotc;
  3217. int imgx = int(img.width+x+(cosr*vx-sinr*vy))%img.width;
  3218. int imgy = int(img.height+y+(sinr*vx+cosr*vy))%img.height;
  3219. buffer.fill(img.get(imgx, imgy));
  3220. buffer.rect(x, y, 1, 1);
  3221. }
  3222. }
  3223. if (type == SORT) {
  3224. for (Integer key : m.keySet()) {
  3225. S segm = m.get(key);
  3226. segm.clrs = sort(segm.clrs);
  3227. segm.positions = sort(segm.positions);
  3228. }
  3229. for (Integer key : m.keySet()) {
  3230. S segm = m.get(key);
  3231. for (int i=0; i<segm.positions.length; i++) {
  3232. int x, y;
  3233. if (segm.xy) {
  3234. x = (segm.positions[i] >> 16) & 0xffff;
  3235. y = segm.positions[i] & 0xffff;
  3236. } else {
  3237. y = (segm.positions[i] >> 16) & 0xffff;
  3238. x = segm.positions[i] & 0xffff;
  3239. }
  3240. buffer.fill(segm.clrs[i]);
  3241. buffer.rect(x, y, 1, 1);
  3242. }
  3243. }
  3244. }
  3245. if (do_blend)
  3246. buffer.blend(img, 0, 0, img.width, img.height, 0, 0, buffer.width, buffer.height, blend_type);
  3247. buffer.endDraw();
  3248. canvas.beginDraw();
  3249. canvas.image(buffer, canvas.width/2, canvas.height/2);
  3250. canvas.endDraw();
  3251. }
  3252. void sortHelper(S segm, int x, int y) {
  3253. int xyval;
  3254. if (segm.xy)
  3255. xyval = (x << 16) | y;
  3256. else
  3257. xyval = (y << 16) | x;
  3258. segm.clrs[segm.iters] = img.get(x, y);
  3259. segm.positions[segm.iters++] = xyval;
  3260. }
  3261. final float getStat(color c1, color c2) {
  3262. switch(stat_type) {
  3263. case HUE:
  3264. abs(hue(c1)-hue(c2));
  3265. case BRIGHTNESS:
  3266. abs(brightness(c1)-brightness(c2));
  3267. case SATURATION:
  3268. abs(saturation(c1)-saturation(c2));
  3269. case ABSDIST:
  3270. return abs(red(c1)-red(c2)) + abs(green(c1)-green(c2)) + abs(blue(c1)-blue(c2));
  3271. default:
  3272. return sq(red(c1)-red(c2)) + sq(green(c1)-green(c2)) + sq(blue(c1)-blue(c2));
  3273. }
  3274. }
  3275. void makeEdges() {
  3276. PImage img2 = mimg.get(0, 0, img.width, img.height);
  3277. if (blur > 0) img2.filter(BLUR, blur);
  3278. // make grid each point connected to neighbours
  3279. for (int x=0; x<img2.width; x++)
  3280. for (int y=0; y<img2.height; y++) {
  3281. color c = img2.get(x, y);
  3282. if (x<img2.width-1) {
  3283. Edge e = new Edge();
  3284. e.a = y*img2.width+x;
  3285. e.b = y*img2.width+x+1;
  3286. e.weight = getStat(c, img2.get(x+1, y));
  3287. edges.add(e);
  3288. }
  3289. if (y<img2.height-1) {
  3290. Edge e = new Edge();
  3291. e.a = y*img2.width+x;
  3292. e.b = (y+1)*img2.width+x;
  3293. e.weight = getStat(c, img2.get(x, y+1));
  3294. edges.add(e);
  3295. }
  3296. if ( (x<img2.width-1) && (y<img2.height-1)) {
  3297. Edge e = new Edge();
  3298. e.a = y*img2.width+x;
  3299. e.b = (y+1)*img2.width+x+1;
  3300. e.weight = getStat(c, img2.get(x+1, y+1));
  3301. edges.add(e);
  3302. }
  3303. if ( (x<img2.width-1) && (y>0)) {
  3304. Edge e = new Edge();
  3305. e.a = y*img2.width+x;
  3306. e.b = (y-1)*img2.width+x+1;
  3307. e.weight = getStat(c, img2.get(x+1, y-1));
  3308. edges.add(e);
  3309. }
  3310. }
  3311. // sort edges
  3312. Collections.sort(edges);
  3313. }
  3314. int findEnd(int x) {
  3315. int y = x;
  3316. while (y != elements[y].parent) y = elements[y].parent;
  3317. elements[x].parent = y;
  3318. return y;
  3319. }
  3320. void joinSegments(int x, int y) {
  3321. if (elements[x].rank > elements[y].rank) {
  3322. elements[y].parent = x;
  3323. elements[x].size += elements[y].size;
  3324. } else {
  3325. elements[x].parent = y;
  3326. elements[y].size += elements[x].size;
  3327. if (elements[x].rank == elements[y].rank) elements[y].rank++;
  3328. }
  3329. num--;
  3330. }
  3331. void calculateSegmentation() {
  3332. int no_vertices = img.width*img.height;
  3333. num = no_vertices;
  3334. elements = new SegmentNode[no_vertices];
  3335. // init nodes
  3336. for (int i=0; i<no_vertices; i++) {
  3337. SegmentNode s = new SegmentNode();
  3338. s.rank = 0;
  3339. s.size = 1;
  3340. s.parent = i;
  3341. elements[i]=s;
  3342. }
  3343. float[] thresholds = new float[no_vertices];
  3344. Arrays.fill(thresholds, threshold);
  3345. for (Edge edge : edges) {
  3346. int a = findEnd(edge.a);
  3347. int b = findEnd(edge.b);
  3348. if (a!=b) {
  3349. if (edge.weight <= thresholds[a] && edge.weight <= thresholds[b]) {
  3350. joinSegments(a, b);
  3351. a = findEnd(a);
  3352. thresholds[a] = edge.weight + threshold/elements[a].size;
  3353. }
  3354. }
  3355. }
  3356. for (Edge edge : edges) {
  3357. int a = findEnd(edge.a);
  3358. int b = findEnd(edge.b);
  3359. if ( (a != b) && ((elements[a].size < min_comp_size) || (elements[b].size < min_comp_size))) {
  3360. joinSegments(a, b);
  3361. }
  3362. }
  3363. //println("Segments: " +num);
  3364. }
  3365. PImage[] patterns;
  3366. void preparePatterns() {
  3367. patterns = new PImage[max_patterns];
  3368. for (int i=0; i<max_patterns; i++) {
  3369. patterns[i] = getSelfPattern();
  3370. }
  3371. }
  3372. PImage getSelfPattern() {
  3373. int x = (int)random(img.width-50);
  3374. int y = (int)random(img.height-50);
  3375. int sx = (int)random(50, img.width-x-1);
  3376. int sy = (int)random(50, img.height-y-1);
  3377. return img.get(x, y, sx, sy);
  3378. }
  3379. PImage getLayerPattern(int layer) { //use me
  3380. int x = (int)random(gui.shaderList.get(layer).canvas.width-50);
  3381. int y = (int)random(gui.shaderList.get(layer).canvas.height-50);
  3382. int sx = (int)random(50, gui.shaderList.get(layer).canvas.width-x-1);
  3383. int sy = (int)random(50, gui.shaderList.get(layer).canvas.height-y-1);
  3384. return gui.shaderList.get(layer).canvas.get(x, y, sx, sy);
  3385. }
  3386. }
  3387. // general class to save distortions for particular segment
  3388. class S {
  3389. color c; // color of the segment root point
  3390. int x, y; // position of segment root point
  3391. int dx, dy; // segment shift
  3392. float rots, rotc, pats;
  3393. PImage pat;
  3394. // sort
  3395. color[] clrs;
  3396. int[] positions;
  3397. boolean xy;
  3398. int iters;
  3399. }
  3400. class Edge implements Comparable {
  3401. int a, b;
  3402. float weight;
  3403. int compareTo(Object o) {
  3404. Edge e = (Edge)o;
  3405. return this.weight<e.weight?-1:this.weight>e.weight?1:0;
  3406. }
  3407. }
  3408. class SegmentNode {
  3409. int rank, parent, size;
  3410. }
  3411. /*
  3412. STREAKER
  3413. */
  3414. class STREAKER extends Shader {
  3415. final int EXCLUSIVE = 0;
  3416. final int LESSER = 1;
  3417. final int GREATER = 2;
  3418. final int CLASSIC = 0;
  3419. final int RGBSUM = 1;
  3420. final int BRIGHT = 2;
  3421. PImage img;
  3422. float tol = 100.0; // tolerance
  3423. int mode = LESSER; // EXCLUSIVE, LESSER, GREATER
  3424. int sum = BRIGHT; // CLASSIC, RGBSUM, BRIGHT
  3425. int lim = 1; // move divisor
  3426. int iterations = 1;
  3427. float rand = 5;
  3428. boolean h = false;
  3429. boolean v = true;
  3430. boolean Hrev = false;
  3431. boolean Vrev = false;
  3432. int W, H;
  3433. STREAKER() {
  3434. name = "fxStreaker";
  3435. img = createImage(canvas.width, canvas.height, ARGB);
  3436. params.add(new Param("vertical/horizontal/both", INTVAL, 0, 2, new int[]{RANDOM}));
  3437. params.add(new Param("verticals up / down", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
  3438. params.add(new Param("horicontals up / down", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
  3439. params.add(new Param("tolerance", FLOATVAL, 0, 100, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  3440. params.add(new Param("tolerance randomness", FLOATVAL, 0, 50, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  3441. params.add(new Param("detection mode (EXCLUSIVE, LESSER, GREATER)", INTVAL, 0, 2, new int[]{RANDOM}));
  3442. params.add(new Param("sum (RBG sum, brightness, R>G>B)", INTVAL, 0, 2, new int[]{RANDOM}));
  3443. params.add(new Param("move divisor", INTVAL, 1, 5, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  3444. params.add(new Param("iterations", INTVAL, 1, 10, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  3445. params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM}));
  3446. directionParamIndex = 9;
  3447. W = canvas.width;
  3448. H = canvas.height;
  3449. }
  3450. void apply() {
  3451. if (W != canvas.width || H != canvas.height) {
  3452. W = canvas.width;
  3453. H = canvas.height;
  3454. img.resize(W, H);
  3455. }
  3456. img = canvas.get();
  3457. int p0 = (int)params.get(0).getValue();
  3458. v = (p0 == 0 || p0 == 2) ? true : false;
  3459. h = (p0 == 1 || p0 == 2) ? true : false;
  3460. Vrev = boolean((int)params.get(1).getValue());
  3461. Hrev = boolean((int)params.get(2).getValue());
  3462. tol = params.get(3).getValue();
  3463. rand = params.get(4).getValue();
  3464. mode = (int)params.get(5).getValue();
  3465. sum = (int)params.get(6).getValue();
  3466. lim = (int)params.get(7).getValue();
  3467. iterations = (int)params.get(8).getValue();
  3468. PGraphics temp = createGraphics(img.width, img.height);
  3469. int off = 0;
  3470. color c;
  3471. boolean a = false;
  3472. for (int i = 0; i < iterations; i++) {
  3473. img.loadPixels();
  3474. temp.beginDraw();
  3475. temp.image(img, 0, 0);
  3476. if (h) {
  3477. if (!Hrev) {
  3478. for (int y = 0; y < img.height-1; y++) {
  3479. for (int x = 0; x < img.width-1; x++) {
  3480. c = img.pixels[x+(y*img.width)];
  3481. while (check (x, y, x+off+1, y) == true && x+off+1 < img.width) {
  3482. off++;
  3483. a = true;
  3484. }
  3485. if (a) {
  3486. temp.stroke(c);
  3487. temp.line(x, y, x+(off/lim), y);
  3488. x = x+(off/lim);
  3489. a = false;
  3490. off = 0;
  3491. }
  3492. }
  3493. }
  3494. } else { // hrev
  3495. for (int y = 0; y < img.height-1; y++) {
  3496. for (int x = img.width-1; x > 1; x--) {
  3497. c = img.pixels[x+(y*img.width)];
  3498. while (check (x, y, x-off-1, y) == true && x-off-1 > 0) {
  3499. off++;
  3500. a = true;
  3501. }
  3502. if (a) {
  3503. temp.stroke(c);
  3504. temp.line(x, y, x-(off/lim), y);
  3505. x = x-(off/lim);
  3506. a = false;
  3507. off = 0;
  3508. }
  3509. }
  3510. }
  3511. }
  3512. }
  3513. if (v) {
  3514. if (!Vrev) {
  3515. for (int x = 0; x < img.width-1; x++) {
  3516. for (int y = 0; y < img.height-1; y++) {
  3517. c = img.pixels[x+(y*img.width)];
  3518. while (check (x, y, x, y+off+1) == true && y+off+1 < img.height-1 ) {
  3519. off++;
  3520. a = true;
  3521. }
  3522. if (a) {
  3523. temp.stroke(c);
  3524. temp.line(x, y, x, y+(off/lim));
  3525. y = y+(off/lim);
  3526. a = false;
  3527. off = 0;
  3528. }
  3529. }
  3530. }
  3531. } else { //Vrev
  3532. for (int x = 0; x < img.width-1; x++) {
  3533. for (int y = img.height-1; y > 1; y--) {
  3534. c = img.pixels[x+(y*img.width)];
  3535. while (check (x, y, x, y-off-1) == true && y-off-1 > 0) {
  3536. off++;
  3537. a = true;
  3538. }
  3539. if (a) {
  3540. temp.stroke(c);
  3541. temp.line(x, y, x, y-(off/lim));
  3542. y = y-(off/lim);
  3543. a = false;
  3544. off = 0;
  3545. }
  3546. }
  3547. }
  3548. }
  3549. }
  3550. temp.endDraw();
  3551. img = temp.get();
  3552. img.updatePixels();
  3553. }
  3554. canvas.beginDraw();
  3555. canvas.image(img, canvas.width/2, canvas.height/2);
  3556. canvas.endDraw();
  3557. }
  3558. boolean check(int x, int y, int xc, int yc) {
  3559. float src, dst, r;
  3560. r = (rand != 0) ? random(0, rand) : 0;
  3561. switch(sum) {
  3562. case 1: //rgbsum
  3563. src = rgbsum(x, y);
  3564. dst = rgbsum(xc, yc);
  3565. break;
  3566. case 2: // brightness
  3567. src = brightness(img.pixels[x+(y*img.width)]);
  3568. dst = brightness(img.pixels[xc+(yc*img.width)]);
  3569. break;
  3570. default: // 'classic' or asdfish
  3571. src = map(img.pixels[x+(y*img.width)], 0, 0xFFFFFF, 0.0, 255.0);
  3572. dst = map(img.pixels[xc+(yc*img.width)], 0, 0xFFFFFF, 0.0, 255.0);
  3573. break;
  3574. }
  3575. if (mode == 0 && (src < dst-tol-r || src > dst+tol+r)) return true;
  3576. else if (mode == 1 && src > dst+tol-r) return true;
  3577. else if (mode == 2 && src < dst-tol+r) return true;
  3578. else return false;
  3579. }
  3580. float rgbsum(int x, int y) {
  3581. int r = img.pixels[x+(y*img.width)] >> 24 & 0xff;
  3582. int g = img.pixels[x+(y*img.width)] >> 16 & 0xff;
  3583. int b = img.pixels[x+(y*img.width)] & 0xff;
  3584. float result = (r + g + b) / 3;
  3585. return result;
  3586. }
  3587. }
  3588. /*
  3589. SEGMENTER
  3590. */
  3591. class SEGMENTER extends Shader {
  3592. int thres = 64; // threshold
  3593. int mode = 0; // lighter/darker, essentially 'reverses' the sort
  3594. boolean diag = true; // diagonal/straight
  3595. boolean v = true; // use to select initial direction.
  3596. boolean h = true; // if cycling, use V=true H=false.
  3597. boolean choice = false;
  3598. int iterations;
  3599. PImage img;
  3600. int[] bounds = {0, 0, 0, 0};
  3601. boolean running = true;
  3602. SEGMENTER() {
  3603. name = "fxSegmenter";
  3604. params.add(new Param("threshold", INTVAL, 8, 252, new int[]{SINE, TRIANG}));
  3605. params.add(new Param("mode", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
  3606. params.add(new Param("diagonal", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
  3607. params.add(new Param("horizontal", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
  3608. params.add(new Param("vertical", INTVAL, 0, 1, new int[] {RANDOM, SQUAR}));
  3609. params.add(new Param("weirdo pattern mode", INTVAL, 0, 1, new int[] {RANDOM, SQUAR}));
  3610. params.add(new Param("iterations", INTVAL, 1, 100, new int[] {SINE, TRIANG}));
  3611. params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM}));
  3612. directionParamIndex = 7;
  3613. img = createImage(canvas.width, canvas.height, ARGB);
  3614. canvas.beginDraw();
  3615. canvas.colorMode(HSB);
  3616. canvas.endDraw();
  3617. }
  3618. int rw, rh;
  3619. void apply() {
  3620. if (rw != canvas.width || rh != canvas.height) {
  3621. rw = canvas.width;
  3622. rh = canvas.height;
  3623. img.resize(rw, rh);
  3624. bounds[0]= 0;
  3625. bounds[1]= 0;
  3626. bounds[2]= rw;
  3627. bounds[3]= rh;
  3628. }
  3629. img = canvas.get();
  3630. thres = (int)params.get(0).getValue();
  3631. mode = (int)params.get(1).getValue();
  3632. diag = boolean((int)params.get(2).getValue());
  3633. v = boolean((int)params.get(3).getValue());
  3634. h = boolean((int)params.get(4).getValue());
  3635. choice = boolean((int)params.get(5).getValue());
  3636. iterations = (int)params.get(6).getValue();
  3637. canvas.beginDraw();
  3638. canvas.image(img, canvas.width/2, canvas.height/2);
  3639. canvas.endDraw();
  3640. canvas.beginDraw();
  3641. for (int i = 0; i < iterations; i++) {
  3642. canvas.loadPixels();
  3643. for (int j = bounds[1]; j < bounds[3]-1; j++) {
  3644. for (int k = bounds[0]; k < bounds[2]-1; k++) {
  3645. float bright = canvas.brightness(canvas.get(k, j));
  3646. color c;
  3647. if (!choice) {
  3648. if (diag) {
  3649. if (mode == 0) {
  3650. if (h && bright < abs(thres)&& k > bounds[0]+1 && j > bounds[1]+1 && (bright < canvas.brightness(canvas.pixels[k-1+((j-1)*canvas.width)]))) {
  3651. swap(k, j, k-1, j-1);
  3652. } else if (v && bright < abs(thres*2) && j > bounds[1]+1 && k < bounds[2]-1 && (bright < canvas.brightness(canvas.pixels[k+1+((j-1)*canvas.width)]))) {
  3653. swap(k, j, k+1, j-1);
  3654. } else if (h && bright < abs(thres*3) && k < bounds[2]-1 && j < bounds[3]-1 && (bright < canvas.brightness(canvas.pixels[k+1+((j+1)*canvas.width)]))) {
  3655. swap(k, j, k+1, j+1);
  3656. } else if (v && k > bounds[0] && j < bounds[3]-1 && (bright < canvas.brightness(canvas.pixels[k-1+((j+1)*canvas.width)]))) {
  3657. swap(k, j, k-1, j+1);
  3658. }
  3659. } else { // mode
  3660. if (h && bright < abs(thres)&& k > bounds[0] && j > bounds[1] && (bright > canvas.brightness(canvas.pixels[k-1+((j-1)*canvas.width)]))) {
  3661. swap(k, j, k-1, j-1);
  3662. } else if (v && bright < abs(thres*2) && j > bounds[1] && k < bounds[2]-1 && (bright > canvas.brightness(canvas.pixels[k+1+((j-1)*canvas.width)]))) {
  3663. swap(k, j, k+1, j-1);
  3664. } else if (h && bright < abs(thres*3) && k < bounds[2]-1 && j < bounds[3]-1 && (bright > canvas.brightness(canvas.pixels[k+1+((j+1)*canvas.width)]))) {
  3665. swap(k, j, k+1, j+1);
  3666. } else if (v && k > bounds[0] && j < bounds[3]-1 && (bright > canvas.brightness(canvas.pixels[k-1+((j+1)*canvas.width)]))) {
  3667. swap(k, j, k-1, j+1);
  3668. }
  3669. } // mode
  3670. }//diag
  3671. else {
  3672. if (mode == 0) {
  3673. if (h && bright < abs(thres)&& k > bounds[0] && (bright < canvas.brightness(canvas.get(k-1, j)))) {
  3674. swap(k, j, k-1, j);
  3675. } else if (v && bright < abs(thres*2) && j > bounds[1] && (bright < canvas.brightness(canvas.get(k, j-1)))) {
  3676. swap(k, j, k, j-1);
  3677. } else if (h && bright < abs(thres*3) && k < bounds[2]-1 && (bright < canvas.brightness(canvas.get(k+1, j)))) {
  3678. swap(k, j, k+1, j);
  3679. } else if (v && k > bounds[0] && j < bounds[3]-1 && (bright < canvas.brightness(canvas.get(k, j+1)))) {
  3680. swap(k, j, k, j+1);
  3681. }
  3682. } else { // mode
  3683. if (h && bright < abs(thres)&& k > bounds[0] && (bright > canvas.brightness(canvas.get(k-1, j)))) {
  3684. swap(k, j, k-1, j);
  3685. } else if (v && bright < abs(thres*2) && j > bounds[1] && (bright > canvas.brightness(canvas.get(k, j-1)))) {
  3686. swap(k, j, k, j-1);
  3687. } else if (h && bright < abs(thres*3) && k < bounds[2]-1 && (bright > canvas.brightness(canvas.get(k+1, j)))) {
  3688. swap(k, j, k+1, j);
  3689. } else if (v && k > bounds[0] && j < bounds[3]-1 && (bright > canvas.brightness(canvas.get(k, j+1)))) {
  3690. swap(k, j, k, j+1);
  3691. }
  3692. } // mode
  3693. } // diag
  3694. } else { //choice
  3695. //weirdo pattern mode
  3696. if (mode == 0) {
  3697. if (bright < thres && k-1+((j-1)*canvas.width) > 0) {
  3698. swap(k, j, k-1, j-1);
  3699. } else if (bright < abs(thres*2) && k+1+((j-1)*canvas.width) > 0) {
  3700. swap(k, j, k+1, j-1);
  3701. } else if (bright < abs(thres*3) && k+1+((j+1)*canvas.width) < canvas.width*canvas.height) {
  3702. swap(k, j, k+1, j+1);
  3703. } else if (k-1+((j+1)*canvas.width) < canvas.width*canvas.height) {
  3704. swap(k, j, k-1, j+1);
  3705. }
  3706. } else { // mode
  3707. if (bright > abs(thres*3) && k-1+((j-1)*canvas.width) > 0) {
  3708. if (k-1+((j-1)*canvas.width) > 0) {
  3709. swap(k, j, k-1, j-1);
  3710. }
  3711. } else
  3712. if (bright > abs(thres*2) && k+1+((j-1)*canvas.width) > 0) {
  3713. if (k+1+((j-1)*canvas.width) > 0) {
  3714. swap(k, j, k+1, j-1);
  3715. }
  3716. } else
  3717. if (bright < thres && k+1+((j+1)*canvas.width) < canvas.width*canvas.height) {
  3718. swap(k, j, k+1, j+1);
  3719. } else if (k-1+((j+1)*canvas.width) < canvas.width*canvas.height) {
  3720. swap(k, j, k-1, j+1);
  3721. }
  3722. } // mode
  3723. }//choice
  3724. }//hori loop
  3725. }//vert loop
  3726. canvas.updatePixels();
  3727. }//iterations
  3728. canvas.endDraw();
  3729. }
  3730. void swap(int x, int y, int xc, int yc) {
  3731. // if (x+(y*width) < width*height && xc+(yc*width) < width*height && xc+(yc*width) > -1) {
  3732. color c = canvas.pixels[x+(y*canvas.width)];
  3733. canvas.pixels[x+(y*canvas.width)] = canvas.pixels[xc+(yc*canvas.width)];
  3734. canvas.pixels[xc+((yc)*canvas.width)] = c;
  3735. // }
  3736. }
  3737. }
  3738. /*
  3739. COLORCRUSHER
  3740. */
  3741. class COLORCRUSHER extends Shader {
  3742. float c;
  3743. int m = 5;
  3744. COLORCRUSHER() {
  3745. name = "fxColorCrusher";
  3746. params.add(new Param("multiplier", INTVAL, 2, 10, new int[]{SINE, TAN, SAWTOOTH, TRIANG}));
  3747. }
  3748. void apply() {
  3749. m = (int)params.get(0).getValue();
  3750. canvas.beginDraw();
  3751. canvas.loadPixels();
  3752. for (int i = 0; i < canvas.pixels.length; i++) {
  3753. c = color(canvas.pixels[i]);
  3754. canvas.pixels[i] = int(c*m);
  3755. }
  3756. canvas.updatePixels();
  3757. canvas.endDraw();
  3758. }
  3759. }
  3760. /*
  3761. RAINBOWHUE
  3762. */
  3763. //...
  3764. /*
  3765. JPGCorruption
  3766. by Victor Giers
  3767. */
  3768. class JPGCORRUPTION extends Shader {
  3769. PImage img;
  3770. byte[] brokenfile;
  3771. JPGCORRUPTION() {
  3772. name = "fxJPGHexGlitch";
  3773. params.add(new Param("byte amount to change probability", INTVAL, 2, 200, new int[]{RANDOM}));
  3774. params.add(new Param("iterations", INTVAL, 2, 10, new int[]{RANDOM}));
  3775. params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM}));
  3776. directionParamIndex = 2;
  3777. rw = canvas.width;
  3778. rh = canvas.height;
  3779. img = createImage(rw, rh, ARGB);
  3780. }
  3781. int rw, rh;
  3782. void apply() {
  3783. if (rw != canvas.width || rh != canvas.height) {
  3784. rw = canvas.width;
  3785. rh = canvas.height;
  3786. img.resize(rw, rh);
  3787. }
  3788. int probparam = (int)params.get(0).getValue();
  3789. int iterations = (int)params.get(1).getValue();
  3790. img = canvas.get();
  3791. canvas.beginDraw();
  3792. for (int k = 0; k < iterations; k++) {
  3793. canvas.image(img, canvas.width/2, canvas.height/2);
  3794. canvas.save(dataPath("")+"/JPGHex.jpg"); //save as jpg
  3795. brokenfile = loadBytes(dataPath("")+"/JPGHex.jpg"); //and reload. just in case it wasnt a jpg.
  3796. double probability = float(probparam) / float(brokenfile.length);
  3797. byte[] savebytes2 = new byte[brokenfile.length];
  3798. boolean headerEnd = false;
  3799. boolean FFfound = false;
  3800. int glitchCount = 0;
  3801. for (int i = 0; i < brokenfile.length; i++) {
  3802. String hexStr = hex(brokenfile[i]);
  3803. if (FFfound && hexStr.equals("DA")) headerEnd = true;
  3804. FFfound = false;
  3805. if (hexStr.equals("FF")) FFfound = true;
  3806. if (headerEnd && random(1)<probability) {
  3807. String randomHex = (str(Character.forDigit((int)random(16), 16)) + str(Character.forDigit((int)random(16), 16))).toUpperCase();
  3808. hexStr = randomHex;
  3809. glitchCount++;
  3810. }
  3811. byte hexByte[] = fromHexString(hexStr);
  3812. for (int j = 0; j < hexByte.length; j++) {
  3813. savebytes2[i] += hexByte[j];
  3814. }
  3815. }
  3816. //println("Glitched " + glitchCount + " bytes");
  3817. saveBytes(dataPath("") + "/JPGHex.jpg", savebytes2);
  3818. img = loadImage(dataPath("") + "/JPGHex.jpg");
  3819. }
  3820. canvas.endDraw();
  3821. }
  3822. byte[] fromHexString(final String encoded) {
  3823. if ((encoded.length() % 2) != 0)
  3824. throw new IllegalArgumentException("Input string must contain an even number of characters");
  3825. final byte result[] = new byte[encoded.length()/2];
  3826. final char enc[] = encoded.toCharArray();
  3827. for (int i = 0; i < enc.length; i += 2) {
  3828. StringBuilder curr = new StringBuilder(2);
  3829. curr.append(enc[i]).append(enc[i + 1]);
  3830. result[i/2] = (byte) Integer.parseInt(curr.toString(), 16);
  3831. }
  3832. return result;
  3833. }
  3834. }
  3835. class WEBPCORRUPTION extends Shader {
  3836. PImage img;
  3837. byte[] brokenfile;
  3838. int rw, rh;
  3839. String[] convertToPNG;
  3840. String[] convertToWebp;
  3841. WEBPCORRUPTION() {
  3842. name = "fxWebpCorruption";
  3843. params.add(new Param("byte amount to change probability", INTVAL, 2, 50, new int[]{RANDOM}));
  3844. params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM}));
  3845. directionParamIndex = 1;
  3846. rw = canvas.width;
  3847. rh = canvas.height;
  3848. img = createImage(rw, rh, ARGB);
  3849. convertToPNG = new String[]{"/usr/local/bin/convert", "-verbose", dataPath("") + "/webp_glitched.webp", dataPath("") + "/webp_glitched.png"};
  3850. convertToWebp = new String[]{"/usr/local/bin/convert", "-verbose", dataPath("") + "/webp_orig.png", dataPath("") + "/webp_orig.webp"};
  3851. }
  3852. void apply() {
  3853. if (rw != canvas.width || rh != canvas.height) {
  3854. rw = canvas.width;
  3855. rh = canvas.height;
  3856. img.resize(rw, rh);
  3857. }
  3858. int probparam = (int)params.get(0).getValue();
  3859. img = canvas.get();
  3860. canvas.beginDraw();
  3861. canvas.image(img, canvas.width/2, canvas.height/2);
  3862. File oldImage = new File(dataPath("")+"/webp_orig.png");
  3863. if (oldImage.exists()) {
  3864. oldImage.delete();
  3865. }
  3866. oldImage = new File(dataPath("")+"/webp_orig.webp"); //is it better to move this up again?
  3867. if (oldImage.exists()) {
  3868. oldImage.delete();
  3869. }
  3870. oldImage = new File(dataPath("")+"/webp_glitched.webp");
  3871. if (oldImage.exists()) {
  3872. oldImage.delete();
  3873. }
  3874. oldImage = new File(dataPath("")+"/webp_glitched.png");
  3875. if (oldImage.exists()) {
  3876. oldImage.delete();
  3877. }
  3878. canvas.save(dataPath("")+"/webp_orig.png"); //save as png
  3879. int failCount = 0;
  3880. while ((runCommand(convertToPNG) != 0) && failCount < 25) {
  3881. failCount ++;
  3882. println("Trying to convert...");
  3883. while (runCommand(convertToWebp) != 0) {
  3884. println("Conversion failed, trying again...");
  3885. }
  3886. brokenfile = loadBytes(dataPath("")+"/webp_orig.webp"); //and reload. just in case it wasnt a jpg.
  3887. byte[] savebytes = new byte[brokenfile.length];
  3888. double probability = float(probparam) / float(brokenfile.length);
  3889. int glitchCount = 0;
  3890. for (int i = 0; i < brokenfile.length; i++) {
  3891. String hexStr = hex(brokenfile[i]);
  3892. if (i > 10) { // skip header
  3893. if (random(1)<probability) {
  3894. String randomHex = (str(Character.forDigit((int)random(16), 16)) + str(Character.forDigit((int)random(16), 16))).toUpperCase();
  3895. hexStr = randomHex;
  3896. glitchCount++;
  3897. }
  3898. }
  3899. byte hexByte[] = fromHexString(hexStr);
  3900. for (int j = 0; j < hexByte.length; j++) {
  3901. savebytes[i] += hexByte[j];
  3902. }
  3903. }
  3904. println("Glitched " + glitchCount + " bytes");
  3905. saveBytes(dataPath("") + "/webp_glitched.webp", savebytes);
  3906. File newImage = new File(dataPath("")+"/webp_glitched.webp");
  3907. while (!newImage.exists()) {
  3908. println("Waiting until bytes have been written to disk...");
  3909. }
  3910. /*
  3911. String[] convertToPNG = {"/usr/local/bin/convert", "-verbose", dataPath("") + "/webp_glitched.webp", dataPath("") + "/webp_glitched.png"};
  3912. while (!runCommand(convertToPNG)) {
  3913. println("Trying to convert...");
  3914. }
  3915. */
  3916. }
  3917. if (failCount == 25) println("Failed 50 times, skipping webp glitch");
  3918. else img = loadImage(dataPath("") + "/webp_glitched.png");
  3919. //launch(dataPath("") + "/webpdecode.command");
  3920. //delay(1500);
  3921. //try or load fallback image and redo in while loop
  3922. //PImage compare = img.get();
  3923. //img = loadImage(dataPath("") + "/result.png");
  3924. canvas.image(img, canvas.width/2, canvas.height/2);
  3925. canvas.endDraw();
  3926. }
  3927. byte[] fromHexString(final String encoded) {
  3928. if ((encoded.length() % 2) != 0)
  3929. throw new IllegalArgumentException("Input string must contain an even number of characters");
  3930. final byte result[] = new byte[encoded.length()/2];
  3931. final char enc[] = encoded.toCharArray();
  3932. for (int i = 0; i < enc.length; i += 2) {
  3933. StringBuilder curr = new StringBuilder(2);
  3934. curr.append(enc[i]).append(enc[i + 1]);
  3935. result[i/2] = (byte) Integer.parseInt(curr.toString(), 16);
  3936. }
  3937. return result;
  3938. }
  3939. }
  3940. /*
  3941. SOX
  3942. */
  3943. class SOX extends Shader {
  3944. PImage img;
  3945. int rw, rh;
  3946. int depth = 8;
  3947. int iterations = 1;
  3948. int samplerate = 44100;
  3949. int channels = 1;
  3950. String coding = "a-law";
  3951. String type = "al";
  3952. int encoding = 0;
  3953. boolean rgbyuv = true;
  3954. boolean do_blend = false;
  3955. int blend_type = 1;
  3956. String[] effectParams;
  3957. SOX() {
  3958. }
  3959. void setSoxParams() {
  3960. rw = canvas.width;
  3961. rh = canvas.height;
  3962. img = createImage(rw, rh, ARGB);
  3963. params.add(new Param("direction", INTVAL, 0, 3, new int[]{RANDOM}));
  3964. directionParamIndex = 0;
  3965. params.add(new Param("iterations", INTVAL, 1, 10, new int[]{RANDOM}));
  3966. params.add(new Param("do blend", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
  3967. params.add(new Param("blend type", INTVAL, 0, blends.length-1, new int[]{RANDOM}));
  3968. params.add(new Param("bitdepth (8, 16, 24)", INTVAL, 1, 3, new int[]{RANDOM}));
  3969. params.add(new Param("samplerate", INTVAL, 1400, 200000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  3970. params.add(new Param("encoding", INTVAL, 0, 7, new int[]{RANDOM}));
  3971. params.add(new Param("yuv / rgb", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
  3972. params.add(new Param("channels (mono / stereo)", INTVAL, 1, 2, new int[]{RANDOM, SQUAR}));
  3973. }
  3974. void apply() {
  3975. iterations = (int)params.get(1).getValue();
  3976. do_blend = boolean((int)params.get(2).getValue());
  3977. blend_type = blends[(int)params.get(3).getValue()];
  3978. depth = (int)params.get(4).getValue() * 8;
  3979. samplerate = (int)params.get(5).getValue();
  3980. encoding = (int)params.get(6).getValue();
  3981. switch(encoding) {
  3982. case(0):
  3983. type = "s8";
  3984. coding = "signed-integer";
  3985. break;
  3986. case(1):
  3987. type = "u8";
  3988. coding = "unsigned-integer";
  3989. break;
  3990. case(2):
  3991. type = "s16";
  3992. coding = "signed-integer";
  3993. break;
  3994. case(3):
  3995. type = "u16";
  3996. coding = "unsigned-integer";
  3997. break;
  3998. case(4):
  3999. type = "s24";
  4000. coding = "signed-integer";
  4001. break;
  4002. case(5):
  4003. type = "u24";
  4004. coding = "unsigned-integer";
  4005. break;
  4006. case(6):
  4007. type = "al";
  4008. coding = "a-law";
  4009. break;
  4010. case(7):
  4011. type = "ul";
  4012. coding = "u-law";
  4013. break;
  4014. default:
  4015. type = "f32";
  4016. coding = "float";
  4017. break;
  4018. }
  4019. rgbyuv = boolean((int)params.get(7).getValue());
  4020. channels = (int)params.get(8).getValue();
  4021. getParams();
  4022. if (rw != canvas.width || rh != canvas.height) {
  4023. rw = canvas.width;
  4024. rh = canvas.height;
  4025. img.resize(rw, rh);
  4026. }
  4027. img = canvas.get();
  4028. canvas.beginDraw();
  4029. canvas.image(img, canvas.width/2, canvas.height/2);
  4030. File oldImage = new File(dataPath("")+"/sox.raw");
  4031. if (oldImage.exists()) {
  4032. oldImage.delete();
  4033. }
  4034. oldImage = new File(dataPath("")+"/sox.png");
  4035. if (oldImage.exists()) {
  4036. oldImage.delete();
  4037. }
  4038. oldImage = new File(dataPath("")+"/sox_sonified.raw");
  4039. if (oldImage.exists()) {
  4040. oldImage.delete();
  4041. }
  4042. canvas.save(dataPath("")+"/sox.png"); //save as png
  4043. String[] convertToRAW = new String[]{"/usr/local/bin/convert", "-verbose", dataPath("") + "/sox.png", "-depth", str(depth), ((rgbyuv) ? "rgb" : "yuv") + ":" + dataPath("") + "/sox.raw"};
  4044. String[] soxCall = new String[]{"/usr/local/bin/sox", "-r", str(samplerate), "-e", coding, "-b", "8", "-c", "2", "-t", type, dataPath("") + "/sox.raw", dataPath("") + "/sox_sonified.raw"};
  4045. String[] sonify = concat(soxCall, effectParams);
  4046. String[] convertToPNG = new String[]{"/usr/local/bin/convert", "-verbose", "-size", str(rw) + "x" + str(rh), "-depth", str(depth), ((rgbyuv) ? "rgb" : "yuv") + ":" + dataPath("") + "/sox_sonified.raw", dataPath("") + "/sox.png"};
  4047. for (int i = 0; i < iterations; i++) {
  4048. if (runCommand(convertToRAW) != 0) {
  4049. println("Conversion to RAW failed");
  4050. }
  4051. if (runCommand(sonify) != 0) {
  4052. println("Sonification failed");
  4053. }
  4054. if (runCommand(convertToPNG) != 0) {
  4055. println("Conversion to PNG failed");
  4056. }
  4057. img = loadImage(dataPath("") + "/sox.png");
  4058. }
  4059. if (do_blend) {
  4060. canvas.blend(img, 0, 0, img.width, img.height, 0, 0, canvas.width, canvas.height, blend_type);
  4061. } else {
  4062. canvas.image(img, canvas.width/2, canvas.height/2);
  4063. }
  4064. canvas.endDraw();
  4065. }
  4066. void getParams() {
  4067. }
  4068. }
  4069. /*
  4070. SOXECHO
  4071. NEEDS FIXING
  4072. */
  4073. class SOXECHO extends SOX {
  4074. float gainin = 0.8;
  4075. float gainout = 0.8;
  4076. float delay = 0.8;
  4077. float decay = 0.8;
  4078. SOXECHO() {
  4079. name = "fxSoxEcho";
  4080. setSoxParams();
  4081. params.add(new Param("gain in", FLOATVAL, 0.01, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  4082. params.add(new Param("gain out", FLOATVAL, 0.01, 1000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  4083. params.add(new Param("delay", FLOATVAL, 0.01, 1000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  4084. params.add(new Param("decay", FLOATVAL, 0.01, 1, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  4085. }
  4086. void getParams() {
  4087. gainin = params.get(9).getValue();
  4088. gainout = params.get(10).getValue();
  4089. delay = params.get(11).getValue();
  4090. decay = params.get(12).getValue();
  4091. effectParams = new String[]{"echo", str(gainin), str(gainout), str(delay), str(decay)};
  4092. }
  4093. }
  4094. /*
  4095. SOXALLPASS
  4096. */
  4097. class SOXALLPASS extends SOX {
  4098. String hkqo = "h";
  4099. int frequency = 100;
  4100. int widt = 100;
  4101. SOXALLPASS() {
  4102. name = "fxSoxAllpass";
  4103. setSoxParams();
  4104. params.add(new Param("frequency", INTVAL, 1, 1000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  4105. params.add(new Param("width", INTVAL, 1, 10000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  4106. params.add(new Param("h/k/q/o", INTVAL, 0, 3, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  4107. }
  4108. void getParams() {
  4109. frequency = (int)params.get(9).getValue();
  4110. widt = (int)params.get(10).getValue();
  4111. switch((int)params.get(11).getValue()) {
  4112. case(0):
  4113. hkqo = "h";
  4114. break;
  4115. case(1):
  4116. hkqo = "k";
  4117. break;
  4118. case(2):
  4119. hkqo = "q";
  4120. break;
  4121. default:
  4122. hkqo = "o";
  4123. break;
  4124. }
  4125. effectParams = new String[]{"allpass", str(frequency), str(widt) + hkqo};
  4126. }
  4127. }
  4128. /*
  4129. SOXBAND
  4130. */
  4131. class SOXBAND extends SOX {
  4132. String hkqo = "h";
  4133. int center = 100;
  4134. int widt = 100;
  4135. boolean n;
  4136. SOXBAND() {
  4137. name = "fxSoxBand";
  4138. setSoxParams();
  4139. params.add(new Param("center", INTVAL, 1, 10000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  4140. params.add(new Param("width", INTVAL, 1, 10000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  4141. params.add(new Param("h/k/q/o", INTVAL, 0, 3, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  4142. params.add(new Param("-n", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
  4143. }
  4144. void getParams() {
  4145. center = (int)params.get(9).getValue();
  4146. widt = (int)params.get(10).getValue();
  4147. switch((int)params.get(11).getValue()) {
  4148. case(0):
  4149. hkqo = "h";
  4150. break;
  4151. case(1):
  4152. hkqo = "k";
  4153. break;
  4154. case(2):
  4155. hkqo = "q";
  4156. break;
  4157. default:
  4158. hkqo = "o";
  4159. break;
  4160. }
  4161. n = boolean((int)params.get(12).getValue());
  4162. effectParams = new String[]{ "band", (n ? "-n " : "") + str(center), str(widt) + hkqo};
  4163. }
  4164. }
  4165. /*
  4166. SOXBANDPASS
  4167. */
  4168. class SOXBANDPASS extends SOX {
  4169. int widt, frequency;
  4170. String hkqo;
  4171. boolean c;
  4172. SOXBANDPASS() {
  4173. name = "soxBandPass";
  4174. setSoxParams();
  4175. params.add(new Param("frequency", INTVAL, 1, 10000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  4176. params.add(new Param("width", INTVAL, 1, 10000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  4177. params.add(new Param("h/k/q/o", INTVAL, 0, 3, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  4178. params.add(new Param("-c", INTVAL, 0, 1, new int[]{RANDOM, SQUAR}));
  4179. }
  4180. void getParams() {
  4181. frequency = (int)params.get(9).getValue();
  4182. widt = (int)params.get(10).getValue();
  4183. switch((int)params.get(11).getValue()) {
  4184. case(0):
  4185. hkqo = "h";
  4186. break;
  4187. case(1):
  4188. hkqo = "k";
  4189. break;
  4190. case(2):
  4191. hkqo = "q";
  4192. break;
  4193. default:
  4194. hkqo = "o";
  4195. break;
  4196. }
  4197. c = boolean((int)params.get(12).getValue());
  4198. effectParams = new String[]{"bandpass", (c ? "-c " : "") + str(frequency), str(widt) + hkqo};
  4199. }
  4200. }
  4201. /*
  4202. SOXBANDREJECT
  4203. */
  4204. class SOXBANDREJECT extends SOX {
  4205. int widt, frequency;
  4206. String hkqo;
  4207. SOXBANDREJECT() {
  4208. name = "soxBandReject";
  4209. setSoxParams();
  4210. params.add(new Param("frequency", INTVAL, 1, 10000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  4211. params.add(new Param("width", INTVAL, 1, 10000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  4212. params.add(new Param("h/k/q/o", INTVAL, 0, 3, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  4213. }
  4214. void getParams() {
  4215. frequency = (int)params.get(9).getValue();
  4216. widt = (int)params.get(10).getValue();
  4217. switch((int)params.get(11).getValue()) {
  4218. case(0):
  4219. hkqo = "h";
  4220. break;
  4221. case(1):
  4222. hkqo = "k";
  4223. break;
  4224. case(2):
  4225. hkqo = "q";
  4226. break;
  4227. default:
  4228. hkqo = "o";
  4229. break;
  4230. }
  4231. effectParams = new String[]{"bandreject", str(frequency), str(widt) + hkqo};
  4232. }
  4233. }
  4234. /*
  4235. SOXBASS
  4236. */
  4237. class SOXBASS extends SOX {
  4238. int widt, frequency, gain;
  4239. float seconds;
  4240. String hkqo;
  4241. SOXBASS() {
  4242. name = "soxBass";
  4243. setSoxParams();
  4244. params.add(new Param("gain", INTVAL, 1, 100, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  4245. params.add(new Param("frequency", INTVAL, 1, 10000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  4246. params.add(new Param("width", INTVAL, 1, 10000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  4247. params.add(new Param("h/k/q/o", INTVAL, 0, 3, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  4248. params.add(new Param("seconds", FLOATVAL, 0.001, 10, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  4249. }
  4250. void getParams() {
  4251. gain = (int)params.get(9).getValue();
  4252. frequency = (int)params.get(10).getValue();
  4253. widt = (int)params.get(11).getValue();
  4254. switch((int)params.get(12).getValue()) {
  4255. case(0):
  4256. hkqo = "h";
  4257. break;
  4258. case(1):
  4259. hkqo = "k";
  4260. break;
  4261. case(2):
  4262. hkqo = "q";
  4263. break;
  4264. default:
  4265. hkqo = "o";
  4266. break;
  4267. }
  4268. seconds = params.get(13).getValue();
  4269. effectParams = new String[]{"bass", str(gain), str(frequency), str(widt) + hkqo};
  4270. }
  4271. }
  4272. /*
  4273. SOXBEND
  4274. */
  4275. class SOXBEND extends SOX {
  4276. int framerate, oversample, start, cents, end;
  4277. SOXBEND() {
  4278. name = "soxBend";
  4279. setSoxParams();
  4280. //params.add(new Param("frequency", INTVAL, 1, 10000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  4281. //params.add(new Param("width", INTVAL, 1, 10000, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  4282. //params.add(new Param("h/k/q/o", INTVAL, 0, 3, new int[]{SAWTOOTH, TRIANG, SINE, TAN, TANINVERSE, RAMPUPDOWN, RAMP, RAMPINVERSE}));
  4283. }
  4284. void getParams() {
  4285. //frequency = (int)params.get(9).getValue();
  4286. //widt = (int)params.get(10).getValue();
  4287. //effectParams = new String[]{"bend", str(frequency), str(widt) + hkqo};
  4288. }
  4289. }