/r/processing

Photograph via snooOG

“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.


Getting Started & Tutorials:

(open to suggestions)


Weekly Challenges Archive


Rules:

Regarding help with school work:

  • asking for help with an assignment is OK
  • asking for someone to do an assignment for you is NOT OK
  • responding to a request for help with hints, suggestions or explanations is OK
  • responding to a request for help with a complete solution is NOT OK

/r/processing

28,109 Subscribers

2

How do I get Clipboard.getContents(null) and it's other java.awt components to work outside of draw()?

I have a project where I have a bunch of nested if conditions, in one of them I need to get the clipboard contents. That is done inside setup() and exits at the end. Since inside these if conditions are a bunch of for loops, implementing it to work inside draw() will get really messy.

I did test getting clipboard contents inside draw(), constantly printing it out and it works. Also tested it in setup inside a while(true) loop, but it just repeats the old contents.

I know draw() does a bunch of stuff that's behind the scenes, but what hidden code gets called when using draw() to get the latest clipboard contents?

1 Comment
2024/11/09
07:50 UTC

12

Eve Interior - 100,000,000 dots on a canvas

1 Comment
2024/11/08
17:50 UTC

3

Hi, problem exporting my sketch :/

Hi! I’m using Processing 4.0, and I can’t export my sketch to MP4 (or most probably I don’t know how). I tried the old method, using the hamoid library and the rec() method that Tim rodenbröker explained on his tutorial: “Video-Export - Processing Tutorial”. But the library is not is not supported on this new version (the 4.0). Can someone help me with this? My sketch has image and sound so I really need to export it in MP4. Thank you in advance :)

1 Comment
2024/11/08
02:05 UTC

0

can someone plz teach me how to do these questions

On the third tab labeled "Overloading methods" i really need help i have a quiz on monday im in intro to programming

https://home-ca3b3.web.app/intro/classes/practice/practice.html

2 Comments
2024/11/07
14:43 UTC

2

help with mouse position based rotation

I have made a code which allows my mouse to go through a pattern which then re rotates in direction of the mouse.

How do I get the Objects(grid) to rotate in the opposite direction?

void draw() {

background(255);

smooth();

stroke(78,155,234);

for (int i=1; i<anz; i++) {

for (int j=1; j<anz; j++) {

//Y und Y vertauscht!!!!!

int posXLine=i*raster+abstand;

int posYLine=j*raster+abstand;

float angle=atan2(mouseY-posYLine, mouseX-posXLine);

pushMatrix();

translate(posXLine,posYLine);

rotate(angle);

rect(0,0, laenge, 1);

popMatrix();

}

}

}

1 Comment
2024/11/06
17:21 UTC

2

Good news: The submission deadline for EvoMUSART 2025 has been extended to November 15th! 🙌

1 Comment
2024/11/06
09:37 UTC

2

Dr. Strange-Inspired Hand-Tracking Web App

Hi everyone! I just made a portal generator web app using p5.js for the UI, the YouTube API for video search, and the MediaPipe library for hand tracking. I hope you like it! It also has a mouse mode if you don’t want to use the webcam to control it (though hand tracking is more fun!). Let me know what you think! https://flavourmachine.com/portal-generator/

0 Comments
2024/11/06
02:52 UTC

74

Eve - 100,000,000 dots on a canvas

4 Comments
2024/11/04
20:50 UTC

2

Trying to make my circle change direction on X-axis when width is reached

Hi all!

I'm trying to make my circle change direction if it reaches the canvas width. However it does not return with my code and gets stuck at x width. What am I missing? Appreciate any insight into this.

float circleX = 0;
float circleY = height/2;
float speed = 1;

void setup() {
  size(640, 360);
  //background(0);
  //circleX = 0;
}

void draw() {

  background(0);

  //if (mouseX > 320) {
  //  background(255);
  //}
  stroke(127);
  strokeWeight(4);
  line(320, 0, 320, height);

  circle(circleX, circleY, 50);

  if (circleX >= 640) {
    circleX = circleX - speed;
  }

  if (circleX < 640) {
    circleX = circleX + (3 * speed);
  }
}

I've also tried it with this code without the additional speed variable.

float circleX = 0;
float circleY = height/2;

void setup() {
  size(640, 360);
  
}

void draw() {
  
  background(0);
  stroke(127);
  strokeWeight(4);
  line(320, 0, 320, height);
  
  circle(circleX, circleY, 50);
  
  if (circleX > 640) {
    circleX--;
  } 
  
  if (circleX <= 640) {
    circleX = circleX + 2;
  }  
}
7 Comments
2024/11/04
10:04 UTC

