I'm using the "drop" library (thanks, @kfrajer). I can access the image, but can't see a way to access its name? Unfortunately the pages in the "javadocs" page are all dead links.
Hot to get an image's name?
controlP5.Chart Background
Hello, i am using controlP5.Chart to display (ploting) Data from Arduino. My question: is it possible to make the chart-background transparent? thanks for your help
PShape within a Class
I am trying to create a lot of cubes. If I just put createShape inside my Setup, then I get 8000 references to the same cube, so I want to make 8000 children cubes that I can modify the translation and rotation of each one. I am missing something with the Class setup as I am getting a Type MisMatch.
I would appreciate any insight into what I might be doing wrong. Thanks for the help.
import processing.opengl.*;
import peasy.*;
PeasyCam cam;
PShape world;
float CS = .25;
int CPS = 20;
int TotalCubes=CPS*CPS*CPS;
float offset = CPS/2;
int CC = 0; //CubeCount
PShape tempcube;
void setup() {
size(2100, 2100, P3D);
cam = new PeasyCam(this, 15000);
noStroke();
println("Making World");
world=createShape(GROUP);
for (int i = 0; i < TotalCubes; i++) {
tempcube = new MyCube();
world.addChild(tempcube);
println(i); }
println("Translating cubes");
for (int i = 0; i < CPS; i++) {
for (int j = 0; j < CPS; j++) {
for (int k = 0; k < CPS; k++) {
PShape tempcube = world.getChild(CC);
tempcube.translate(i-offset,j-offset,k-offset);
println(CC++, tempcube); }}}
} // end setup
void draw() {
background(127);
scale(90);
shape(world,0,0);
//Change_Cells();
} // end draw
class MyCube {
PShape output;
MyCube() {
int size = 1;
println("Making CUBE");
PShape output = createShape();
output.beginShape(QUADS);
output.fill(0x44FF0000); output.vertex(-CS, CS, CS);output.vertex( CS, CS, CS);output.vertex( CS, -CS, CS);output.vertex(-CS, -CS, CS);
output.fill(0x4400FF00); output.vertex( CS, CS, CS);output.vertex( CS, CS, -CS);output.vertex( CS, -CS, -CS);output.vertex( CS, -CS, CS);
output.fill(0x440000FF); output.vertex( CS, CS, -CS);output.vertex(-CS, CS, -CS);output.vertex(-CS, -CS, -CS);output.vertex( CS, -CS, -CS);
output.fill(0x44FFFF00); output.vertex(-CS, CS, -CS);output.vertex(-CS, CS, CS);output.vertex(-CS, -CS, CS);output.vertex(-CS, -CS, -CS);
output.fill(0x4400FFFF); output.vertex(-CS, CS, -CS);output.vertex( CS, CS, -CS);output.vertex( CS, CS, CS);output.vertex(-CS, CS, CS);
output.fill(0x44FF00FF); output.vertex(-CS, -CS, -CS);output.vertex( CS, -CS, -CS);output.vertex( CS, -CS, CS);output.vertex(-CS, -CS, CS);
output.endShape(CLOSE);
return output;
} // end constructor
}// end MyCube
about SinOsc array: difficulty in stop the sound (sounds stupid!)
Hi, I'm writing a coding for assignment, just one last step: stop the sound. I use an array to store the sound, but when I call it to stop ( sin[y].stop(); ), it would not! It keeps saying Null Pointer Exception. I know the reason that it is null before I selected a square, but it does not work either when I use specific value (sin[0].stop(); etc.).
Here's the full coding.
import processing.sound.*;
SinOsc [] sin;
int t=0;
int spacing = 10;
int rectSize = 40;
boolean [][] selected;
int [] notes = {880, 990, 1110, 1320, 1480};
void setup()
{
size(810,500);
background(129,199,212);
selected = new boolean[16][5];
for (int i = 0; i < selected.length; i++)
{
for(int j = 0; j < selected[i].length; j++)
{
selected[i][j] = false;
}
}
sin = new SinOsc[5];
}
void draw()
{
if(frameCount%20==1)
{
t=(t+1)%16;
sin[0].stop(); //the question is here!~
for (int y=0; y < 5; y++)
{
if(selected[t][y])
{
sin[y] = new SinOsc(this);
sin[y].freq(notes[y]);
sin[y].play();
}
}
}
//draw rectangles
for(int i = 0; i < 16; i++)
{
for (int j = 0; j < 5; j++)
{
int a = spacing*(i+1)+rectSize*i;
int b = spacing*(j+1)+rectSize*j;
if(selected[i][j]) fill(150,150,255); //selected = blue
else fill(254,223,225); //unselected = pink
if(i==t) fill (208,90,110); //red bar according to time
noStroke();
rect(a, b, rectSize, rectSize);
}
}
//interaction buttons
fill(254,223,225);
rect(270, 2*height/3,80,80);
rect(375, 2*height/3,80,80);
rect(480, 2*height/3,80,80);
fill(208,90,110);
rect(285, 2*height/3+15, 50, 50);
triangle(390,2*height/3+10,390, 2*height/3+70, 440,2*height/3+40);
translate(105,0);
triangle(390,2*height/3+40, 440, 2*height/3+10, 440, 2*height/3+70);
rect(380, 2*height/3+10,10,60);
}
void mousePressed()
{
int redX = mouseX/(spacing+rectSize);
int redY = mouseY/(spacing+rectSize);
if (redX>-1 && redX<selected.length && redY>-1 && redY<selected[redY].length)
selected[redX][redY]=!selected[redX][redY];
//buttons
if(dist(mouseX,mouseY,310,2*height/3+40)<40) noLoop(); //pause
else if(dist(mouseX,mouseY,415,2*height/3+40)<40) loop(); //start
else if(dist(mouseX,mouseY,520,2*height/3+40)<40) t=0; //restart: change the variables to the initial value
}
pls pls pls somebody help me! University assignment even the tutor could not solve #minimLibrary
Ball[] balls = new Ball[600]; // An array of 100 Ball objects! String filename = "Christmas"; PShape bot; int sceneNumber = 1; PImage img; import ddf.minim.*; import ddf.minim.effects.*;
Minim minim; AudioPlayer groove;
void setup() { //setup function size(1920, 1080); //set the size of the window bot = loadShape("santa_claus_vector.svg"); smooth(); for (int i = 0; i < balls.length; i ++ ) { // Initialize each Ball using a for loop. balls[i] = new Ball(color (255), random(width), random(height), random(5), random(3), random(10, 25));
} minim = new Minim(this); groove = minim.loadFile("WeWishYouShort.mp3", 2048); }
void draw() { groove.loop(); if (sceneNumber == 1) { background(0, 0, 153); for (int i = 0; i < balls.length; i ++ ) { // Run each Car using a for loop. balls[i].displayAndMove(); }
translate(width/5, height/5); float zoom = map(mouseX, 0, width, 0.1, 4.5); scale(zoom); shape(bot, mouseX, mouseY); } for(int i = 0; i < groove.bufferSize() - 1; i++) { line(i, 50 + groove.left.get(i)50, i+1, 50 + groove.left.get(i+1)50); line(i, 150 + groove.right.get(i)50, i+1, 150 + groove.right.get(i+1)50); }
if (sceneNumber == 2) {
img = loadImage("xmas card.0.jpg");
image(img, 0, 0, 1440, 810);}
}
void mousePressed() {
textSize(60);
//stroke(0, 0, 0);
fill(255, 0, 0);
text("Marry Christmas", 550, 170);
text("Happy New Year", 550, 250);
}
class Ball { //define a new class called Ball color c; //define a color variable called c float xpos; float ypos; float xspeed; float yspeed; float diam;
Ball(color tempC, float tempxpos, float tempypos, float tempxspeed, float tempyspeed, float tempdiam) { //this is the constructor for the class c = tempC; //set the color value to be the color passed in from the attribute xpos = tempxpos; ypos = tempypos; xspeed = tempxspeed; yspeed = tempyspeed; diam = tempdiam; }
void displayAndMove() { noStroke(); fill(c); //set the fill value to the value of the colour variable ellipse(xpos, ypos, diam, diam); //define the ellipse: (x, y, width, height) xpos = xpos+xspeed; //move the ball in x ypos = ypos+yspeed; //move the ball in y if (xpos > width) { //detect the right and left edges of the screen xpos = 0; } if (ypos > height) { //detect the bottom and top edges of the screen ypos = 0; }
} //end of the displayAndMove function
} //end of the class definition
void keyPressed() { if ( key == '2' ) sceneNumber = 2; if ( key == '1' ) sceneNumber = 1; if ( key == 'p' ) sceneNumber = 2; { int d = day(); int m = month(); int h = hour(); int min= minute(); int s = second();
String days = String.valueOf(d);
String month = String.valueOf(m);
String hours = String.valueOf(h);
String minutes = String.valueOf(min);
String seconds = String.valueOf(s);
println(filename +"-" + days + "-" + month + "-"+ hours + "-"+ minutes+ "-" + seconds + ".jpg");
save(filename+ "-"+ days +"-" + month + "-"+ hours + "-" + minutes+"-" + seconds + ".jpg");
delay(1000);
background(255);
}
}
Adding Sound to a Object when it is clicked. (URGENT!!!)
Okay Guys! So, basically I want to be able to incorporate a 'Ding' sound using the minim library that is played every time the Target is hit, which in this case is our Saucer.png. The problem is not with registering a click on the saucer but rather being able to incorporate the code necessary so when the Target is hit, it will play the sound and then continue to do so everytime it is hit
Here is my code:
import ddf.minim.*;
int rad = 60; // Width of the shape
float xpos, ypos; // Starting position of shape
float xspeed = 2.0; // Speed of the shape
float yspeed = 2.0; // Speed of the shape
int xdirection = 1; // Left or Right
int ydirection = 1; // Top to Bottom
int score=0; //Inital score
int lives=5; //Number of lives you start with
boolean lost=false; //Have you lost yet?
int speed=1;
PImage bg;
PImage Target;
int y;
AudioPlayer player;
Minim minim;
void setup()
{
size(736,460);
minim = new Minim(this);
fill(255,255,255);
noStroke();
frameRate(60);
Target = loadImage("Saucer (1).png");
xpos = width/2; // Set the starting position of the shape
ypos = height/2;
bg = loadImage("space 2.jpg"); //Load Image (jpg,png,gif)
player = minim.loadFile("Song 1.mp3"); //Load Audio File (mp3,wav)
player.loop();
}
void draw()
{
background(bg);
image(Target,xpos,ypos,60,60);
xpos = xpos + ( xspeed * xdirection ); // Update the position of the shape
ypos = ypos + ( yspeed * ydirection );
if (xpos > width-rad || xpos < rad) { // Test to see if the shape exceeds the boundaries of the screen
// If it does, reverse its direction by multiplying by -1
xdirection *= -1;
}
if (ypos > height-rad || ypos < rad) {
ydirection *= -1;
}
text("score = "+score,10,10); //Print the score on the screen
text("lives = "+lives,width-80,10); //Print remaining lives
if (lives<=0) //Check to see if you lost
{
textSize(50);
text("Click to Restart", 450,200);
noLoop(); //Stop looping at the end of the draw function
lost=true;
textSize(13);
}
}
void mousePressed() //Runs whenever the mouse is pressed
{
if (dist(mouseX, mouseY, xpos, ypos)<=rad) //Did we hit the target?
{
score=score+speed; //Increase the speed
speed=speed+1; //Increase the Score
}
else //We missed
{
if (speed<1) //If speed is greater than 1 decrease the speed
{
speed=speed-1;
}
lives=lives-1; //Take away one life
}
if (lost==true) //If we lost the game, reset now and start over
{
speed=1; //Reset all variables to initial conditions
lives=5;
score=0;
xpos=width/2;
xdirection=1;
lost=false;
loop(); //Begin looping draw function again
}
}
Thank you to everyone that can help me, feel free to give me code or modify the code above as well as provide links to reference pages!
How to add a GIF into a code?
I added a gif into my code, but only shows up as a static image. How am I able to make the GIF animate?
Using gifs in processing
Hi,
Can anyone help me with how I'd insert a transparent .gif on on to my processing file? I've read on this website that the .gif library isn't supported on Processing 3 so surely there must be an alternative?
I want it layered above my background image.
New to the whole concept!
Thank you :)
The Video Library does not work on my laptop running El Capitan.
The is a warning message about something being depreciated. But there is a problem. The video starts, image and audio but then then audio cuts off.
setVisible
I have the following program creates cubes and changes them. I am trying to make the cubes invisible until they are activated in updatecells, but I want them part of my overall VBO that is created during setup to help performance. I have tried putting the "setVisible( false )" code in many places, but cannot seem to get it to work. I have tried making each side of the cubes invisible separately, and that did not work either. Any suggestions are welcome.
import processing.opengl.*;
import peasy.*;
PeasyCam cam;
PShape world;
float CS = .25;
int CPS = 10;
int totalcubes = CPS*CPS*CPS;
float offset = CPS/2;
color colors[]= {0x88FF0000,0x8800FF00,0x880000FF,0x88FFFF00,0x8800FFFF,0x88FF00FF};
int dice_orientations[][][]={{{1,6,2,4,5,3},{1,6,4,5,3,2},{1,6,5,3,2,4},{1,6,3,2,4,5}},
{{6,1,2,3,5,4},{6,1,3,5,4,2},{6,1,5,4,2,3},{1,6,4,2,3,5}},
{{3,4,5,6,2,1},{3,4,6,2,1,5},{3,4,2,1,5,6},{3,4,1,5,6,2}},
{{4,3,1,2,6,5},{4,3,2,6,5,1},{4,3,6,5,1,2},{4,3,5,1,2,6}},
{{2,5,4,6,3,1},{2,5,6,3,1,4},{2,5,3,1,4,6},{2,5,1,4,6,3}},
{{5,2,1,3,6,4},{5,2,3,6,4,1},{5,2,6,4,1,3},{5,2,4,1,3,6}}};
int rcolor;
void setup() {
size(2100,2100, P3D);
cam = new PeasyCam(this, 150*CPS);
noStroke();
print("Making World ");
world = createShape(GROUP);
for (int i = 0; i < CPS; i++) {
for (int j = 0; j < CPS; j++) {
for (int k = 0; k < CPS; k++) {
MyCube cube = new MyCube(i - offset, j - offset, k - offset);
world.addChild(cube.output);
}}print("-");}
println(" done");} // end setup
void draw() {
background(127);
scale(95);
shape(world, 0, 0);
updatecells();
} // end draw
void updatecells(){
PShape cube = world.getChild(int(random(totalcubes)));
color sidecolor;
int tempfront = int(random(6));
int temptop = int(random(4));
int tempside = 0;
for (int side=0; side < 6; side++) {
tempside=dice_orientations[tempfront][temptop][side];
sidecolor=colors[tempside-1];
for (int V=0; V < 4; V++) {
cube.setFill(side*4+V ,sidecolor);
} // end V
} // end side
} // end updatecells
// could just be a method, returning PShape
class MyCube {
PShape output;
MyCube(float x, float y, float z) { // <- new arguments
int size = 1;
output = createShape();
output.translate(x, y, z); // <- new tanslate
output.beginShape(QUADS);
output.fill(colors[0]);
output.vertex(-CS, CS, CS);output.vertex( CS, CS, CS);output.vertex( CS,-CS, CS);output.vertex(-CS,-CS, CS);
output.fill(colors[1]);
output.vertex( CS, CS, CS);output.vertex( CS, CS,-CS);output.vertex( CS,-CS,-CS);output.vertex( CS,-CS, CS);
output.fill(colors[2]);
output.vertex( CS, CS,-CS);output.vertex(-CS, CS,-CS);output.vertex(-CS,-CS,-CS);output.vertex( CS,-CS,-CS);
output.fill(colors[3]);
output.vertex(-CS, CS,-CS);output.vertex(-CS, CS, CS);output.vertex(-CS,-CS, CS);output.vertex(-CS,-CS,-CS);
output.fill(colors[4]);
output.vertex(-CS, CS,-CS);output.vertex( CS, CS,-CS);output.vertex( CS, CS, CS);output.vertex(-CS, CS, CS);
output.fill(colors[5]);
output.vertex(-CS,-CS,-CS);output.vertex( CS,-CS,-CS);output.vertex( CS,-CS, CS);output.vertex(-CS,-CS, CS);
output.setVisible( false );
output.endShape(CLOSE);
} // end constructor
}// end MyCube
video library processing 3.2.1 bug
Hello, Here is my problem, I installed the video library for processing ("GStreamer-based video library for Processing") yesterday, but it isn't working. When I run any examples (here it's about the "Loop" example), I've got this bug : " A library used by this sketch is not installed properly. A library relies on native code that's not available. Or only works properly when the sketch is run as a 32-bit application. " I also tried to run it with a 32-bit version, it doesn't change anything. Is anybody has an idea ?
What does beat and fft means?
I'm currently having a hard time to understand the both of these. Can anyone explain to me in a more simple yet understandable way??
controlP5 : changing color of bang, button, sliders.
How to change the colors of bang, button and sliders? TIA.
my for-loop skips a position
i tried to adjust a slit scan video code to move the copy command from left to right through the video. that works, but in the output it skips a position, leaving a white strip between. how can i make the output dense?
import processing.video.*;
Movie myMovie;
int pos;
int sliceSize = 5;
int outputcounter= 1;
String date;
void setup() {
size(5000, 720);
myMovie = new Movie(this, "versuch1.mp4");
myMovie.loop();
pos = 0;
date = timestamp();
//myMovie.jump(176);
}
void draw() {
if (myMovie.available()) {
myMovie.read();
pushMatrix();
for (int i=0; i<1280; i+= sliceSize){
//translate(width/2, height/2);
//rotate(HALF_PI);
//translate(-width/2, -height/2);
//tint(255, 20);
copy(myMovie, i, 0, sliceSize, myMovie.height, pos, 0, sliceSize, height); //(copy (quelle, x , y, breite, höhe, position im neuen bild, ))
scale(-1,1);
pos+=sliceSize*i; //horizontal gefilmt
//copy(myMovie, 0, myMovie.height/2, myMovie.width, sliceSize, 0, pos, width, sliceSize); //vertical gefilmt
//pos-=sliceSize;
if (pos>width) {
saveFrame("png/"+ date+"/"+nf(outputcounter,3)+".png");
outputcounter++;
pos = 0;
}
}
//image(myMovie, 0,0,960,540);}
popMatrix();
}
}
// Called every time a new frame is available to read
/**void movieEvent(Movie m) {
m.read();
}*/
void keyPressed() {
if (key == 32) {
saveFrame("png/output_"+timestamp()+".png");
}
}
String timestamp() {
return new java.text.SimpleDateFormat("yyyy_MM_dd_kkmmss").format(new java.util.Date ());
}
//webseite 100vh quadrat (3/4=133) png= 001.png, 002.png
Create an Image Mask On Top of a Live Feed
Hey all!
So for this code I'm trying to create a code that will use a live webcam feed and face tracking to put an image on top of the tracked face. After this point, I want to press a key ('n' in the code I posted below) and have it switch to a different picture. Right now as a base code I have processing's "LiveFaceTracking" example in my code. Any help you guys could give me would be greatly appreciated!
import gab.opencv.*;
import processing.video.*;
import java.awt.*;
PImage WD;
PImage GJ;
Capture video;
OpenCV opencv;
void setup() {
size(640, 480);
video = new Capture(this, 640/2, 480/2);
opencv = new OpenCV(this, 640/2, 480/2);
opencv.loadCascade(OpenCV.CASCADE_FRONTALFACE);
video.start();
loadImage("WD");
loadImage("GJ");
}
void draw() {
scale(2);
opencv.loadImage(video);
image(video, 0, 0 );
noFill();
stroke(0, 255, 0);
strokeWeight(3);
Rectangle[] faces = opencv.detect();
println(faces.length);
for (int i = 0; i < faces.length; i++) {
println(faces[i].x + "," + faces[i].y);
rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
}
}
void captureEvent(Capture c) {
c.read();
}
void keyPressed(){
if(key = 'n'){
loadImage = WD;
Editing vectors
Is there any library which will allow mouse editing of 2D vector-based shapes in a Processing sketch?
Something that will take care of handles, drag/drop, rubber banding etc.
Same Capture stream in two PApplet frames
Hello, I'd like to ask for your help.
I'm working on a Processing sketch running two frames (via runSketch() ). In the main PApplet I'm showing and filtering, with a GLSL shader, a Capture object. I'd like to see the same Capture stream in the second PApplet, unfiltered, using it as a "system monitor", and launch PApplet 1 on projector and PApplet 2 on Macbook display.
As fai as I can go, I'm referencing the Capture obj from the main PApplet in the second. if I call image(Capture,0,0) I'm just able to see the first captured frame from the webcam. To actually see the frames updating, I gotta call image(Capture.copy(),0,0); but also if the PApplet framerate doesn't drop, I can see a frame drop in the two sketches.
This doesn't happen if I call two times image(Capture,0,0) in the main PApplet. Framerate of PApplet and Capture stays up.
Any hints?
Thank you.
Channel Shifting Video
Is it possible to shift the rgb channels of camera horizontally in realtime? In other words, I would like to make a normal video like this:
look like this:

I plan on making the red and blue channels move according to the volume of a microphone input while the green one stays in place. I don't know where to start as far as the channel shifting besides importing the video library, although I've found scripts on channel shifting for images. I was thinking that I could have three different outputs for the camera, each being a different channel, so that it would be easier to shift them, but I'd still have to know how to extract the channel from each one. Thanks!
Multiple Cameras
Hi, I'm making a 3d proyect, and I want to have two differents cameras simultaneously, camera A in the left, and camera B in the right, having differents points of view of the same scene. It's posible? How can I make it? Thanks!
How to use video to create music...
Sorry I'm new to programming but I've searched the forums and generally online, with no useful answer to this... I can get videos playing and have managed to use other peoples shared games and generative code to input midi into Logic and record... I'm just having trouble combining the two.
So... how would I go about using light information such as brightness of a video to influence midi note on/off... would anyone share such code with me?
Any info would be greatly appreciated! sorry if this seems obvious to you.
Thanks,
bmz