All posts by /r/processing

Help with code for a simple game

Hi, can anyone help me with the code for a simple game where three different pieces of fruit fall from a plane and a character must catch them? I'm trying to time each fruit's fall however either they all end up falling, none, or completely break by the end.

I realise the code isn't very efficient but I had some other features which I recently took out to fix a lot of problems.

submitted by Kungr
[link] [comment]

This won’t load in a browser?

Hey! I'm working on a minimalist sketching app in processing! It works fine in java mode but won't run in java script mode when I run / export it and open it in a browser. It's such a basic sketch, I have no idea why it won't work in java script mode. The default html page will load with the sketch description but the sketch is not in the window.

here's my code! any ideas what's causing this?

submitted by KURT1S
[link] [comment]

The Floating Ball

Hey reddit! So currently I was assigned a mini project from my teacher. He is trying to teach us code and I kinda need help. I need to make a 2d ball bounce around the window . Can someone help me? Here's the link I don't want answers just a place to start. It is exercise#1. Thanks!

submitted by GizzlyGrit
[link] [comment]

what does `&` mean in the context of `stroke(i++ & 255)` ?

I've not seen this before and can't find an example in the reference / docs.

here's the code :

int i, w=500; void setup(){ size(w, w); } void draw(){ fill(w, 0, 0, 7); stroke(i++ & 255); bezier(i%w, 0, i%(w+13), w/2, i/w*i%(w+33), w/2, i%(w+87), w); } 

took the code from here :

submitted by y45y564
[link] [9 comments]

PGraphics using .svg instead of the type

Hello everyone,

I have been dabbling with processing for quite some time and I've found this series of tutorials.

The code I am playing this is one for Aggregate drawing and I'm wondering what would be the way to make it use an .svg instead of type? Thank you!!

int drawSpeed = 200; // number of drawn shapes per draw() call int drawMode = 0; // move through the drawing modes by clicking the mouse color BACKGROUND_COLOR = color(255); color PGRAPHICS_COLOR = color(0); PGraphics pg; void setup() { size(1280, 720); background(BACKGROUND_COLOR); // start of with a white background colorMode(HSB, 360, 100, 100); // change to Hue-Saturation-Brightness color mode rectMode(CENTER); // create and draw to PPraphics (see Getting Started > UsingPGraphics example) pg = createGraphics(width, height, JAVA2D); pg.beginDraw(); pg.textSize(500); pg.textAlign(CENTER, CENTER); pg.fill(PGRAPHICS_COLOR); pg.text("TYPE", pg.width/2, pg.height/2); pg.endDraw(); } void draw() { // This for loop ensures the code is repeated 'drawSpeed' times for (int i=0; i<drawSpeed; i++) { // pick a random coordinate int x = (int) random(width); int y = (int) random(height); // check if the coordinate is inside the text (in the offscreen PGraphics) boolean insideText = (pg.get(x, y) == PGRAPHICS_COLOR); // if it is indeed, then draw a shape in the main screen if (insideText) { // switch based on the current draw mode (move through them by clicking the mouse) // each drawing mode has custom settings (stroke, fill, shape, rotation) pushMatrix(); translate(x, y); switch (drawMode) { case 0: float er = random(5, 45); color ec = color(random(360), 100, 100); stroke(0); fill(ec); ellipse(0, 0, er, er); break; case 1: float td = random(3, 10); float tr = random(TWO_PI); color tc = color(random(180, 300), 100, random(50, 100)); noStroke(); fill(tc); rotate(tr); triangle(0, -td, -td, td, td, td); break; case 2: float rw = random(5, 20); float rh = random(5, 50); float rr = random(TWO_PI); color rc = color(random(20), random(70, 100), random(20, 100)); stroke(0); fill(rc); rotate(rr); rect(0, 0, rw, rh); break; } popMatrix(); } } } void mousePressed() { background(BACKGROUND_COLOR); // clear the screen when changing drawing mode drawMode = ++drawMode%3; // move through 3 drawing modes (0, 1, 2) } 
submitted by OpiumTea
[link] [comment]

Using objects with processing – think I’m getting muddled up – is there much point?

Bit of a two parter ->

First off, the sketch that I've written isn't functioning as expected, I'm expecting the colors to be randomly assigned to each object, whereas they seem to be randomly assigned then applied to every object.

here's a video of the programme functioning, those two shapes should be different (random) colors (that's what I expected to be happening at least)

codes at the end of the post.

Secondly - is OOP really needed? I mean, most of the tutorials that I'm reading are learning towards using and writing in OOP, but to me it seems a bit much. I mean, I can understand that for some things its going to be useful but what I want to do is make geometry leaning animations similar to this kind of thing.

Animations such as this one [1] have code that looks like this , which doesn't seem to be OOP at all.

Would OOP serve that kind of programming function or not? The reason I ask is that this kind of thing is what I'm currently interested in making, and I feel that the tutorials [2] that keep pushing towards OOP are perhaps inappropriate for what I want to do, and that there could be better ones.

Id be interested to hear any thoughts on this,

cheers :)

[1] he float's about here sometimes afaik, here's a link to his tumblr though with many more gems on it...

[2] tutorials that i've been looking through have been the ones on the Processing site, the Learn Processing book and Processing 2nd edition.

submitted by y45y564
[link] [comment]

filter(DILATE) and filter(ERODE) expand my colors in diamond patterns, I’d rather they be smooth circles.

//Click and drag with the left and right mouse buttons alternately void setup() { size(300, 300); noStroke(); ellipseMode(CENTER); } void draw() { //filter(BLUR, 4); filter(ERODE); } void mouseDragged() { if (mousePressed && (mouseButton == LEFT)) { fill(255, 255, 255, 40); ellipse(mouseX, mouseY, 50, 50); } else if (mousePressed && (mouseButton == RIGHT)) { fill(0,0,0, 50); ellipse(mouseX, mouseY, 50, 50); filter(DILATE); } } 

I turned off the BLUR in draw() to show the diamond shaping a bit more clearly. Is there a way to get inside these operations to change how they work? I'm kind of new to this so a point in the right direction would be a huge help!

submitted by wiseclockcounter
[link] [comment]

Is learning Java a good idea if I want to be better at Processing… or should I just concentrate on Processing itself ?

I'm a graphic designer and teacher. I do interactive projections and generative art and I'm happy with that: I'm perfectly happy with what Processing can do and offers but I want to learn MORE and be better at it! (I consider myself "intermediate"). I was just wondering if it could be useful to learn java or is it a waste a time (aka I should just practice Processing).

Maybe learning java could help me... - Understand some of the java libraries I use? - Better understand what's under the hood? - Read some of those crazy red bug messages I get sometimes in the console?

Is learning /knowing java useful to you in your Processing practice ?

submitted by Carcaju
[link] [1 comment]