Camera movement problem
in
Programming Questions
•
3 years ago
Hi there,
I hope someone can help me on this project! Its giving me a headache!
I understand that the nature of processing means that if you move the camera position, you must redraw everything.
My problem is that I am generating a line that extends and occasionally splits off and changes course and i want the camera to always slowly be zooming out so that the content always fits the window. But ofcourse, when i move the camera, it messes up what the drawing..
Here's my sketch so far, any help would be greatly appreciated!
- import processing.opengl.*;
- Spiral[] mySpirals;
- int xpos = 0;
- int ypos = 0;
- int spiralcount = 0;
- int direction = 0;
- void setup() {
- size(800,600,OPENGL);
- background(255);
- smooth();
- xpos = width/2;
- ypos = height;
- mySpirals = new Spiral[10];
- for(int i = 0; i < 10; i++)
- {
- mySpirals[i] = new Spiral();
- }
- }
- void draw(){
- noStroke();
- fill(0);
- ellipse(xpos, ypos, 16, 16);
- ypos -= 1;
- for(int i = 0; i < 10; i++)
- {
- if(mySpirals[i].done==true)
- mySpirals[i].drawit();
- }
- }
- void mouseClicked() {
- mySpirals[spiralcount].ypostart = ypos;
- mySpirals[spiralcount].done=true;
- spiralcount++;
- if(direction==0){direction=1;}else{direction=0;}
- }
- class Spiral{
- float r = 60;
- float theta = 0;
- float lt = 16;
- float cize = random(0.2, 4);
- float direction = int(random(0,2));
- int ypostart = 0;
- boolean done = false;
- void drawit() {
- //println(direction);
- if(lt>0){
- // Polar to Cartesian conversion
- float x = 0;
- if(direction==1){
- x = r * cos(theta)*cize;} //change to a minus + add60*cizeinstead of minus below to flip
- if(direction==0){
- x = r * -cos(theta)*cize;}
- float y = r * sin(theta)*cize;
- // Draw an ellipse at x,y
- noStroke();
- fill(0);
- if(direction==1){
- ellipse(x+width/2-(60*cize), y+ypostart, lt, lt);}
- if(direction==0){
- ellipse(x+width/2+(60*cize), y+ypostart, lt, lt);}
- // Decrement the angle
- theta -= 0.02;
- // Deccrement the radius
- r -= 0.1;
- //Decrement the thickness
- lt -= 0.03;
- //println(r);
- }else{
- done = true;
- }
- }
- }
1