4

APDE (Android App for Processing P5 programming) missing from Play Store

Just wanted to install it on a new device, but couldn't find it in the Play Store and the URL on processing.org referring to the app leads to a 404 on the Play Store website. Does anyone know any alternative sources?

3 Comments
2024/11/04
09:42 UTC

2

How to view outgoing serial stream?

For troubleshooting purposes, I would like to see what data Processing is actually sending out when it executes "myPort.write()". Everything I can find online(including the Serial reference) is how to write to serial outgoing, read from serial incoming, or how to use an Arduino to receive data; but nothing to actually listen in on what my program is saying. Seems like this would be simple but I am not having any luck.

How do I view my outgoing serial stream from within Processing itself?

1 Comment
2024/11/04
05:56 UTC

72

Triangle Rasterization in p5*js

5 Comments
2024/11/03
12:51 UTC

3

Step Sequencer with processing.sound library weirdly laggy

I'm trying to make a simple step sequencer that can play one-shot audio samples on a 16th note grid.

I first did the timing using the frame rate but that was obviously inconsistent and laggy. Now I am using the millis() function to check if another 16th note has passed. Where I noticed the 16th notes (should be 111ms at 135bpm) being off by up to 10 milliseconds. So now I even correct for that.

Still I do not get a consistent clock output and the sound glitches every couple of steps and cuts off for short amounts of time randomly.

I know there are other sound libraries out there but I have to make it work with processing.sound because it's an assignment.

All files are 16bit 48 kHz stereo WAV files, with no trailing or leading silence to make it as simple as possible.

If anyone knows a potential fix I'd be very grateful.

Here's the code:

import processing.sound.*;

public class Track {
  public ArrayList<Step> steps = new ArrayList<Step>();
  public SoundFile sample;
  public boolean doesLoop;

  public Track(SoundFile sample, boolean doesLoop) {
    this.sample = sample;
    this.doesLoop = doesLoop;
  }

  public void addStep(Step step) {
    steps.add(step);
  }

  public void fillEmptySteps(int count) {
    for (int i = 0; i < count; i++) {
      steps.add(new Step(false, 1, 1));
    }
  }

  public Step modifyStep(int index) {
    return steps.get(index);
  }

  public boolean playStep(int index) {
    Step step;
    if (steps.size() > index) {
      step = steps.get(index);
    } else {
      step = steps.get((int) (index / steps.size()));
    }

    if (steps.size() > index) {
      step.play(sample);
      return step.active;
    } else if (doesLoop) {
      step.play(sample);
      return step.active;
    }

    return false;
  }
}

public class Step {
  public boolean active;
  public float velocity;
  public float pitch;

  public Step(boolean active, float velocity, float pitch) {
    this.active = active;
    this.velocity = velocity;
    this.pitch = pitch;
  }

  public void play(SoundFile sample) {
    if (active) {
      sample.stop();
      sample.rate(pitch);
      sample.amp(velocity);
      sample.play();
    }
  }

  public color getColor() {
    return color(0, pitch/2, velocity);
  }
}

int position = 0;
int lastTime = 0;


int globalLength = 64;
float bpm = 135;
float sixteenth = 60/(4*bpm);

color emptyStep;
color activeStep;
int stepDimension;

Track melody;
Track kick;
Track tom;
Track hat1;
Track hat2;
Track snare;
Track clap;
Track perc;

