keyPressed working, then not working.

I playing with a small game program which uses the left and right keys to control a paddle. I'm using a chunk of keyPressed code to control the paddle (keyPressed sets / unsets a boolean flag which controls whether the movement happens). When I start up processing then run the sketch it runs absolutely fine. If I stop the script and then re-run it then it doesn't work. I've put in a print statement and it appears that it's simply not registering any key presses at all. If I close down processing entirely and rerun it the script works fine again. Anyone got any clues as to what might be happening here?

submitted by /u/snapse
[link] [comments]

Prolong and fade out if statement action in OpenCV opticalflow sketch

Hi everyone,

This might be a very simple, stupid question but I am rather a noobie to Processing. I have been working on a code which uses the average opticalflow using the OpenCV library. I have an if statement in it, where if the opticalflow is between 2 values, a semi-transparent green rectangle is drawn above.

The code is supposed to work for application in urban lighting design, so when you pass in front of the light the color changes. Problem is that as soon as the opticalflow value drops below my threshold's minimum value set in the if statement, the color changes suddenly. I want it to stay changed for a few more seconds and then fade out. How should I do this? I tried easing, but I think my logic is faulty. Appreciate some help.

import gab.opencv.*; import*; import java.awt.*; Capture video; OpenCV opencv; PImage render; int sizeX = 600; //control zoom level and complexity 200,400,600,800 int sizeY = 600; //Variable for opacity of vectors int alphaVal=50; int alphaVal2; int brightness=100; float easing = 0.01; void setup() { size(500, 500); //fullScreen(); smooth(); render = createImage(sizeX, sizeY, RGB); video = new Capture(this, 640/2, 480/2); opencv = new OpenCV(this, 640/2, 480/2); video.start(); } void draw() { //Creates the Turing pattern render.loadPixels(); for (int i=0; i<sizeX; i++) { for (int j=0; j<sizeY; j++) { float temp = wave(i, j, 5, -frameCount *5, 0, 255); //complexity (5) and speed 1,3,5,7 if (temp<0) temp = 0; if (temp>255) temp = 255; render.pixels[i + j * sizeX] = color(temp); } } render.updatePixels(); image(render, 0, 0, width, height); fill(0, 0, 0, brightness); rect(0, 0, 1366, 768); //Draws average optical flow opencv.loadImage(video); opencv.calculateOpticalFlow(); translate(video.width, 640/2, 480/2); stroke(255); strokeWeight(0); opencv.drawOpticalFlow(); PVector aveFlow = opencv.getAverageFlow(); float flowScale = 0.5; println(aveFlow.x); // stroke(1); // fill(255); PVector newFlow = new PVector(abs(aveFlow.x), abs(aveFlow.y)); if (0.2 < newFlow.x && newFlow.x< 10) { fill(0, 255, 0, alphaVal); noStroke(); rect(0, 0, 1366, 768); //ellipse(width/2,height/2,500,500); } else { float alphaVal; alphaVal = 30 - newFlow.x; fill(0,0,0,alphaVal); noStroke(); //ellipse(width/2,height/2,500,500); rect(0, 0, 1366, 768); } } float wave(float posX, float posY, float freq, float phase, float min, float max) { float dist1 = dist(posX, posY, 0, 0); float dist2 = dist(posX, posY, sizeX, 1); float dist3 = dist(posX, posY, 1, sizeY); float dist4 = dist(posX, posY, sizeX, sizeY); float wave1 = sin( radians( ( ( dist1 * freq) + phase) ) ); float wave2 = sin( radians( ( ( dist2 * freq) + phase) ) ); float wave3 = sin( radians( ( ( dist3 * freq) + phase) ) ); float wave4 = sin( radians( ( ( dist4 * freq) + phase) ) ); return map(wave1 + wave2 + wave3 + wave4, -1.0, 1.0, min, max); } void captureEvent(Capture c) {; } 
submitted by /u/verdealbastrui
[link] [comments]

Michel Campeau. Life Before Digital

Anonyme, Easter Greetings, about 1955. Collection de Michel Campeau

While in Montreal for a series of panels curated by HOLO magazine for the digital festival MUTEK, i felt the need (as i often do) to take a break from discussions about digital creativity. That’s how i ended up visiting the Michel Campeau retrospective at the McCord Museum. The title of the show was promising: Michel Campeau. Life Before Digital.

