/r/processing
“Processing is a flexible software sketchbook and a language for learning how to code within the context of the visual arts. Since 2001, Processing has promoted software literacy within the visual arts and visual literacy within technology. There are tens of thousands of students, artists, designers, researchers, and hobbyists who use Processing for learning and prototyping.”—from Processing.org
Share your projects, news and questions about Processing or Processing.js here.
(open to suggestions)
/r/processing
I am making a game on Processing 4.3, and a part of the game is that I want to be able to pick up an object with the mouse and drag it. So far I can't seem to make the mouse pick up an object because of how my code has it so that when the mouse is pressed within the area, it hides the original circle and makes a new one at the mouseX and mouseY. Please suggest how I can fix my code to do this. Thank You!
void setup () {
size(1000,900);
background(0);
}
void draw() {
fill(255);
ellipse(100,100,100,100);
drag();
}
void drag() {
if(mousePressed == true && mouseX > 100 && mouseX < 100 && mouseY > 100 && mouseY < 100) {
fill(0);
ellipse(100,100,100,100);
fill(0,0,255);
ellipse(mouseX,mouseY,100,100);
}
}
Hey folks! I'm trying to upload a game I made into a standalone executable to add to an itch page. But for whatever reason, even though i followed the export application process and clicked embed java, the exe can still not be run without downloading java. It comes up with the error: "This application requires a Java Runtime Environment 17". This is my first time trying to export a processing exe in particular, so maybe I'm missing something obvious on how to do this. But could anyone tell me what I'm doing wrong, or how to fix this? It's not an issue with the update either since i've had this issue since before the update.
Thank you all in advance!!
I need to open a project that ran on p3, but when trying to open in p4, it says I “You must first install PDE X to use this sketch”.
I don’t remember if there was anything special about the sketch. In my mind it should run fine in P4. I basically just want to open it, save as a new p4 sketch and start making changes.
What’s the best way around this? I can also note that there’s nothing called PDE X in the contributions manager as far as I can tell.
Make a new sketch and copy code over via notepad?
EDIT: SOLVED! I found a properties file with “experimental mode” stuff in it. Could open and run after removing that.
Hi everyone, poo brain newbie here. Whenever I try run this sketch, I can't, to put it simply. Does anyone know where I'm going wrong/ how I could fix? The code is taken from a book 'getting started with arduino' and the only thing ive added is the import tags as newer processor versions dont seem to work well with arduino. Any response appreciated!
// Example 08A: Arduino networked lamp
// parts of the code are inspired
// by a blog post by Tod E. Kurt (todbot.com)
//
// Copy and paste this example into an empty Processing sketch
import processing.serial.*;
import java.net.URL;
import java.net.URLConnection;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
String feed = "http://blog.makezine.com/index.xml";
int interval = 10; // retrieve feed every 60 seconds;
int lastTime; // the last time we fetched the content
int love = 0;
int peace = 0;
int arduino = 0;
int light = 0; // light level measured by the lamp
Serial port;
color c;
String cs;
String buffer = ""; // Accumulates characters coming from Arduino
PFont font;
void setup() {
size(640,480);
frameRate(10); // we don't need fast updates
font = loadFont("HelveticaNeue-Bold-32.vlw");
fill(255);
textFont(font, 32);
// IMPORTANT NOTE:
// The first serial port retrieved by Serial.list()
// should be your Arduino. If not, uncomment the next
// line by deleting the // before it, and re-run the
// sketch to see a list of serial ports. Then, change
// the 0 in between [ and ] to the number of the port
// that your Arduino is connected to.
//println(Serial.list());
String arduinoPort = Serial.list()[0];
port = new Serial(this, arduinoPort, 9600); // connect to Arduino
lastTime = 0;
fetchData();
}
void draw() {
background( c );
int n = (interval - ((millis()-lastTime)/1000));
// Build a colour based on the 3 values
c = color(peace, love, arduino);
cs = "#" + hex(c,6); // Prepare a string to be sent to Arduino
text("Arduino Networked Lamp", 10,40);
text("Reading feed:", 10, 100);
text(feed, 10, 140);
text("Next update in "+ n + " seconds",10,450);
text("peace" ,10,200);
text(" " + peace, 130, 200);
rect(200,172, peace, 28);
text("love ",10,240);
text(" " + love, 130, 240);
rect(200,212, love, 28);
text("arduino ",10,280);
text(" " + arduino, 130, 280);
rect(200,252, arduino, 28);
// write the colour string to the screen
text("sending", 10, 340);
text(cs, 200,340);
text("light level", 10, 380);
rect(200, 352,light/10.23,28); // this turns 1023 into 100
if (n <= 0) {
fetchData();
lastTime = millis();
}
port.write(cs); // send data to Arduino
if (port.available() > 0) { // check if there is data waiting
int inByte = port.read(); // read one byte
if (inByte != 10) { // if byte is not newline
buffer = buffer + char(inByte); // just add it to the buffer
}
else {
// newline reached, let's process the data
if (buffer.length() > 1) { // make sure there is enough data
// chop off the last character, it's a carriage return
// (a carriage return is the character at the end of a
// line of text)
buffer = buffer.substring(0,buffer.length() -1);
// turn the buffer from string into an integer number
light = int(buffer);
// clean the buffer for the next read cycle
buffer = "";
// We're likely falling behind in taking readings
// from Arduino. So let's clear the backlog of
// incoming sensor readings so the next reading is
// up-to-date.
port.clear();
}
}
}
}
void fetchData() {
// we use these strings to parse the feed
String data;
String chunk;
// zero the counters
love = 0;
peace = 0;
arduino = 0;
try {
URL url = new URL(feed); // An object to represent the URL
// prepare a connection
URLConnection conn = url.openConnection();
conn.connect(); // now connect to the Website
// this is a bit of virtual plumbing as we connect
// the data coming from the connection to a buffered
// reader that reads the data one line at a time.
BufferedReader in = new
BufferedReader(new InputStreamReader(conn.getInputStream()));
// read each line from the feed
while ((data = in.readLine()) != null) {
StringTokenizer st =
new StringTokenizer(data,"\"<>,.()[] ");// break it down
while (st.hasMoreTokens()) {
// each chunk of data is made lowercase
chunk= st.nextToken().toLowerCase() ;
if (chunk.indexOf("love") >= 0 ) // found "love"?
love++; // increment love by 1
if (chunk.indexOf("peace") >= 0) // found "peace"?
peace++; // increment peace by 1
if (chunk.indexOf("arduino") >= 0) // found "arduino"?
arduino++; // increment arduino by 1
}
}
// Set 64 to be the maximum number of references we care about.
if (peace > 64) peace = 64;
if (love > 64) love = 64;
if (arduino > 64) arduino = 64;
peace = peace * 4; // multiply by 4 so that the max is 255,
love = love * 4; // which comes in handy when building a
arduino = arduino * 4; // colour that is made of 4 bytes (ARGB)
}
catch (Exception ex) { // If there was an error, stop the sketch
ex.printStackTrace();
System.out.println("ERROR: "+ex.getMessage());
}
}
I have experimented with processing over the years, but mostly by creating objects from shapes and animating them. Now I would like to create a slow slideshow where one image transitions to the next image one pixel at a time. Is this something I can do with processing? I may actually want to do more than 1 pixel at a time, and I want to fiddle with the timing considering a 4k image would need to change 8,294,400 pixels. But generally speaking, is this something that would be fairly straightforward in processing?
Hey all, I’m looking for resources or example code that show how one would go about making a 3rd person “flight” controller. I’m looking to fly around some generated terrain and don’t know where to start on the thing that’s actually flying. This seems like something that would have been built many times in the past so I’m hoping there’s a best practice for this sort of controller.
I’m not looking for anything realistic or overly complicated, more arcade game than flight sim.
Any ideas help!
Hello there, I am relativly new to Proccessing and programming in general as IT/programming are my main courses in school. We have to make a mini 2d game as a 2 person project but unfortunatly my partner knows even less than me. (We are allowed the use of external help/assistance)
My game is basically where a circle/the player collects tokens while dodging falling stars(images). Each token collected should add a 5 point to the highscore. If hit by star game ends. I'm struggling to find tips/tutorials on these things: 1. randomly generated (reapearing?) object (similair with the Snake; 2. image and object collision (I have an idea but idk how to implement it); 3. highscore number displayed and goes up (when token is collected); and ig 4. game stops (but like you can restart it?)
I apologize for asking this on such a short notice, I have until tomorrow to compleat this. (roughly 18-20h) Thank you for reading and sparing me some of your time anyway. o(〃^▽^〃)o
I am trying to create an app for on my phone to be able to scan a nfc tag and based on the nfc tag make an image pop up. However, everything i have tried hasnt worked at all! I am at a loss, every library regarding this is not up to date or broken. Most codes are not working or when i change a single thing everything brakes. Can someone help? Or has anyone made something similar?
Edit: nvm, figured it out. Geniusses put 100 white lines to start off an external file basically: "hey this is the wrong file", 100x whitelines, actual code....
I am teaching class for 12 ish year olds on starter programming, via an external organisation.
My organisation has setup this entire curriculum i am to cover, teaching them game design. Drawing stuff, mouse and keyboard inputs, collisions etc.
Now, this school has its students use chromebooks so the regular environment hasnt worked, whole thing, found one online, cool.
However, they have opted to simplify some things using (what I'm guessing are) custom functions. One of these is for collisions. My best guess is that it is sketching a hitbox and checking if it is hitting a colour. For a circle as follows:
Collision("ellipse", x, y, width, heigth, colour)
Im guessing this function is custom as the actual name of the function in the code is in dutch.
Now, i only really have experience with python, this project was internally advertised as needing minimal programming experience, which I already disagree with. I cannot find a declaration for this function anywhere to implement it in class, any pointers are welcome.
for some context Im a hs student trying to make a chess game in processing(java version) that allows user to play an ai im allowed to use a ready made chess ai is it possible for me to add the Leela chess ai to my sketch?https://lczero.org/play/quickstart/ the site if you want to look into it
Hi! I was working on a project on my Linux mint system and was getting weird data from the official processing audio library. I fired up the Audio Waveform example and it only plays about the first half a second of sound then freezes. The Keyboard example has no audio but the visuals do continue working so the issue appears to be the sound library and not the whole environment.
Anyone have any ideas?
Hiiiiii,
Im super beginner to this so my apologies if this is unclear!
Im making a virtual 'desk', and on the desk is a laptop which has photos you can click through using the arrow keys.
behind the laptop is a window and im trying to have rainy foggy day in the back. This issue i'm running into is when i run the rain code, the rain is appearing in front of my loaded images. Is there a way to make the images hold in front of the rain code?
thank you in advance :)
Edit:
My rain code is written as a for loop and placed at the very beginning of my Draw function.
Ive tried keyPressed() as a function, and as a variable ( set at the very end of my draw function).
Im assuming because the for loop is continuous, and my keyPressed only runs once, the rain will continues to cover the image. Is there a way to ensure the rains stays behind the image while it continues to run>
I'm looking for a way forward regarding the use of points. I want to be able to generate a few thousand spherical shaped objects in a 3D space and have them all move separately from each other. I started this process using Spheres, but could only get the performance I wanted by scaling the Sphere Detail value down to 1, and this doesn't look great.
By switching from Spheres to Points, I got a huge boost in performance. The issue I am having now is with the way points seem to be implemented. I want my objects to respond to distance correctly, meaning the farther they are from the camera, the smaller they should be. Points seem to be drawn to the screen the same size no matter what their actual coordinates are in space.
Here is an example of the scene using Spheres, notice how their size scales with distance:
And here is the same scene using points - notice how the farther away points stay the same size and end up looking blurry/crowded:
Is there a way to get around this aspect of drawing points to the screen? Is there a way to get better performance out of Spheres?
Hello! Currently animating a WASD sprite for a class project. I've reached a point where my program crashes and says "ArrayIndexOutOfBoundsException: Index 3 out of bounds for length 3"
I understand that I am trying to access a nonexistent part of an array somewhere... but I don't see where. Can someone help? Project linked:
https://drive.google.com/drive/folders/1aG3hmvwM3RyHqO-mGtnx5kGQre530Wqu?usp=sharing
I made two versions one for singleplayer and another for multiplayer, there are instructions on how to run them if you're interested :)).
I have some processing code would like to post but it is 524 lines long. How do I share it? Do I create it as a zip file and post it here like that? Copy paste it in markdown mode?
Hi,
I was looking into exporting below code output (not mine, not a programmer) into SVG.
Is there a simple way to do this?
Title. I'm using a surface pro 8 and trying to get processing to access my camera. I go through everything right, my code has no syntax errors. I've got the video and OpenCV libraries downloaded. I've even tried reinstalling both processing and Windows 11 on my PC. Still no luck.
Here's the code-
import processing.video.*;
import gab.opencv.*;
Capture cam;
OpenCV opencv;
void setup() {
size(640, 480);
cam = new Capture(this, 640, 480);
opencv = new OpenCV(this, cam.width, cam.height);
cam.start();
}
void draw() {
if (cam.available() == true) {
cam.read();
image(cam, 0, 0);
opencv.loadImage(cam);
// Your OpenCV processing here
}
}
//
Regardless, I always get the same two error messages-
BaseSrc: [ksvideosrc0] : failed to start capture (0x00000020)
BaseSrc: [ksvideosrc0] : Internal data stream error.
Please help me. I've even asked my college professor and even he was unable to find a solution.
I have a 3d shape that is getting drawn into a P3D context, created with:
PShape shape= p.createShape(PShape.GEOMETRY);
shape.beginShape(PConstants.QUADS);
... define vertices with uv values...
shape.endShape();
I have found that shape.setTextureUV() will successfully change the uv values of my defined vertices, but only if called before the shape has ever been drawn using e.g. shape.draw(myPGraphics) or myPGraphics.shape(shape).
Interestingly, shape.setVertex() does work correctly after being drawn.
I was thinking perhaps this is due to the shape data being sent to the graphics card and needing to be updated, but I can't find anything in PShape or PGraphics that would seem to pertain to this (at least in the public interfaces). Am I missing something?
Update: I've found it works only when I call the function between shape.beginTessellation() and shape.endTessellation(), but it's as yet unclear why as that function is poorly documented.
Update2: Additionally, this tesselation step seems to be throwing off the UV numbering after several thousand quads.
Update3: If anyone else comes across this with a similar issue, it does seem to be based on amount of geometry in the PShape, I was able to avoid the UV numbering issue by grouping multiple PShapes together and ensuring each had less than 16383 (0x3FFF) quads, for whatever reason that was the cutoff.
so if i want to re-create the pac-man maze... how can i do that? like whats the easiest way of doing it? (ignoring the speed that a program might take)