void setup() {

  colorMode(HSB, 1.0, 1.0, 1.0);
  size(2000, 1000);
  frameRate(bpm);

  emptyStep = color(0, 0, 0.42);
  activeStep = color(0, 0, 0.69);
  stepDimension = 30;

  kick = new Track(new SoundFile(this, "Kick short.wav"), true);
  tom = new Track(new SoundFile(this, "Tom.wav"), true);
  hat1 = new Track(new SoundFile(this, "Hat 1.wav"), true);
  hat2 = new Track(new SoundFile(this, "Hat 2.wav"), true);
  snare = new Track(new SoundFile(this, "Snare.wav"), true);
  clap = new Track(new SoundFile(this, "Clap.wav"), true);
  perc = new Track(new SoundFile(this, "Perc.wav"), true);

  //kick
  for (int i = 0; i < 16; i++) {
    kick.addStep(new Step(true, 1, 1));
    kick.fillEmptySteps(3);
  }

  //tom
  for (int i = 0; i < 2; i++) {
    tom.fillEmptySteps(3);
    tom.addStep(new Step(true, 1, 1));
    tom.fillEmptySteps(5);
    tom.addStep(new Step(true, 1, 1.58333));
    tom.fillEmptySteps(1);
    tom.addStep(new Step(true, 1, 1));
    tom.fillEmptySteps(4);
    tom.fillEmptySteps(3);
    tom.addStep(new Step(true, 1, 1));
    tom.fillEmptySteps(5);
    tom.addStep(new Step(true, 1, 2));
    tom.fillEmptySteps(1);
    tom.addStep(new Step(true, 1, 1));
    tom.fillEmptySteps(4);
  }

  //hat 1
  for (int i = 0; i < 4; i++) {
    hat1.fillEmptySteps(2);
    hat1.addStep(new Step(true, 1, 1));
    hat1.fillEmptySteps(2);
    hat1.addStep(new Step(true, 0.33, 1));
    hat1.addStep(new Step(true, 1, 1));
    hat1.fillEmptySteps(3);
    hat1.addStep(new Step(true, 1, 1));
    hat1.fillEmptySteps(3);
    hat1.addStep(new Step(true, 1, 1));
    hat1.addStep(new Step(true, 0.33, 1));
  }

  //hat 2
  for (int i = 0; i < 2; i++) {
    hat2.fillEmptySteps(30);
    hat2.addStep(new Step(true, 1, 1));
    hat2.fillEmptySteps(1);
  }

  //snare
  for (int i = 0; i < 4; i++) {
    snare.fillEmptySteps(1);
    snare.addStep(new Step(true, 0.5, 2));
    snare.fillEmptySteps(5);
    snare.addStep(new Step(true, 1, 1));
    snare.fillEmptySteps(1);
    snare.addStep(new Step(true, 0.5, 1.58333));
    snare.fillEmptySteps(3);
    snare.addStep(new Step(true, 1, 1));
    snare.fillEmptySteps(2);
  }

  //clap
  for (int i = 0; i < 2; i++) {
    clap.addStep(new Step(true, 1, 1));
    clap.fillEmptySteps(2);
    clap.addStep(new Step(true, 1, 1));
    clap.fillEmptySteps(12);
    clap.addStep(new Step(true, 1, 1));
    clap.fillEmptySteps(2);
    clap.addStep(new Step(true, 1, 1));
    clap.fillEmptySteps(10);
    clap.addStep(new Step(true, 0.5, 1));
    clap.fillEmptySteps(1);
  }

  //perc
  perc.fillEmptySteps(2);
  perc.addStep(new Step(true, 1, 1));
  perc.fillEmptySteps(4);
  perc.addStep(new Step(true, 1, 1));
  perc.fillEmptySteps(3);
  perc.addStep(new Step(true, 1, 1));
  perc.fillEmptySteps(5);
  perc.addStep(new Step(true, 1, 1));
  perc.fillEmptySteps(4);
  perc.addStep(new Step(true, 1, 1));
  perc.fillEmptySteps(4);
  perc.addStep(new Step(true, 1, 1));
  perc.fillEmptySteps(3);
  perc.addStep(new Step(true, 1, 1));
  perc.fillEmptySteps(5);
  perc.addStep(new Step(true, 1, 1));
  perc.fillEmptySteps(4);
  perc.addStep(new Step(true, 1, 1));
  perc.fillEmptySteps(4);
  perc.addStep(new Step(true, 1, 1));
  perc.fillEmptySteps(3);
  perc.addStep(new Step(true, 1, 1));
  perc.fillEmptySteps(5);
  perc.addStep(new Step(true, 1, 1));
  perc.fillEmptySteps(4);
  perc.addStep(new Step(true, 1, 1));
  perc.fillEmptySteps(1);
}

