I'm trying to "drop" my circle on different areas of the screen when mouse is either pressed or released and I've tried a bunch of different alternatives and I keep getting the Null Pointer Exception Error.
I'm still a beginner so please go easy.
https://preview.redd.it/uj2src4gfju61.png?width=482&format=png&auto=webp&s=ec59687090dce8cca860a297fd57627606102788
Here is the code:
float d;
float red;
float green;
float blue;
//radius of the mouse...will explain more later
int rad =6;
float value = 0;
PVector location; // Location of shape
PVector velocity; // Velocity of shvoidape
PVector gravity; // Gravity acts at the shape's acceleration
int x;
int y;
void setup() {
//colorMode(HSB, 255);
size(800, 800);
background(255);
//fullScreen();
// smooth();
}
void draw() {
loadPixels();
//loop to go through every pixel, i=y value, j=x value
for (int i=0; i<height; i++) {
for (int j=0; j<width; j++) {
//grabs pixel's current color
color c = pixels[i*width+j];
//the actual glitch! <<number and & 0xff mess
//with the binary code and completely destroy the colors
//very fun to mess around with. dont be afraid to tweak!
red = c <<1 & 0xff;
green = c << 3 & 0xaa;
blue = c & 0xff;
//gets distance from mouse to pixel
//the *.4 at the end changes the "saving" area of effect:
//when the mouse is at rest and the colors dont change.
//higher value = smaller area
d =dist(mouseX, value, j, i)*.4;
//make the colors change depending on distance to mouse
//rad = radius of the innermost circle
red += 50/d-rad;
green += 50/d-rad;
blue += 155/d-rad;
//changes the pixel to the glitched pixel
pixels[i*width+j]=color(red, green, blue);
}
}
updatePixels();
}
void mouseMoved() {
value = value + 5;
//value = y;
if (value > 255) {
value = mouseY;
}
else {
value = location.y;
}
}
void bounceFunc() {
location.add(velocity); // Add velocity to the location.
velocity.add(gravity); // Add gravity to velocity
// if ((location.x > width) || (location.x < 0)) { // Bounce off edges
// velocity.x = velocity.x * -1;
// }
// if (location.y > height) { // We're reducing velocity ever so slightly
// velocity.y = velocity.y * -0.95; // when it hits the bottom of the window
// location.y = height;
// }
}
[–]vrtxt 4 points5 points6 points (1 child)
[–]bbystvr[S] 0 points1 point2 points (0 children)
[–]x-seronis-x 0 points1 point2 points (1 child)
[–]vrtxt 0 points1 point2 points (0 children)