We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexDiscussionExhibition › simple dna rotate
Page Index Toggle Pages: 1
simple dna rotate (Read 1766 times)
simple dna rotate
Jul 13th, 2007, 9:52pm
 
simple example of dna rotating in space
not much else,

cheers,
Richard


import processing.opengl.*;

dna1 bar1;

void setup() {
 size(800, 600, OPENGL);

 background(50);
 //smooth();
 bar1 = new dna1(400, 100, 0, 50);
 //println(bar1);

 frameRate(60);
}

void mousePressed() {
  println("framerate");
  println(frameRate);
}

void draw() {

 background(50);  
 //noStroke();
 //println(bar1);
 bar1.draw ();
 //translate(30, 20);
 //sphere(10);
//rect(0, 0, 55, 55);
//translate(14, 14);
//rect(0, 0, 55, 55);
}

class dna1 {
 int x, y, z, xsize, ysize, zsize;

 float rotation = PI/15;
 boolean over;
 boolean locked;
 int loose;
 int newxpos, newypos;



 dna1(int x1, int y1, int z1, int xsize1) {
   //println("dna made");
   x = x1;
   y= y1;
   z= z1;
   xsize = xsize1;
   ysize = 10*30;
   
   newxpos = x1;
   newypos = y1;
   
   loose = 10;
   
 
 }

 public boolean isOver() {
   
   if (mouseX > x && mouseX < x+xsize && mouseY > y && mouseY < y+ysize)
     return true;
   else return false;
   
 }

 public void update() {
   
   if (rotation > (2*PI))
     rotation = 0;
   else
     rotation = rotation + (PI/frameRate);
     
   if (isOver())
     over = true;
   else
     over = false;
     
   //if (mousePressed && over)
   if (mousePressed)
     locked = true;
   
   if (!mousePressed)
     locked = false;
   
   if (locked) {
     newxpos = constrain(mouseX, 0, 800);
     newypos = constrain(mouseY, 0, 600);
   }
   
   if (abs(newxpos - x) > 1) {
     x = x + (newxpos-x)/loose;
     y = y + (newypos-y)/loose;
   }
   
     
 }



 public void draw() {
   //println("drawin");
   
   update();
   
   if (isOver() || locked)
     fill(255, 102, 0);
   else
     fill(255);
   
   noStroke();
   
   lights();
   
   translate(x, y, 0);
   
   rotateY(rotation);
   
   for (int i=1; i<30; i++) {
     
     translate(-xsize/2, 0, 0);
     box(5, 8, 8);
   
     translate(xsize/2, 0, 0);
     //
     box(xsize, 3, 10);
   
     translate(xsize/2, 0, 0);
     
     translate(-xsize/2, 0, 0);
     translate(0, 10, 0);
     
     rotateY(PI/11);
     
   }  
 }

}
Re: simple dna rotate
Reply #1 - Aug 19th, 2007, 12:35pm
 
There is a smiley in your code, so it wont run.
Can you repost it with no smiley ?

Actually, it works if I just replace the smiley with 10.

Not bad!
Re: simple dna rotate
Reply #2 - Aug 19th, 2007, 1:14pm
 
YaBB forum supports BBCode.
Re: simple dna rotate
Reply #3 - Sep 6th, 2007, 10:52am
 
nice
Page Index Toggle Pages: 1