void draw() {

  int currentTime = millis();
  boolean trigger = currentTime >= lastTime + (int) (sixteenth * 1000) - ((currentTime - lastTime) - (int) (sixteenth * 1000));

  if (trigger) lastTime = currentTime;

  background(0, 0, 0);

  if (position >= globalLength) position = 0;

  // kick
  for (int i = 0; i < globalLength; i++) {
    if (i == position) {
      fill(activeStep);
      if (trigger) {
        kick.playStep(i);
      }
    } else if (kick.steps.get(i).active) {
      fill(kick.steps.get(i).getColor());
    } else {
      fill(emptyStep);
    }
    rect(stepDimension + i * stepDimension, stepDimension * 1, stepDimension, stepDimension, 5);
  }

  // tom
  for (int i = 0; i < globalLength; i++) {
    if (i == position) {
      fill(activeStep);
      if (trigger) {
        tom.playStep(i);
      }
    } else if (tom.steps.get(i).active) {
      fill(tom.steps.get(i).getColor());
    } else {
      fill(emptyStep);
    }
    rect(stepDimension + i * stepDimension, stepDimension * 2, stepDimension, stepDimension, 5);
  }

  //hat 1
  for (int i = 0; i < globalLength; i++) {
    if (i == position) {
      fill(activeStep);
      if (trigger) {
        hat1.playStep(i);
      }
    } else if (hat1.steps.get(i).active) {
      fill(hat1.steps.get(i).getColor());
    } else {
      fill(emptyStep);
    }
    rect(stepDimension + i * stepDimension, stepDimension * 3, stepDimension, stepDimension, 5);
  }

  //hat 2
  for (int i = 0; i < globalLength; i++) {
    if (i == position) {
      fill(activeStep);
      if (trigger) {
        hat2.playStep(i);
      }
    } else if (hat2.steps.get(i).active) {
      fill(hat2.steps.get(i).getColor());
    } else {
      fill(emptyStep);
    }
    rect(stepDimension + i * stepDimension, stepDimension * 4, stepDimension, stepDimension, 5);
  }

  //snare
  for (int i = 0; i < globalLength; i++) {
    if (i == position) {
      fill(activeStep);
      if (trigger) {
        snare.playStep(i);
      }
    } else if (snare.steps.get(i).active) {
      fill(snare.steps.get(i).getColor());
    } else {
      fill(emptyStep);
    }
    rect(stepDimension + i * stepDimension, stepDimension * 5, stepDimension, stepDimension, 5);
  }

  //clap
  for (int i = 0; i < globalLength; i++) {
    if (i == position) {
      fill(activeStep);
      if (trigger) {
        clap.playStep(i);
      }
    } else if (clap.steps.get(i).active) {
      fill(clap.steps.get(i).getColor());
    } else {
      fill(emptyStep);
    }
    rect(stepDimension + i * stepDimension, stepDimension * 6, stepDimension, stepDimension, 5);
  }


  //perc
  for (int i = 0; i < globalLength; i++) {
    if (i == position) {
      fill(activeStep);
      if (trigger) {
        perc.playStep(i);
      }
    } else if (perc.steps.get(i).active) {
      fill(perc.steps.get(i).getColor());
    } else {
      fill(emptyStep);
    }
    rect(stepDimension + i * stepDimension, stepDimension * 7, stepDimension, stepDimension, 5);
  }

  if (trigger) {
    position++;
  }
}
0 Comments
2024/11/03
12:34 UTC

14

My first complete work with Processing and Pure Data

Dear all, I would like to share with you guys, for fun and some feedback, my latest work called BYON. It was made entirely with Pure Data and Processing. I started to learn Processing specifically for this, and this community helped me when I got stuck.

My official fancy description of the project is: "BYON (or Bring Your Own Number) is an audiovisual piece with 1,000,001 movements. Little by little, these movements are being discovered, and whoever discovers a movement has the right to name it. Each movement consists of stereo music and video, both generated by computer code and based only on a numeric input. The music and video are unique for each number, ranging from (and including) 0 to 1,000,000. Yet, despite the seemingly random nature of the process, the sounds and visuals are not entirely chaotic. Through careful planning, coherence emerges across the movements, even in the absence of direct human control, making BYON an exploration of compromise with the unknown and an exercise in acceptance."

This is one of my favorite numbers so far, and I am uploading every new submission to this channel: https://youtu.be/ZLpDYavUFHI

If you want to discover and title your own movement, submit any number you’d like to see featured on this channel using this form: https://forms.gle/21mcnpsVA737aqTS7

A couple of people suggested that I added a BYON channel on my discord and we are experimenting with that. Link is in the video description as well.

Please let me know if you have any question or feedback.

0 Comments
2024/11/02
01:16 UTC

21

Self Portrait - 39,999,960 dots on a canvas

1 Comment
2024/11/01
08:34 UTC

3

Why does this happen and can I rectify it in the Game Control Plus Library

I have reinstalled the library and the software over and over again but to no avail.

