Unexpected token: void error
in
Programming Questions
•
8 months ago
I am getting this error and I have looked at other posts with the same error but the solutions dont seem to apply to my code.
Hope some one can help
////////////////////////////////// Display ///////////////////////////////////////////
import processing.serial.*;
Serial peggyPort;
PImage peggyImage = new PImage(16, 16);
byte [] peggyHeader = new byte[]
{
(byte)0xde, (byte)0xad, (byte)0xbe, (byte)0xef, 1, 0
};
byte [] peggyFrame = new byte[8*16];
////////////////////////////////// END DISPLAY ////////////////////////////////////////
import oscP5.*;
import netP5.*;
OscP5 oscP5Connect;
NetAddress sendingLocation;
int savedTime;
int totalTime = 5000;
int num_drops = 400;
Drop[] myDrops = new Drop[num_drops];
/////////////////////////////////////////////////////////////////////////////////////
void setup()
{
////////////////////////////////// Display ///////////////////////////////////////////
peggyPort = new Serial(this, "/dev/tty.usbmodemfa131", 115200); // CHANGE_HERE
////////////////////////////////// Display ///////////////////////////////////////////
size(500, 500);
smooth();
noStroke();
savedTime = millis();
////////////////////////////////// OSC SET PORT AND HOST ////////////////////////////
// start oscP5, telling it to listen for incoming messages at port 5000 */
oscP5Connect = new OscP5(this,5000);
// set the remote location to be the localhost on port 5000
sendingLocation = new NetAddress("127.0.0.1",5001);
///////////////////////////////// END OSC SET PORT AND HOST//////////////////////////
////////////////////////////////// RAIN POPULATION //////////////////////////////////
for (int i = 0; i<num_drops; i++)
{
myDrops[i] = new Drop();
myDrops[i].posX = random(0, width);
myDrops[i].posY = random(0, height);
myDrops[i].speedX = random(0, 3);
}
}
////////////////////////////////// END RAIN POPULATION //////////////////////////////////
void draw() {
background(0);
int passedTime = millis() - savedTime;
rainMaker();
if (passedTime < totalTime) {
for (int i = 0; i<num_drops; i++)
{
myDrops[i].update();
}
}
else {
stoptRainMaker();
savedTime = millis(); // Save the current time to restart the timer!
}
////////////////////////////////// Display ///////////////////////////////////////////
renderToPeggy(grabDisplay());
////////////////////////////////// END Display ///////////////////////////////////////
}
////////////////////////////////// RAIN FUNCTION //////////////////////////////////
void startRainMaker() {
////////////////////////////////// OSC SEND MESSAGE ////////////////////////////////
OscMessage messageToSendToPd;
messageToSendToPd = new OscMessage("/play");
messageToSendToPd.add(1);
oscP5Connect.send(messageToSendToPd, sendingLocation);
////////////////////////////////// END OSC SEND MESSAGE /////////////////////////////
for (int i = 0; i<num_drops; i++)
{
myDrops[i].update();
}
}
////////////////////////////////// END RAIN FUNCTION ////////////////////////////////
void stoptRainMaker() {
////////////////////////////////// OSC SEND MESSAGE ////////////////////////////////
OscMessage messageToSendToPd;
messageToSendToPd = new OscMessage("/play");
messageToSendToPd.add(0);
oscP5Connect.send(messageToSendToPd, sendingLocation);
////////////////////////////////// END OSC SEND MESSAGE /////////////////////////////
////////////////////////////////// RAIN CLASS ///////////////////////////////////////
class Drop
{
//properties
int myDiameter = 4;
float posX = 250;
float posY = 250;
float speedX = 0.1;
float speedY = 0;
float gravity = 0.05;
//method
void update()
{
//ellipse(posX, posY, myDiameter, myDiameter);
fill(#62B7FF, 200);
ellipse(posY, posX, myDiameter, myDiameter);
posX += speedX + 0.01;
speedX = speedX + gravity;
if (posX > width)
{
posX = 0;
speedX = speedX*-.10;
}
}
}
////////////////////////////////// END RAIN CLASS ///////////////////////////////////
////////////////////////////////// Display ///////////////////////////////////////////
// render a PImage to the Peggy by transmitting it serially.
// If it is not already sized to 25x25, this method will
// create a downsized version to send...
// render a PImage to the Peggy by transmitting it serially.
// If it is not already sized to 25x25, this method will
// create a downsized version to send...
void renderToPeggy(PImage srcImg)
{
int idx = 0;
PImage destImg = peggyImage;
if (srcImg.width != 16 || srcImg.height != 16)
destImg.copy(srcImg,0,0,srcImg.width,srcImg.height,
0,0,destImg.width,destImg.height);
else
destImg = srcImg;
// iterate over the image, pull out pixels and
// build an array to serialize to the peggy
for (int y =0; y < 16; y++)
{
byte val = 0;
for (int x=0; x < 16; x++)
{
color c = destImg.get(x,y);
int br = ((int)brightness(c))>>4;
if (x % 2 ==0)
val = (byte)((br<<4));
else
{
val = (byte) ((br)|val);
peggyFrame[idx++]= val;
}
}
}
// send the header, followed by the frame
peggyPort.write(peggyHeader);
peggyPort.write(peggyFrame);
}
// this method creates a PImage that is a copy
// of the current processing display.
PImage grabDisplay()
{
PImage img = createImage(width, height, ARGB);
loadPixels();
arraycopy(pixels, 0, img.pixels, 0, width * height);
return img;
}
////////////////////////////////// END Display ////////////////////////////////
1