Category Archives: processing

BufferedImage class does not exist

i am trying to use robot.createScreenCapture and it returns a bufferedimage but when i try to create a bufferedimage variable it says

"the class Bufferedimage does not exist" how can i fix this?

code:

import java.awt.*; Rectangle screenrect; BufferedImage screenimg; Robot robot; void setup(){ screenrect=new Rectangle(100,100,100,100); try { robot = new Robot(); robot.setAutoDelay(0); } catch (Exception e) { } } void draw(){ screenimg=robot.createScreenCapture(screenrect); } 
submitted by /u/jgvpfmbsqwrbk
[link] [comments]

Why is my module inspector changing the color of the cubes?

boolean square = true;

int squuu = 0; //color

color[] colorlist = {#065F4A, #48599B, #933445, #AA395D, #484545};

float rotation = 0; //rotation

void setup () {

size (1200, 600, P3D);

}

void draw() {

background(0);

camera(mouseX, mouseY, mouseY / tan(PI/35), mouseX, height/2, 0, 0, 1, 0);

noFill();

strokeWeight(12);

pushMatrix();

translate(200,200,90);

if (keyPressed){

if (key == 'b'){

rotateY(radians(rotation));

rotateX(radians(rotation));

}

}

for (int i = 50; i <= 2000; i=i+50) {

box(i);

stroke(colorlist[squuu]);

squuu=(squuu+1)%5;

}

popMatrix();

rotation = rotation+1;

}

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

Can not download anything from the PDE "Contributions Library Manager"

I can not download anything from the PDE "Contributions Library Manager".

I am using Processing 3.5.3 in Java mode on Windows 10 Pro Version 1709 Build 16299.1127

A pink colored text box appears on the Contributions Library Manager screen with the following error message:

---------------------------------------------------------------------------

Could not connect to the Processing Server.

Contributions cannot be installed or updated without an Internet connection.

Please verify your network connection again, then try connecting later.

----------------------------------------------------------------------------

This is what is output to the console:

java.net.SocketException: Address family not supported by protocol family: connect

at java.net.DualStackPlainSocketImpl.connect0(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect([DualStackPlainSocketImpl.java:83](https://DualStackPlainSocketImpl.java:83)) at java.net.AbstractPlainSocketImpl.doConnect([AbstractPlainSocketImpl.java:350](https://AbstractPlainSocketImpl.java:350)) at java.net.AbstractPlainSocketImpl.connectToAddress([AbstractPlainSocketImpl.java:206](https://AbstractPlainSocketImpl.java:206)) at java.net.AbstractPlainSocketImpl.connect([AbstractPlainSocketImpl.java:188](https://AbstractPlainSocketImpl.java:188)) at java.net.PlainSocketImpl.connect([PlainSocketImpl.java:172](https://PlainSocketImpl.java:172)) at java.net.SocksSocketImpl.connect([SocksSocketImpl.java:392](https://SocksSocketImpl.java:392)) at java.net.Socket.connect([Socket.java:589](https://Socket.java:589)) at sun.net.NetworkClient.doConnect([NetworkClient.java:175](https://NetworkClient.java:175)) at sun.net.www.http.HttpClient.openServer([HttpClient.java:463](https://HttpClient.java:463)) at sun.net.www.http.HttpClient.openServer([HttpClient.java:558](https://HttpClient.java:558)) at sun.net.www.http.HttpClient.<init>([HttpClient.java:242](https://HttpClient.java:242)) at [sun.net.www.http.HttpClient.New](https://sun.net.www.http.HttpClient.New)([HttpClient.java:339](https://HttpClient.java:339)) at [sun.net.www.http.HttpClient.New](https://sun.net.www.http.HttpClient.New)([HttpClient.java:357](https://HttpClient.java:357)) at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient([HttpURLConnection.java:1220](https://HttpURLConnection.java:1220)) at sun.net.www.protocol.http.HttpURLConnection.plainConnect0([HttpURLConnection.java:1156](https://HttpURLConnection.java:1156)) at sun.net.www.protocol.http.HttpURLConnection.plainConnect([HttpURLConnection.java:1050](https://HttpURLConnection.java:1050)) at sun.net.www.protocol.http.HttpURLConnection.connect([HttpURLConnection.java:984](https://HttpURLConnection.java:984)) at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0([HttpURLConnection.java:1334](https://HttpURLConnection.java:1334)) at sun.net.www.protocol.http.HttpURLConnection.getOutputStream([HttpURLConnection.java:1309](https://HttpURLConnection.java:1309)) at [processing.app.contrib.ContributionManager.download](https://processing.app.contrib.ContributionManager.download)([ContributionManager.java:82](https://ContributionManager.java:82)) at [processing.app.contrib.ContributionListing$1.run](https://processing.app.contrib.ContributionListing$1.run)([ContributionListing.java:385](https://ContributionListing.java:385)) at [java.lang.Thread.run](https://java.lang.Thread.run)([Thread.java:748](https://Thread.java:748)) 
submitted by /u/IMbob303
[link] [comments]

How to change from mousePressed to a button on Arduino

Hi, this is the code I'm working on, which changes every time the mouse is pressed. Now, I want to change the mouse to a button, but I can't seem to do it. It works when I draw a simple sketch in Processing:

import processing.serial.*; Serial myPort; int val; void setup() { size(200, 200); String portName = Serial.list()[1]; myPort = new Serial(this, portName, 9600); } void draw() { if (myPort.available() > 0) { val = myPort.read(); } if (val == 1) { rect(0,0, 10, 10); } } 

I'm just not able to combine it with the following sketch and I don't know why.

float x1; float x2; float x3; float x4; float x5; float y1; float y2; float y3; float y4; float r1; float g1; float b1; float r2; float g2; float b2; float r3; float g3; float b3; float r4; float g4; float b4; float r5; float g5; float b5; float r6; float g6; float b6; float r7; float g7; float b7; float r8; float g8; float b8; float r9; float g9; float b9; float r10; float g10; float b10;

boolean a = true; boolean b = false; boolean c = false; boolean d = false; boolean e = false; boolean f = false; boolean g = false; boolean h = false; boolean i = false; boolean j = false;

void setup() { fullScreen(); noCursor(); noStroke(); }

void draw() {

if (a == true) { fill(r1, g1, b1); rect(0, 0, width, height); fill(r2, g2, b2); rect(0, 0, x1, height);

x1 = random(0, width); r1 = random(255); g1 = random(255); b1 = random(255); r2 = random(255); g2 = random(255); b2 = random(255); 

}

if (b == true) { fill(r1, g1, b1); rect(0, 0, width, height); fill(r2, g2, b2); rect(0, 0, x1, height); fill(r3, g3, b3); rect(0+x1, y1, width, height);

y1 = random(0, height); r3 = random(255); g3 = random(255); b3 = random(255); 

}

if (c == true) { fill(r1, g1, b1); rect(0, 0, width, height); fill(r2, g2, b2); rect(0, 0, x1, height); fill(r3, g3, b3); rect(0 + x1, y1, width, height); fill(r4, g4, b4); rect(0, 0, x1, y2);

y2 = random(0, height); r4 = random(255); g4 = random(255); b4 = random(255); 

}

if (d == true) { fill(r1, g1, b1); rect(0, 0, width, height); fill(r2, g2, b2); rect(0, 0, x1, height); fill(r3, g3, b3); rect(0 + x1, y1, width, height); fill(r4, g4, b4); rect(0, 0, x1, y2); fill(r5, g5, b5); rect(0 + x1, y1, x2, height);

x2 = random(0, width - x1); r5 = random(255); g5 = random(255); b5 = random(255); 

}

if (e == true) { fill(r1, g1, b1); rect(0, 0, width, height); fill(r2, g2, b2); rect(0, 0, x1, height); fill(r3, g3, b3); rect(0 + x1, y1, width, height); fill(r4, g4, b4); rect(0, 0, x1, y2); fill(r5, g5, b5); rect(0 + x1, y1, x2, height); fill(r6, g6, b6); rect(0, 0, x3, y2);

x3 = random(0, x1); r6 = random(255); g6 = random(255); b6 = random(255); 

}

if (f == true) { fill(r1, g1, b1); rect(0, 0, width, height); fill(r2, g2, b2); rect(0, 0, x1, height); fill(r3, g3, b3); rect(0 + x1, y1, width, height); fill(r4, g4, b4); rect(0, 0, x1, y2); fill(r5, g5, b5); rect(0 + x1, y1, x2, height); fill(r6, g6, b6); rect(0, 0, x3, y2); fill(r7, g7, b7); rect(0 + x1, y1, x2, y3);

y3 = random(0, height - y1); r7 = random(255); g7 = random(255); b7 = random(255); 

}

if (g == true) { fill(r1, g1, b1); rect(0, 0, width, height); fill(r2, g2, b2); rect(0, 0, x1, height); fill(r3, g3, b3); rect(0 + x1, y1, width, height); fill(r4, g4, b4); rect(0, 0, x1, y2); fill(r5, g5, b5); rect(0 + x1, y1, x2, height); fill(r6, g6, b6); rect(0, 0, x3, y2); fill(r7, g7, b7); rect(0 + x1, y1, x2, y3); fill(r8, g8, b8); rect(0, 0, x3, y4);

y4 = random(0, y2); r8 = random(255); g8 = random(255); b8 = random(255); 

}

if (h == true) { fill(r1, g1, b1); rect(0, 0, width, height); fill(r2, g2, b2); rect(0, 0, x1, height); fill(r3, g3, b3); rect(0 + x1, y1, width, height); fill(r4, g4, b4); rect(0, 0, x1, y2); fill(r5, g5, b5); rect(0 + x1, y1, x2, height); fill(r6, g6, b6); rect(0, 0, x3, y2); fill(r7, g7, b7); rect(0 + x1, y1, x2, y3); fill(r8, g8, b8); rect(0, 0, x3, y4); fill(r9, g9, b9); rect(0 + x1, y1, x4, y3);

x4 = random(0, x2); r9 = random(255); g9 = random(255); b9 = random(255); 

}

if (i == true) { fill(r1, g1, b1); rect(0, 0, width, height); fill(r2, g2, b2); rect(0, 0, x1, height); fill(r3, g3, b3); rect(0 + x1, y1, width, height); fill(r4, g4, b4); rect(0, 0, x1, y2); fill(r5, g5, b5); rect(0 + x1, y1, x2, height); fill(r6, g6, b6); rect(0, 0, x3, y2); fill(r7, g7, b7); rect(0 + x1, y1, x2, y3); fill(r8, g8, b8); rect(0, 0, x3, y4); fill(r9, g9, b9); rect(0 + x1, y1, x4, y3); fill(r10, g10, b10); rect(0, 0, x5, y4);

x5 = random(0, x3); r10 = random(255); g10 = random(255); b10 = random(255); 

}

delay(300); }

void mousePressed() {

if (a && !b && !c && !d && !e && !f && !g && !h && !i) { a = false; b = true; c = false; d = false; e = false; f = false; g = false; h = false; i = false; }

else if (!a && b && !c && !d && !e && !f && !g && !h && !i) { a = false; b = false; c = true; d = false; e = false; f = false; g = false; h = false; i = false; }

else if (!a && !b && c && !d && !e && !f && !g && !h && !i) { a = false; b = false; c = false; d = true; e = false; f = false; g = false; h = false; i = false; }

else if (!a && !b && !c && d && !e && !f && !g && !h && !i) { a = false; b = false; c = false; d = false; e = true; f = false; g = false; h = false; i = false; }

else if (!a && !b && !c && !d && e && !f && !g && !h && !i) { a = false; b = false; c = false; d = false; e = false; f = true; g = false; h = false; i = false; }

else if (!a && !b && !c && !d && !e && f && !g && !h && !i) { a = false; b = false; c = false; d = false; e = false; f = false; g = true; h = false; i = false; }

else if (!a && !b && !c && !d && !e && !f && g && !h && !i) { a = false; b = false; c = false; d = false; e = false; f = false; g = false; h = true; i = false; }

else if (!a && !b && !c && !d && !e && !f && !g && h && !i) { a = false; b = false; c = false; d = false; e = false; f = false; g = false; h = false; i = true; }

else if (!a && !b && !c && !d && !e && !f && !g && !h && i) { a = false; b = false; c = false; d = false; e = false; f = false; g = false; h = false; i = false; saveFrame("print/img-####.jpg"); } }

Can anyone offer some help? (Sorry for not formatting the second sketch, it's very long and I don't want to type the four spaces in front of all of the lines...)

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

Shuffling Array of String Type in Processing (Fisher Yates shuffle)

https://github.com/justintopiary/Shuffling-Arrays-of-String-Type-in-Processing-Fisher-Yates-shuffle-

I've coded a little program to shuffle an array, that uses a computationally efficient and perfectly randomised method. I started coding in Process yesterday and am loving it. I hope this helps somebody; if there's any critique, I'd love to hear feedback. Happy coding everyone.

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

Can someone please explain what the different percentages are doing in each instance?

int col = 0; //color

color[] str = {#93a56d, #d7671e, #bd4917, #8a060c, #3d3333};

float counter = 0; //rotation

float posX = 0;

void setup(){

size(1200,600, P3D);

}

void draw(){

background(0);

noFill();

strokeWeight(12);

pushMatrix();

//shifting the center

translate(300+posX,300,50+posX);

//rotating the boxes by shifting the z axis

rotateY(radians(counter));

rotateX(radians(counter));

//box edges

for(int i = 50; i <= 1500; i=i+50) {

box(i,i,i);

stroke(str[col]);

col=(col+1)%5;

}

popMatrix();

posX = (posX + 1)%1020;

counter = (counter+1)%1020;

}

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

Hi, I have code for a Processing and Arduino game I am making. I want to add balloons to my game and when my cannon shoots and hits the balloons (collision), they are removed from the game. I already have the code working with Arduino and shooting, just need to add balloons & when hit they are gone.

PROCESSING CODE!

//CannonKnob

import processing.serial.*;

import cc.arduino.*;

Arduino arduino;

PImage img;

import ddf.minim.*;

Minim minim;

AudioSnippet hitSound;

int downPin=8;

int knobPin=0;

float angle = -PI/4;

PVector location = new PVector(50, 300);

boolean shot = false;

CannonBall ball;

void setup() {

minim = new Minim(this);

hitSound = minim.loadSnippet("gun-gunshot-02.mp3");

size(640, 360);

ball = new CannonBall(location.x, location.y);

arduino = new Arduino(this, Arduino.list()[1], 57600);

arduino.pinMode(downPin, Arduino.INPUT);

arduino.pinMode(knobPin, Arduino.INPUT);

img=loadImage("cannon game background.jpg");

}

void draw() {

background(255);

noStroke();

fill(100,100,100, 80);

image(img,0,0);

int knobVal=arduino.analogRead(0);

int keypress=arduino.digitalRead(8);

//calculate the angle of the cannon based on mouseY position

angle= map(knobVal, 0, 1023, -PI/2, PI/2);

pushMatrix();

translate(location.x, location.y);

rotate(angle);

rect(0, -5, 50, 10);//draw the cannon

popMatrix();

if (shot) {

PVector gravity = new PVector(0, 0.2);

ball.applyForce(gravity);

ball.update();

}

ball.display();

if (ball.location.y > height) {

ball = new CannonBall(location.x, location.y);

shot = false;

}

//when the mouse is pressed

if (keypress==arduino.HIGH && shot== false){

hitSound.play(0);

shot = true;

PVector force = PVector.fromAngle(angle);

force.mult(10);

ball.applyForce(force);

}

}

//CannonBall

class CannonBall {

PVector location;

PVector velocity;

PVector acceleration;

// Size

float r = 10;

float topspeed = 10;

CannonBall(float x, float y) {

location = new PVector(x,y);

velocity = new PVector();

acceleration = new PVector();

}

void update() {

velocity.add(acceleration);

velocity.limit(topspeed);

location.add(velocity);

acceleration.mult(0);

}

void applyForce(PVector force) {

acceleration.add(force);

}

void display() {

noStroke();

pushMatrix();

translate(location.x,location.y);

ellipse(0,0,r*2,r*2);

popMatrix();

}

}

ARDUINO

int downPin=8;

int knobPin=A0;

int knobVal;

void setup(){

Serial.begin(9600);

pinMode(downPin,INPUT);

pinMode(knobPin, INPUT);

}

void loop(){

int downKey = digitalRead(downPin);

if (downKey == HIGH){

Serial.println("shoot");

}

knobVal=analogRead(knobPin);

Serial.println(knobVal);

}

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

Keep getting black screen

Hey i was doing my school assignment and need some help. I'm not that good at processing but I'm trying. Everytie i run my code I keep ending up with a black screen. I don'd know how to fix this. Plz help. Had to take out the comments. This is my code:

int playerx = 150;

int playery = 325;

color playercolor = color(58, 150, 240);

int[] blockx = {75, 335, 580, 805, 1070, 1315, 1560, 1805};

int[] blocky = {425, 75, 425, 75, 425, 75, 425, 75};

color blockcolor = color(120, 122, 124);

int gamemode = 1;

PImage img;

int x = 0;

void setup(){

size (1000, 600);

img = loadImage("midnight_moon.png");

background(0);

void draw(){

while(gamemode == 0){

drawstartscreen();

fill(173, 164, 164);

if(mousePressed == true && mouseX >= 290 && mouseX <= 350 && mouseY <= 400 && mouseY >=200){

fill(33, 112, 52);

gamemode = 1;

}

rect(310, 400, 400, 150);

fill(255, 255, 255);

textSize(30);

text("CLICK TO START", 390, 490);

}

while (gamemode == 1){

image(img, x, 0);

image(img, x + img.width, 0);

x--;

if(x < -img.width)

x = 0;

drawplayer(playerx, playery, playercolor);

drawblock1(blockx [0], blocky [0], blockcolor);

drawblock1(blockx [1], blocky [1], blockcolor);

drawblock2(blockx [2], blocky [2], blockcolor);

drawblock1(blockx [3], blocky [3], blockcolor);

drawblock3(blockx [4], blocky [4], blockcolor);

drawblock3(blockx [5], blocky [5], blockcolor);

drawblock1(blockx [6], blocky [6], blockcolor);

drawblock2(blockx [7], blocky [7], blockcolor);

blockx [0] = blockx [0] - 2;

if(blockx [0] <= -290){

blockx [0] = 1700;

}

blockx [1] = blockx [1] - 2;

if(blockx [1] <= -290){

blockx [1] = 1700;

}

blockx [2] = blockx [2] - 2;

if(blockx [2] <= -290){

blockx [2] = 1700;

}

blockx [3] = blockx [3] - 2;

if(blockx [3] <= -290){

blockx [3] = 1700;

}

blockx [4] = blockx [4] - 2;

if(blockx [4] <= -290){

blockx [4] = 1700;

}

blockx [5] = blockx [5] - 2;

if(blockx [5] <= -290){

blockx [5] = 1700;

}

blockx [6] = blockx [6] - 2;

if(blockx [6] <= -290){

blockx [6] = 1700;

}

blockx [7] = blockx [7] - 2;

if(blockx [7] <= -290){

blockx [7] = 1700;

}

}

}

void drawplayer(int x, int y, color c){

fill(c);

rect(x, y, 60, 100);

}

void drawblock1(int x, int y, color c){

fill(c);

rect(x, y, 300, 100);

}

void drawblock2(int x, int y, color c){

fill(c);

rect(x, y, 200, 100);

}

void drawblock3(int x, int y, color c){

fill(c);

rect(x, y, 400, 100);

}

void drawstartscreen(){

fill(0, 0, 0);

for(int i = 0; i < 600; i++){

ellipse(random(1000), random(600), 5, 5);

}

}

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