Limit the range of rotate() ?
in
Programming Questions
•
1 year ago
Please bear with me, I'm struggling to figure out this particular aspect while also trying to figure out array and classes. So I may be a little mixed up. I've taken the example script from my class last night and modified it to use a line instead of ellipse and whatnot so I can simulate the star trek warp effect a little. However, as I want to condense all of the lines to just a certain range of the rotate(), I'm just plain stuck on how to do this. I plan to move the translate() off to the right side for a better warp effect and I would rather limit the rotate() effect to just the angles toward the viewport. This condense the array of 3000 lines within just those angles rather than spreading a little too thinly.
The yellow line is approximately where I want to limit the rotate() to. How can I go about this?
- Warp[] warps = new Warp[3000];
- int totalWarps=0;
- void setup() {
- size(400, 400);
- smooth();
- }
- class Warp {
- float x, y;
- float speed;
- float r;
- float t = random(1 , 10);
- Warp() {
- r=1;
- x=random(5);
- y = -r*4;
- speed=t;
- }
- void move() {
- y+=speed;
- }
- void display() {
- stroke(255, 150);
- strokeWeight(t);
- line(x, y, x, y-(10*t));
- }
- }
- void draw() {
- background(0);
- translate(width/2, height/2);
- //initialize totalDrops
- warps[totalWarps]= new Warp();
- //Increment totalDrops
- totalWarps++;
- //if we hit the end of the array
- if (totalWarps >= warps.length) {
- totalWarps = 0;
- }
- //move and display drops
- for (int i=0; i<totalWarps; i++) {
- rotate(i);
- warps[i].move();
- warps[i].display();
- }
- }
~~~
http://www.lost-ear-studio.com
1