Hi, guys,
I have a question how can I mirror my mouse event?
At the moment I have a growing lightningbolt while moving my mouse and I need it mirrored now.
Here is the code
int width = 250;
int height = 250;
//angle of the parts of the bolt
float maxDTheta = PI/10;
float minDTheta = PI/20;
float maxTheta = PI/2;
//CHANCE OF HAVING A CHILD STRIKE
float childGenOdds = .01;
float minBoltWidth = 1;
float maxBoltWidth = 1;
float boltLen= 10;
//lenght of the parts of the bolt
float minJumpLength = 1;
float maxJumpLength = 10;
boolean stormMode = true;
boolean fadeStrikes = true;
boolean randomColors = false;
float maxTimeBetweenStrikes = 300;
color boltColor;
color bolt2Color;
color skyColor;
lightningBolt bolt;
lightningBolt2 bolt2;
float lastStrike = 0;
float nextStrikeInNms = 0;
//distance, in milliseconds, of the storm.
float meanDistance = 0;
//if the current time matches the time in this arraylist, it should fire!
ArrayList thunderTimes = new ArrayList();
int value = 0;
int dir = 0;
void setup(){
colorMode(HSB,100);
smooth();
size(600, 800);
noFill();
meanDistance = 1000*.5;
background(skyColor);
}
void draw(){
boltColor = color(200,200,99);
bolt2Color = color(80,200,99);
int maxMouseX= 0;
float boltLen= 0;
float boltAdd=0;
if(mouseX > maxMouseX){
maxMouseX = mouseX;
boltLen = boltLen + boltAdd;
boltAdd = boltAdd+0.01;
}
else if (mouseX < maxMouseX){
maxMouseX = mouseX;
// boltLen = boltLen + boltAdd;
boltLen = -boltAdd;
}
if(stormMode && millis()-lastStrike>nextStrikeInNms){//time for a new bolt?
lastStrike = millis();
nextStrikeInNms = random(0,maxTimeBetweenStrikes);
//parameters are starting (startung x, startuíng y, thickness, angle of part, minlenght, max lenght, color)
bolt = new lightningBolt(100,100,random(minBoltWidth,maxBoltWidth),0,minJumpLength,maxJumpLength,mouseX, boltColor);
bolt.draw();
}
else{
if(fadeStrikes){
noStroke();
//fill(skyColor);
rect(0,0,width,height);
noFill();
}
}
}
void stop(){
//thunderSound.close();
//minim.stop();
super.stop();
}
int randomSign() //returns +1 or -1
{
float num = random(-1,1);
if(num==0)
return -1;
else
return (int)(num/abs(num));
}
color randomColor(){
return color(random(0,100),99,99);
}
color slightlyRandomColor(color inputCol,float length){
float h = hue(inputCol);
h = (h+random(-length,length))%100;
return color(h,99,99);
}
And also the lightningbolt
class lightningBolt{
float lineWidth0,theta,x0,y0,x1,y1,x2,y2,straightJump,straightJumpMax,straightJumpMin,lineWidth, btLen;
color myColor;
//parameters are starting
lightningBolt(float x0I, float y0I, float width0, float theta0, float jumpMin, float jumpMax, float boltLen, color inputColor){
lineWidth0 = width0;
lineWidth = width0;
theta = theta0;
x0 = x0I;
y0 = y0I;
x1 = x0I;
y1 = y0I;
x2 = x0I;
y2 = y0I;
straightJumpMin = jumpMin;
straightJumpMax = jumpMax;
myColor = inputColor;
btLen = boltLen;
//it's a wandering line that goes straight for a while,
//then does a jagged jump (large dTheta), repeats.
//it does not aim higher than thetaMax
//(where theta= 0 is down)
straightJump = random(straightJumpMin,straightJumpMax);
}
//tells when the thunder should sound.
float getThunderTime(){
return (millis()+meanDistance*(1+random(-.1,.1)));
}
void draw()
{
//this where you can control the min and max lenght and x y
while((y2>0 && y2<200) && (x2>0 && x2<btLen))
{
strokeWeight(1);
theta += randomSign()*random(minDTheta, maxDTheta);
if(theta>maxTheta)
theta = maxTheta;
if(theta<-maxTheta)
theta = -maxTheta;
straightJump = random(straightJumpMin,straightJumpMax);
x2 = x1-straightJump*sin(theta-HALF_PI);
y2 = y1-straightJump*cos(theta-HALF_PI);
if(randomColors)
myColor = slightlyRandomColor(myColor,straightJump);
lineWidth = map(y2, height,y0, 1,lineWidth0);
if(lineWidth<0)
lineWidth = 0;
stroke(myColor);
strokeWeight(lineWidth);
line(x1,y1,x2,y2);
x1=x2;
y1=y2;
//think about making a fork
if(random(0,1)<childGenOdds){//if yes, have a baby!
float newTheta = theta;
newTheta += randomSign()*random(minDTheta, maxDTheta);
if(theta>maxTheta)
theta = maxTheta;
if(theta<-maxTheta)
theta = -maxTheta;
// nForks++;
(new lightningBolt(x2, y2, lineWidth, newTheta, straightJumpMin, straightJumpMax, btLen, boltColor)).draw();
//it draws the whole limb before continuing.
}
}
}
}
thank you in advance!