Just wanted to document an issue and fix I discovered today with Android and JSON parsing.
It seems the processing version of JSONObject library does not play nicely with Android, and worst of all it overwrites the usage of the JSONObject class. If you try to import the built in Android JSON library (as far as I understand it to be), org.json.* or org.json.JSONObject then an error is thrown with 2 versions of JSONObject. If you rely on just the processing.data.JSONObject then it crashes Android. This gave me hours of headaches, until I realized that I could prefix the JSONObject with org.json so that it forces the usage of the Android version of JSONObject. I had to change my code in order for it to work, but in the end it is all working.
I was trying this:
JSONObject json = new JSONObject(result);
^ This yielded an error that JSONObject in processing.data.JSONObject is protected access. This is troublesome because that syntax is suggested in all Java forums.
In order to compile, I changed it to this:
JSONObject json = JSONObject.parse(result);
^ This would compile, but throw an error in Android Logcat saying something about processing.data.JSONObject not existing.
In the end I did this:
org.json.JSONObject = new org.json.JSONObject(result);
^ This works.
I'm not sure where the fundamental issues are arising, Processing version, Android version, etc. But I wanted to document it in case someone else got stuck by this.
Hi all. I am having what appears to be a strange bug, but I'm sure I'm doing something stupid.
I have a "HeatPoint" class which is basically a point that is assigned a color value. From that color value I am creating a fading circle around that point if a pixel is within a certain distances from the point. Essentially I want to draw a heatmap, which I'm still wrapping my head around. To fade, I am just mapping my min/max distance onto an alpha value and drawing a square 8 pixel width/height) as my 'pixels' for a fading circle. The problem is that when there are multiple HeatPoint objects, the alpha channels for the fading circle are rendering as black.
Attached is a screenshot. The HeatPoint is being drawn as a 200x200 ellipse and you can see the fading circle behind it. There are 2 in the screenshot.
I would actually love to do this by coloring the pixel[] array, but alpha seems to get completely ignored. I have searched the forums with nothing that solves my issue.
I appreciate any help you have to offer. Code below:
int numHeatPoints = 2;
HeatPoint[] heatPoints = new HeatPoint[numHeatPoints];
void setup(){
size(1280,800);
smooth();
for(int i=0;i<numHeatPoints;i++){
heatPoints[i] = new HeatPoint(random(0,width),random(0,height));
Hello, I am trying to do something that I'm sure has been done before but I don't really know how to phrase it.
If I have a series of overlapping squares, how can I find the outer polyline that fits overlapping shapes? The red lines are the squares and the black lines is the "exterior bounding shape".
I should mention, I am trying to do this without a library because I need to write it for the web using processing.js. So unless there is a library that has been ported for js from processng or a javascript library anyone is aware of, I need to write it from scratch.
I have tried to test if a squares vertex is inside another square, and if it is not then add it to an arraylist of "exterior points" but this misses intersections at the exterior and also ordering is all messed up. I will keep hacking at this but I figured someone here may have experience with it.
Here is what I have so far:
Here is the code:
int regionDistance = 200;
Square[] squares = new Square[5];
ArrayList<PVector> boundingPoints = new ArrayList<PVector>();
void setup(){
size(800,600);
smooth();
for(int i=0;i<squares.length;i++){
squares[i] = new Square(random(0+regionDistance/2,width-regionDistance/2),random(0+regionDistance/2,height-regionDistance/2));
Hey all, I am trying to figure out how to draw a Black and White Image and then have circles overlay which will contain the colored part of the image. Imagine an BW image of a person but a circle drawn over their face which makes their face the only part that is colored.
I have been looking at the "mask()" function as well as "breakShape()" with no success. I think I can do it by drawing the image multiple times as a texture map but this will be very slow I think and I want to avoid using the image multiple times.
Hello, I am having some issues that I cannot figure out. I tried posting on the Arduino forums, but they suggested posting here instead.
I have an Arduino Uno (the basic one) and am running this code:
Arduino:
void setup(){
Serial.begin(9600);
}
void loop(){
float a = -4.56789;
a /= random(10);
Serial.println(a, 5);
delay(500);
}
Processing:
import processing.serial.*;
Serial myPort;
float value;
void setup()
{
myPort = new Serial(this, Serial.list()[0], 9600);
}
void draw()
{
}
void serialEvent(Serial p) {
// get message till line break (ASCII > 13)
String message = myPort.readStringUntil(13);
if(message != null){
value = float(message);
println(value);
}
}
This works fine. Processing will print the float coming in from Arduino/Serial. I have also tried uploading StandardFirmata to the Uno board and then running a Processing sketch with Serial/Arduino libraries which also worked fine.
I then unplug my Uno board and plug in my new Arduino Micro board in, upload the Arduino code, and run the Processing code. It is strange because there are no errors or anything, it just reacts as if there are no SerialEvents at all. Just nothing happens. I can print to the console Serial.list() and the correct port comes up, but nothing is read on Processing's side from Arduino.
I cannot figure out why this would be. Anyone have any ideas?
Hello, I am using Sonia (yes I know, it is quite old at this point) and I am unable to save a recording sample.
I call the mySample.saveFile("filename") and it does not do anything.
I am using Sonia for simplicity reasons and volume control (Minim volume control is almost unusable). Not being able to save a recording is seriously dampening me though.
Any ideas? I have searched the forums, but there seems to be no real answer out there yet.
Hi, I am using minim to record different loops from microphones.
A sound is recorded directly to a file for a certain period of time (not a buffer), and then when it is done recording, a player then plays that file. And the process continues for a length of time.
I am doing some audio processing -> such as fades and some granular synthesis with the recorded files.
I am wondering, how can I record the synthesized output as one large file? Record/save for the length the program is running for.
I'm wondering if it is possible to import a jpg to processing (of a waveform) and somehow translate the "waveform" to audio, basically the opposite of generating a waveform from audio.