https://preview.redd.it/uuq4rdroi7yd1.png?width=1104&format=png&auto=webp&s=d47ec6462df2e180921b6b8cc49e97e27d9ca42c

4 Comments
2024/11/01
03:11 UTC

37

Random Quadrilaterals inspired by Vera Molnar's works

3 Comments
2024/10/31
03:16 UTC

3

help processing/java/sokoban/video games

Hello, I have an assignment on Open Processing. We need to follow the guideline of 50x50 pixels.

Please let me know what I can improve; I really don't like the colors, I find them very dull. I want something pastel and more girly, but I'm stuck. It's driving me crazy:

void settings() {
  size(500, 500);
}

void setup() {
  loadLevel(1);
}

void draw() {
  background(200);
  drawMap();
}

boolean solved() {
  return true; // To be completed later
}

void loadLevel(int lev) {
  // Load the level (to be completed later)
}

void drawMap() {
  drawMur(0, 0);     // Wall
  drawCaisse(0, 50); // Box
  drawSol(0, 100);   // Floor
  drawAvatar(0, 150); // Avatar
}

// Function to draw the box
void drawCaisse(int x, int y) {
  fill(184, 134, 11); // Box color
  rect(x, y, 50, 50);
  
  stroke(139, 69, 19); // Outline
  strokeWeight(4);
  line(x + 5, y + 5, x + 45, y + 45);
  line(x + 5, y + 45, x + 45, y + 5);
  
  strokeWeight(2);
  line(x, y + 10, x + 50, y + 10);
  line(x, y + 25, x + 50, y + 25);
  line(x, y + 40, x + 50, y + 40);
  
  strokeWeight(1); // Reset line thickness
}

// Function to draw the wall
void drawMur(int x, int y) {
  fill(169, 169, 169); // Wall color
  rect(x, y, 50, 50);
  
  fill(105, 105, 105); // Brick color
  // Each brick is drawn to stay within the 50x50 pixels limit
  rect(x + 2, y + 2, 20, 10);
  rect(x + 28, y + 2, 20, 10);
  rect(x + 2, y + 14, 20, 10);
  rect(x + 28, y + 14, 20, 10);
  rect(x + 2, y + 26, 20, 10);
  rect(x + 28, y + 26, 20, 10);
  rect(x + 2, y + 38, 20, 10);
  rect(x + 28, y + 38, 20, 10);
}

// Function to draw the floor
void drawSol(int x, int y) {
  fill(211, 211, 211); // Floor color
  rect(x, y, 50, 50);
  
  fill(169, 169, 169); // Stone texture
  ellipse(x + 25, y + 25, 30, 30); // Central stone
  ellipse(x + 15, y + 15, 10, 10); // Small stones
  ellipse(x + 35, y + 35, 10, 10);
  ellipse(x + 20, y + 35, 7, 7);
}

// Function to draw the avatar
void drawAvatar(int x, int y) {
  fill(255, 215, 0); // Hair
  arc(x + 25, y + 20, 40, 40, PI, TWO_PI);
  rect(x + 10, y + 20, 30, 25);
  
  fill(255, 224, 189); // Face
  ellipse(x + 25, y + 20, 25, 25); // Reduced to avoid overflow
  
  fill(147, 112, 219); // Eyes
  ellipse(x + 18, y + 18, 6, 6); // Adjusted size
  ellipse(x + 32, y + 18, 6, 6);
  
  fill(255);
  ellipse(x + 16, y + 16, 2, 2); // Highlights in the eyes
  ellipse(x + 30, y + 16, 2, 2);
  
  fill(255, 182, 193, 150); // Cheeks
  ellipse(x + 15, y + 23, 5, 4); // Reduced size
  ellipse(x + 35, y + 23, 5, 4);
  
  stroke(255, 105, 180); // Mouth
  strokeWeight(2);
  noFill();
  arc(x + 25, y + 25, 8, 8, 0, PI);
  
  fill(255, 105, 180); // Hair accessories
  ellipse(x + 10, y + 10, 6, 6);
  ellipse(x + 40, y + 10, 6, 6);
  
  noStroke();
  fill(255, 182, 193); // Dress
  triangle(x + 15, y + 45, x + 25, y + 30, x + 35, y + 45); // Adjusted to avoid overflow
  
  stroke(255, 224, 189); // Arms
  strokeWeight(2);
  line(x + 15, y + 35, x + 10, y + 40); // Left
  line(x + 35, y + 35, x + 40, y + 40); // Right
  
  line(x + 22, y + 45, x + 22, y + 50); // Left leg
  line(x + 28, y + 45, x + 28, y + 50); // Right leg
}