I wasn’t disappointed. Campeau is a wonderfully talented photographer with a strong interest for the history of photography and in particular the disappearance of analog tools and practices. Each of the series in the exhibition explores a material culture that used to suggest magic and craftmanship: the messy darkrooms with duct tape to fend off the light and wooden pegs to hang the images to dry; the colourful rolls of photo film and the iconic camera models; the amateur developer who gave way to the computer pixel specialist, etc.

Man in bow tie with woman looking at slide, c. 1955 (2015.) Series “Red Border Kodachrome”

Campeau’s homage to silver-based photography culture has a whiff of nostalgia but it’s one that’s never mushy nor mournful. The retrospective presents works executed between 2005 and 2017 as well as anonymous, amateur photographs from the 1950s and 60s. Shown together these images build a very moving, poetic and sometimes even humorous portrait of the rituals of pre-digital photography.

Industrial Splendour and Fetishism: The Bruce Anderson Collection. Sylvania Superflash Blue Dot 25 Flashbulb, Montreal Quebec, c. 1950. Photo via Eric Dupont gallery

Industrial Splendour and Fetishism : The Bruce Anderson Collection. Flash Canon, Tokyo, Japan / Flash Leitz, Wetzlar, Allemagne, c. 1950. Photo via Eric Dupont gallery

Industrial Splendour and Fetishism : The Bruce Anderson Collection. Sinclair Traveller Una, London, England, 1927. Photo via Eric Dupont gallery

Exhibition view of Michel Campeau. Life Before Digital. Photo: McCord Museum

Industrial Splendour and Fetishism are black room portraits of iconic cameras and accessories of the pre-digital era. The instruments look cumbersome, have a bit of a worn-out air but they remain beautifully engineered objects.

Exhibition view of Michel Campeau. Life Before Digital. Photo: McCord Museum

Brussels, Belgium, file no. 9845. Series “Darkroom”, 2005-2010

From the series “Darkroom”, 2005-2010

The Darkrooms is another tribute to analogue photography, this time focusing on spaces that are disappearing fast.

Campeau talks in details about the series in an interview with Ciel Variable. I like the following quote:

“One of the criticisms of the series is that I focused on the dilapidation and decrepitude of the places I photographed. I don’t see things this way; a very large part of the history of photography took place in similar places, and not in antiseptic digital laboratories.”

Other series in the exhibition establish Campeau as a keen collector of ‘found photography’:

Anonymous, Four Color Postcard [détail], about 1960. Collection of Michel Campeau

Anonymous, Four Color Postcard [détail], about 1960. Collection of Michel Campeau

The Monstreal-based artist hunted down colour postcards from the 1950s to the 1970s that show a person taking a photo. He then enlarged the detail featuring the photographer so as to lay bare the four-colour printing process.

Rudolph Edse, Autoportrait, about 1955. Collection of Michel Campeau

Rudolph Edse, An involuntary autobiography, about 1958. Collection of Michel Campeau

Edse was a German scientist who immigrated to the U.S. after 1945. One day, Campeau discovered on eBay his self-portraits which often showed him surrounded by photo instruments. Campeau acquired more photos authored by Edse. The collection is charming, they show a European family living the “American Dream”.

Anonymous, Photo Club, about 1955. Collection of Michel Campeau

Anonymous, Desired Moments, about 1955. Collection of Michel Campeau

Exhibition view of Michel Campeau. Life Before Digital. Photo: McCord Museum

Anonymous, Desired Moments, about 1955. Collection of Michel Campeau

The series Desired Instants compiles anonymous amateur photography from the 1950s that show, once again, amateur photographers holding or posing next to their instruments. They expose a real enthusiasm for a medium that is still intact 60 years later.

Exhibition view of Michel Campeau. Life Before Digital. Photo: McCord Museum

Anonymous, PAS-Foto, Copenhague, DNK, about 1956. Collection of Michel Campeau

Michel Campeau. Life Before Digital remains open at The McCord Museum in Montreal until the 6th of May 2018.

Collision detection using rotate function?

Hey I'm attempting to calculate the collision on my ship as it rotates using the rotate function. Is this a good way to go about it? As the ship is stationary you can see that the collision detection works but as I press the directional keys the collision detection no longer works. Is there a quick fix for this?

