We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi guys I'm new to processing so this is may be a silly questions for the mayority here : ).
I would like to be able to draw a series of shooting star that starts and ends to a random point of a stroke circle (for example an ellipse of 200 radius), not inside of it. I started by using a code of Charlie McDowell that I find on open processing, in wich creates exactly the same effect that I wanted to create, but the stars are randomly drawned on the size of the screen. How can I exactly set the start and end point of the star on random point of the ellipse perimeter?
Here is the code:
/* OpenProcessing Tweak of @http://www.openprocessing.org/sketch/41149@ / / !do not delete the line above, required for linking your tweak if you upload again / / This program draws a starry sky with stars that twinkle. It also includes randomly occuring shooting stars. Author: Charlie McDowell */
// // the tail of the shooting star int[] shootX = new int[30]; int[] shootY = new int[30]; int METEOR_SIZE = 10; // initial size when it first appears float meteorSize = METEOR_SIZE; // size as it fades
// distance a shooting star moves each frame - varies with each new shooting star float ssDeltaX, ssDeltaY; // -1 indicates no shooting star, this is used to fade out the star int ssTimer = -1; // starting point of a new shooting star, picked randomly int startX,startY;
void setup() { size(500,500); smooth(); }
void draw() { background(0); // dark blue night sky
//
// draw the shooting star (if any) for (int i = 0; i < shootX.length-1; i++) { int shooterSize = max(0,int(meteorSizei/shootX.length)); // to get the tail to disappear need to switch to noStroke when it gets to 0 if (shooterSize > 0) { strokeWeight(shooterSize); stroke(255); } else noStroke(); //line(shootX[i], shootY[i], shootX[i+1], shootY[i+1]); ellipse(shootX[i], shootY[i], meteorSizei/shootX.length,meteorSizei/shootX.length); } meteorSize=0.9; // shrink the shooting star as it fades
// move the shooting star along it's path for (int i = 0; i < shootX.length-1; i++) { shootX[i] = shootX[i+1]; shootY[i] = shootY[i+1]; }
// add the new points into the shooting star as long as it hasn't burnt out if (ssTimer >= 0 && ssTimer < shootX.length) { shootX[shootX.length-1] = int(startX + ssDeltaX(ssTimer)); shootY[shootY.length-1] = int(startY + ssDeltaY(ssTimer)); ssTimer++; if (ssTimer >= shootX.length) { ssTimer = -1; // end the shooting star
} }// create a new shooting star with some random probability if (random(5) < 1 && ssTimer == -1) { newShootingStar();
} }/* Starts a new shooting star by randomly picking start and end point. */ void newShootingStar() { int endX, endY; startX = (int)random(width); startY = (int)random(height); endX = (int)random(width); endY = (int)random(height); ssDeltaX = (endX - startX)/(float)(shootX.length); ssDeltaY = (endY - startY)/(float)(shootY.length); ssTimer = 0; // starts the timer which ends when it reaches shootX.length meteorSize = METEOR_SIZE; // by filling the array with the start point all lines will essentially form a point initialy for (int i = 0; i < shootX.length; i++) { shootX[i] = startX; shootY[i] = startY; } }
Thank you for your patience.
Answers
please format the code.
select it, hit ctrl-o.
Hi koogs! Sorry about that, here is the code :
You should be able to use this example to accomplish what you want.
Thanks ttguy44! I'm almost getting there. Here is a new code that I rewrite.
I manage to get a shooting star (ellipse) appear in a random radians value along an ellipse of 200 pixel radius. But I'm quite stuck ... :( I don't know how to simply fade the ellipse after for ex 1 sec, without putting a black rectangle that covered brutaly the shape, and then generating new random star position without using predictable arrays. Any tips? Thank you again!
you can use fill with a 2nd parameter for opacity
over time decrease this value (as a var) from 255 to 0 I think
Thanks Chrisir! I find another trick by decrasing the width and height of the ellipse, but now I don't really undestand how can repeate this infinetly times. I know that is the basics, please a little hint?
here is the code:
Thank you :)
last line::::::
rMove = 1.0;
I'm sorry I do not explained very well : /. I would like to create another ellipse with the same random radians probability of the first one. Having a star shooting one after another one. loooooooping over and over :D
do you see only one ellipse at a time or many?
when it's only one at a time: how long is it there? 360° ?
I see 1 ellipse at the time. The x and y of the ellipse are set to the width and height /2 + cos (a) * r (wich is 200 ); and (a) is a random value of (0.0, PI*2); and also the speed is a random value. So each time I run the sketch is a different type of shooting star wich is exactly what I want. But I would like to have that over and over without pressing play each time. This sound reeeally bad I know sorry, I 'm just new to it so I would like to undestand it better. Thank you Chrisir! :)
puuuh
ok, a is the angle, when a is
> TWO_PI
we want to start all oversince you set all vars before setup() when declaring them, I advice you to
have before setup() only
float a;
etc. etc.then have a new function reset where you say
a = random(0.0, PI*2);
etc. etc.without the float !!!!
now call
reset
fromsetup()
and when a is> TWO_PI
yeeeeesss! It is working now, thank you so much Chrisir! :)
great!