thinkmine
YaBB Newbies
Offline
Posts: 15
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); } } }