PImage stars; float positionX = 0; float positionY = 0; float mouseXX; float mouseYY; //ship rotation float rotated = 0.0; int x = 0; int y = 0; void setup() { size(1000, 800); } void keyPressed() { if (key==CODED) { if (keyCode==RIGHT) { rotated+=0.05; } if (keyCode==LEFT) { rotated-=0.05; } } } void ship() { //side engines fill(255, 0, 0); stroke(255, 0, 0); triangle(positionX, positionY-50, positionX+30, positionY, positionX-30, positionY); //main body fill(150); stroke(150); triangle(positionX, positionY-80, positionX+20, positionY, positionX-20, positionY); //center engine fill(255, 0, 0); stroke(255, 0, 0); triangle(positionX, positionY-25, positionX+10, positionY, positionX-10, positionY); //outside of engine fill(100); stroke(100); triangle(positionX, positionY-25, positionX+3, positionY, positionX+-3, positionY); //window fill(0); stroke(0); triangle(positionX, positionY-75, positionX+3, positionY-60, positionX-3, positionY-60); if (rotated>=TAU) rotated=0; if (rotated<0) rotated=TAU; } void draw() { mouseXX = mouseX - (width/2); mouseYY = (mouseY - (height/2))-40; background(0); pushMatrix(); translate(width/2,height/2); rotate(rotated); translate(0, 40); // offset by half the ship height to rotate around middle of the ship ship(); //calculating ship collision areas //side engines triangle float areaOrigin1 = abs( ((positionX+30)-positionX)*((positionY)-positionY-50) - ((positionX-30)-positionX)*((positionY)-positionY-50) ); float area1 = abs( ((positionX)-mouseXX)*((positionY)-mouseYY) - ((positionX+30)-mouseXX)*((positionY-50)-mouseYY) ); float area2 = abs( ((positionX+30)-mouseXX)*((positionY)-mouseYY) - ((positionX-30)-mouseXX)*((positionY)-mouseYY) ); float area3 = abs( ((positionX-30)-mouseXX)*((positionY-50)-mouseYY) - ((positionX)-mouseXX)*((positionY)-mouseYY) ); //main body triangle float areaOrigin2 = abs( ((positionX+20)-positionX)*((positionY)-positionY-80) - ((positionX-20)-positionX)*((positionY)-positionY-80) ); float area4 = abs( ((positionX)-mouseXX)*((positionY)-mouseYY) - ((positionX+20)-mouseXX)*((positionY-80)-mouseYY) ); float area5 = abs( ((positionX+20)-mouseXX)*((positionY)-mouseYY) - ((positionX-20)-mouseXX)*((positionY)-mouseYY) ); float area6 = abs( ((positionX-20)-mouseXX)*((positionY-80)-mouseYY) - ((positionX)-mouseXX)*((positionY)-mouseYY) ); popMatrix(); fill(255,0,0); ellipse(100,100,100,100); if (area1 + area2 + area3 == areaOrigin1 || area4 + area5 + area6 == areaOrigin2){ fill(0,255,0); ellipse(100,100,100,100); } text("Engines", 180,150); text ("Main", 270, 150); text(areaOrigin1, 180,200); text (areaOrigin2, 270, 200); text((area1 + area2 + area3), 180,250); text((area4 + area5 + area6), 270,250); } 

Thank you.

submitted by /u/Bennypea
[link] [comments]

help with sample.trigger ()

When you click, it takes a moment to reproduce the generated sample, how to do it so that the click is instantly reproduced

import ddf.minim.*; import ddf.minim.analysis.*; import ddf.minim.ugens.*; int buffersize=65536; //32768 //16384 //65536 int samplerate=44100; Minim minim; AudioOutput mainOut; MultiChannelBuffer sampleBuffer; Sampler sampler; void setup() { size(512, 480); minim = new Minim(this);//AudioOutput getLineOut(Minim.MONO, int bufferSize) para salida de audio mainOut = minim.getLineOut(Minim.MONO,buffersize,samplerate); sampleBuffer = new MultiChannelBuffer(samplerate,1); sampler = new Sampler( sampleBuffer, samplerate, 1 ); } void draw() { if (mousePressed) { for(int i=0 ; i<samplerate ; i++ ){ sampleBuffer.setSample(0,i,random(1)); } sampler.setSample(sampleBuffer,samplerate); sampler.unpatch(mainOut); sampler.patch(mainOut); sampler.trigger (); } } 
submitted by /u/macob12432
[link] [comments]