void keyReleased() {
  // To be completed later
}

void mouseClicked() {
  // To be completed later
}
3 Comments
2024/10/29
15:03 UTC

5

Can sombody help me loading an Image

class Player {
  // Atribute
   float xPos;
   float yPos;
   int speed;
   PImage pImg;
  
   Keylistener kh;

  //Konstruktormethode
  public Player(Keylistener keyL) {
  kh = keyL;
  speed = 3;
  xPos = 0;
  yPos = 0;
  pImg= loadImage("player.png");
  }
  
  void update(){
    if (kh.w == true) {
    xPos = xPos - speed;
  }
    if (kh.a == true) {
    yPos = yPos - speed;
  }
    if (kh.s == true) {
    xPos = xPos + speed;
  }
    if (kh.d == true) {
    yPos = yPos + speed;
    
   
  }
  
  
  } 
  void draw(){
    
    if (pImg != null){
      image(pImg,yPos,xPos);}
    
  
  
  
  
  }

This is the code for the player of my game. Right now I am trying to load the image every time i try it does not load . Please help me I really don't know what to do.

9 Comments
2024/10/28
16:09 UTC

3

(Processing 4.3) P3D not working

Whenever I run some boiler plate code for a window, it works, but as soon as I draw any primitive, processing throws:

sphere() is not available with this renderer.

I'm running windows 11, do ya'll have any Idea why this doesn't work?

3 Comments
2024/10/26
16:44 UTC

2

[p5js] How do rid of lag?

This is a prototype game about a goose who has to keep the temperature right or else the world ends. I'm trying to add in more mechanics in but I really can't move on because the lag gets worse the more you play. Is there anything I can reduce or simplify?

let gabHeatColor = 0;
let gabThermoStat = 30;

var gooseHonk;
let laserHue = 0;

//denaplesk2 game timer
let timerValue = 30;
let startButton;

let timerBar = 0; //will appear @ top screen

function preload() {
  soundFormats('wav');
  gooseHonk = loadSound('spacejoe_bird-honk-2.wav');
}

function mousePressed() { //plays goose honk
  gooseHonk.play();
}

function setup() {
  createCanvas(windowWidth, windowHeight);
  // textAlign(CENTER);
  setInterval(timeIt, 1000);
}

function timeIt() {
  if (timerValue > 0) {
    timerValue--;
  }
}

function draw() {
  // frameRate(20);
  background(140, 140, 72);
  strokeWeight(0);
  
  fill(107, 94, 43); //floor background
  rect(0, windowHeight/1.3, windowWidth, windowHeight);
  
  fill(140, 213, 237); //window
  rect(windowWidth/3, windowHeight/7, 200, 450);
  
  //timer > winstate or gameover
  fill(0);
  if (timerValue <= 60) {
    text(timerValue + " SECONDS", width / 3, height / 10);
  } else {
    text(timerValue + " SECONDS, You WIN!", width / 3, height / 10);
    frameRate(0);
  } 
  
  if (gabThermoStat > 100) {
    gabThermoStat = 999;
    text("oops world heated", 50, 50);
    text("Oh no SECONDS, You LOSE!", width / 3, height / 10);
  } if (gabThermoStat <= 0) {
    gabThermoStat = -99;
    textSize(windowWidth/20);
    text("oops world frozen", 50, 50);
    text("NO SECONDS, You LOSE!", width / 3, height / 10);
    frameRate(2);
  }
  
  gabFan();
  gabGooseBod();
}

function gabGooseBod() {
  push(); //goose neck
  stroke(240);
  strokeWeight(30);
  line(0, windowHeight, mouseX-(mouseX/2), mouseY-25);
  pop();
  
  fill(240); //goose torso
  circle(0, windowHeight, 300);
  fill(300); //gooseHead
  rect(mouseX-(mouseX/2), mouseY-25, 50, 50); 
  circle(mouseX-(mouseX/2), mouseY-25, 100);
  fill(0);
  circle(mouseX-(mouseX/2), mouseY-25, 40); //eye
  fill(255,166,0);
  circle(mouseX-(mouseX/2)+50, mouseY, 50); //goose bill & mouth
  
  fill(300,0,0,laserHue);
  rect(mouseX-(mouseX/2), mouseY-40, mouseX-(mouseX/2), 30);
  if (mouseIsPressed === true) {
    laserHue = laserHue + 40;
  } else {
    laserHue = 0;
  }
}

function gabFan() {
  fill(220);
  rect(windowWidth/2,windowWidth/2,windowWidth/2,windowHeight/2);
  
  fill(0);
  textSize(windowWidth/20);
  text("Thermostat: " + gabThermoStat + "/100", windowWidth/2+25, windowHeight/2)
  gabThermoStat = gabThermoStat + 1;
  
  let button0 = createButton("-1"); //heats up
  // button.mouseClicked(fanButton[0]);
  button0.size(90, 70);
  button0.position(windowWidth/2, windowHeight/2);
  button0.style("font-size", "48px");
  
  let button3 = createButton("3"); //3 button
  button3.mousePressed(fanButton);
  print(button3.mousePressed(fanButton));
  button3.size(90, 70);
  button3.position(windowWidth/2, windowHeight/2 + 70);
  button3.style("font-size", "48px");
  
  let button2 = createButton("2"); //2 button
  // button.mouseClicked(fanButton[1]);
  button2.size(90, 70);
  button2.position(windowWidth/2, windowHeight/2 + 140);
  button2.style("font-size", "48px");
  
  let button1 = createButton("1"); //1 button
  // button.mouseClicked(fanButton[2]);
  button1.size(90, 70);
  button1.position(windowWidth/2, windowHeight/2 + 210);
  button1.style("font-size", "48px");
}

function fanButton() {
  gabThermoStat = gabThermoStat - 20;
  print("-20, temp lowered");
}
4 Comments
2024/10/25
21:36 UTC

2

Comp Sci Project Issue

Hello! New to Processing for Comp Sci I. For my midterm, I created a dice rolling simulator. I cannot get the first animation array scene that says "Click to Shake" to come back after clicking twice. Instead, it just gives you a new roll right away. How do I fix this?

import processing.sound.*; //imports sound library

SoundFile diceshaking, dicerolling; //declare sound variables

PImage roll0, roll1, roll2, roll3, roll4, roll5; //declare image variables

int numFrames = 6; //amount of images in the initial animation

PImage[] images = new PImage[numFrames]; //declaring an array for the animation

int frame = 0;

String shake = "Click to Roll"; //text for the first scene

String rolltext = "Click to Roll Again"; //text for the second scene

PFont engraved; //the font for the text

int x = 10; //variables to help the flow of the scenes

int y = 10;

void setup(){

size(700,700); //size of the canvas

frameRate(14); //the amount of frames shown per second

roll0 = loadImage("diceroll00.jpg"); //loading in images of the final dice roll

roll1 = loadImage("diceroll01.jpg");

roll2 = loadImage("diceroll02.jpg");

roll3 = loadImage("diceroll03.jpg");

roll4 = loadImage("diceroll04.jpg");

roll5 = loadImage("diceroll05.jpg");

diceshaking = new SoundFile(this, "diceshaking.mp3"); //loading in the shaking and rolling sound effects

dicerolling = new SoundFile(this, "dicerolling.mp3");

engraved = loadFont("AcademyEngravedLetPlain-48.vlw"); //loading in the font of the text

textFont(engraved); //naming the font

for(int i = 0; i < images.length; i++){ //for loop for the initial animation

String imageName = "diceshake" + nf(i, 2) + ".jpg"; //the array will take images based on the name and number of the file

images[i] = loadImage(imageName);

}

imageMode(CENTER); //makes images and text in center mode

textAlign(CENTER);

diceshaking.loop();

}

void draw(){

if(y == 10){

frame = frameCount % numFrames; //prints the images of the animation to the frame rate

println(frame);

image(images[frame], 350, 350);

fill(255);

textSize(40);

text(shake,width/2,height-30); //prints the String text

}

if (mousePressed == true && x == 10){ //if the mouse is pressed, a random interger 0-6 will be chosen

x = 15;

y = int(random(0,6));

}

if(x == 15 && y == 0){ //calling the dice roll function to display image and text based on interger associated

roll(roll0);

}

if(x == 15 && y == 1){

roll(roll1);

}

if(x == 15 && y == 2){

roll(roll2);

}

if(x == 15 && y == 3){

roll(roll3);

}

if(x == 15 && y == 4){

roll(roll4);

}

if(x == 15 && y == 5){

roll(roll5);

}

}

void mousePressed (){ //when the mouse is pressed, it shows a random dice roll and will give another when clicked again

if(x == 20){

dicerolling.pause();

diceshaking.loop();

x = 10;

y = 10;

}

}

void roll (PImage result){ //function that pauses the shaking sound, plays rolling sound, and displays the dice roll image

diceshaking.pause();

dicerolling.play();

image(result, 350, 350);

text(rolltext,width/2,height-30);

x = 20;

}

1 Comment
2024/10/25
05:56 UTC

2

Collision issues

I'm trying to make one of those 2D car games where there are obstacles along the road and if one hits the car then game over, I created a class called obstacles and made an array containing 5 obstacles, I created this function to detect collisions with the car:

void crash(Car c){

if(dist(obstLocation.x,obstLocation.y,c.carLocation.x,c.carLocation.y) < 5){

textSize(128);

fill(255,0,0);

text("Game Over", 100,200);

hasCrashed = true;

}

}

When I run the code it seems that only one of the obstacles actually ends up calling this function (I'm guessing its the last object in the array?) whilst the rest do nothing.

Any advice on how I should go about fixing this issue?

4 Comments
2024/10/24
18:18 UTC

2

Game Control Plus Library help

I have the code working to the point of this video, https://youtu.be/MUM8_4mWxng?si=MgqxrN8TLcfzVu27 but am lost on what to do after it ends. it explains how to map the joy sticks to the getSlider code and such. the video says nothing about how to map the A, B, Y, and X buttons, the D-pad, the bumpers, or the triggers on the controller. i have looked at the example text included with the libraries I have added, but my pea sized brain cant read them. i need the a button to move a servo as long as i am pressing it, and the b button to do the same the opposite way. if i can get the code for that, i can copy it for the rest. any help would be appreciated

4 Comments
2024/10/24
01:29 UTC

28

Kenyan car mechanic uses processing to control engines

I was watching this video when all of a sudden I recognized processing on his laptop. Thought I'd share with you guys.

6 Comments
2024/10/22
14:41 UTC

5

Centering Scene in Processing 2D

Is there any way I can center the scene (similar to how you can change where you view from using the camera function in p3d) in p2d? Where I am now it would require a lot of work to implement this such that I am drawing my objects relative to the cameras view. I'm wondering if theres any way I can just move the camera in p2d.

2 Comments
2024/10/19
20:45 UTC

4

Stuttering text with P2D and P3D

I've been experimenting with P2D and P3D instead of using the default renderer, and absolutely love the effect it has on my main program. Using anything but the default renderer makes my text stutter though. I can accept not using those renderers, but I'm still so curious as to why. Can anyone here help me?

void setup() {
  size(800, 800, P2D);  //THIS IS WHERE I'M CHANGING THE RENDERER options: -leave blank- for default, P2D, and P3D
  frameRate(60);
}

void draw() {
  background(0);
  pulseText();
}

void pulseText() {
  //flexible variables

  //text to display
  String text = "CLICK TO CHARGE WARP DRIVE!";

  //pulse settings
  float pulseSpeed = 0.05; //default: 0.01
  float pulseIntensity = 5; //default: 5

  //text formatting
  int textSize = width / 20; //default: width / 20
  int textColor = 255; //default: 255

  //text placement
  int textAlignment = CENTER; //options: CENTER LEFT RIGHT default: CENTER
  float textX = width / 2;
  float textY = height * .9;

  //set variables
  float pulse;

  //text formatting
  textAlign(textAlignment);
  fill(textColor);

  //oscillate the text size back and forth
  pulse = textSize + pulseIntensity * sin(frameCount * pulseSpeed);
  println("frameCount: " + frameCount);
  textSize(pulse);

  //display text
  text(text, textX, textY);
}
1 Comment
2024/10/19
20:01 UTC

3

Coding ace attorney like system in Processing?

Hi, I’m a newbie-ish to processing. For my final project, I want to make a game like ace attorney (much lower in complexity and different characters, but still)! However, an issue has arisen. I’m unsure how to create a certain system.

During the trial scenes, a “cross examination” feature exists, where each witness will repeat their testimony continuously. On each line, you can either “press”, which will ask for more information, create a dialogue brach, and then send you back to the testimony, or you can “present evidence” (choose an item from your inventory to contradict it). However, I have… no idea how to program it. My system currently only has dialogue and a system to pan to each of the different locations in the court. How do I code the cross examination and the inventory menu? Also, how do I make it possible to be able to present any piece of evidence, but only one works in order to progress?

2 Comments
2024/10/18
02:58 UTC

Back To Top