Ciao 访客, welcome back to old school! :p
Dna myDna;void setup() { size(500, 500, P3D); myDna = new Dna();}void draw() { background(255); translate(width/2, height/2); rotateX(mouseY * 0.05); rotateY(mouseX * 0.05); myDna.display();}void DrawDna(int Y_) { pushMatrix(); translate(-50, Y_, 0); sphereDetail(4); sphere(10); popMatrix(); pushMatrix(); translate(50, Y_, 0); sphereDetail(4); sphere(10); popMatrix(); pushMatrix(); rotateY(PI/2); translate(0, Y_, 0); box(3, 3, 100); popMatrix();}class Dna { int totalAmount; float theta; Dna() { totalAmount = 20; theta = 0.0; } void display() { theta += 0.01; rotateX(theta); rotateY(theta); for (int i=0;i<totalAmount;i++) { DrawDna(i*30-height/2); rotateY(10); } }}
DNA dna;void setup() { size(600, 600, P3D); smooth(); frameRate(10); dna= new DNA();}void draw() { background(255); lights(); hint(ENABLE_OPENGL_4X_SMOOTH); translate(width/2, height/2); dna.update();}void drawhelix(int y) { pushMatrix(); translate(-60, y); sphereDetail(5); sphere(9); popMatrix(); pushMatrix(); translate(60, y); sphereDetail(5); sphere(9); popMatrix(); line(60, y, -60, y); }class DNA { int totalAmount; int randiansY; DNA() { //randiansY = 0; totalAmount = 20; } void update() { rotateY(mouseX/10); for (int i=0;i<totalAmount;i++) { drawhelix(i*30-height/2); rotateY(16); //randiansY ++; } }}
DNA [] myDNA = new DNA[20];void setup(){ size(400, 600, P3D); smooth(); for(int i=0;i<myDNA.length;i++){ myDNA[i] = new DNA(13, 3); }}void draw(){ background(0); lights(); translate(width/2, height/2); rotateX(radians((height/2 - mouseY)*0.6)); rotateY(radians((mouseX))); for (int i=0; i<myDNA.length;i++){ myDNA[i].display(50, 30*i, 30*i); //myDNA[i].update(); }}
class DNA { int sphereSize; int boxSize; DNA(int sSize, int bSize) { sphereSize = sSize; boxSize = bSize; } void display(float x_, float y_, float radian_) { pushMatrix(); rotateY(radians(radian_)); drawSphere(-x_, y_, color(255,0,0));//draw first sphere drawSphere(x_, y_, color(0,0,255));//draw second sphere drawBox(0, y_, x_*2, color(200,200,200));//draw box popMatrix(); } void drawSphere(float transX, float a, color color_) { pushMatrix(); translate(transX, -height/2+a); noStroke(); fill(color_); sphereDetail(8); sphere(sphereSize); popMatrix(); } void drawBox(float transX, float a, float length_, color color_) { pushMatrix(); translate(transX, -height/2+a); noStroke(); fill(color_); box(length_, boxSize, boxSize); popMatrix(); } }