Systeme sys; void setup(){ size(600,400); background(0,19,55); sys=new Systeme(); } void loop(){ sys.afficher(); } //////////////////////////////////////////////////// // CLASSE SYSTEME //////////////////////////////////////////////////// class Systeme{ Helice vrille1,vrille2,vrille3; Camera lacamera; Vecteur lumiere; float ty,deforme; public Systeme(){ this.lumiere=new Vecteur(-100,10,70); this.lacamera=new Camera(); this.ty=0; this.deforme=10; lumiere.normer(); this.vrille1=new Helice(550,1200,new Vecteur(0,0,0),lumiere); } void afficher(){ clear(); push(); deforme+=((-mouseX+width)/30-deforme)/20; ty+=(mouseY/50-ty)/10; rotateZ(ty); float lx=objectX(6000,0,0); float ly=objectY(6000,0,0); float lz=objectZ(6000,0,0); pop(); Vecteur lookhere=new Vecteur(500,900,3000); Vecteur positionRepere=new Vecteur(lx,ly,lz); lacamera.placercamera(positionRepere,lookhere,deforme/10); vrille1.dessiner(0,TWO_PI*15,deforme); } } //////////////////////////////////////////////////// // CLASSE CAMERA //////////////////////////////////////////////////// class Camera{ float fov, oeilX, oeilY,oeilZ, lookX, lookY,lookZ, oeilDist, nearDist, farDist, aspect; public Camera(){ fov = 60; oeilX = 0; oeilY = 0; oeilZ=0; oeilDist = 6000; nearDist = oeilDist / 10.0f; farDist = oeilDist * 10.0f; aspect = (float)width / (float)height; } void placercamera(Vecteur pos,Vecteur look,float rotz){ beginCamera(); perspective(fov, aspect, nearDist, farDist); lookat(pos.x ,pos.y , pos.z , look.x , look.y , look.z , sin(rotz) , cos(rotz),0 ); endCamera(); } } //////////////////////////////////////////////////// // CLASSE HELICE //////////////////////////////////////////////////// class Helice { float pas,temps,inctemps ,inct,rayon,plat; Position pos; Vecteur position0,coul1,coul2,c1,c2,ci,aci,ac1,ac2,lumiere; public Helice(float pas,float rayon,Vecteur position0,Vecteur lumiere){ this.coul1=new Vecteur(250,255,0); this.coul2=new Vecteur(135,150,250); this.position0=position0; this.pas=pas; this.temps=0; this.rayon=rayon; this.lumiere=lumiere; this.plat=rayon/10; this.inctemps=PI/10; this.inct=inctemps/10; this.pos=new Position(pas,rayon,position0); } void dessiner(float debut,float fin,float deforme){ noStroke(); temps+=inctemps;if(temps>PI*10||temps<0) inctemps*=-1; push(); ac1=pos.calc(debut-inct,1,deforme);//+temps ac2=pos.calc(debut+TWO_PI-inct,1,deforme); aci=pos.calc(debut-inct,0.55,deforme); for(float i = debut ; i<=fin; i+=inct){//+temps c1=pos.calc(i,1,deforme); c2=pos.calc(i+TWO_PI,1,deforme); ci=pos.calc(i,0.55,deforme); float pasz=(ac2.z-ac1.z)/2; beginShape(QUAD_STRIP); float col=scalcouleur(c1,c2,ci,plat,-plat+pasz); Vecteur col1=coul1.multiplier(col); fill(255-col1.x,col1.y,col1.z); vertex(ac1.x,ac1.y,ac1.z+plat); vertex(c1.x,c1.y,c1.z+plat); vertex(ci.x,ci.y,ci.z-plat+pasz); vertex(aci.x,aci.y,aci.z-plat+pasz); col=scalcouleur(aci,ci,ci,-plat+pasz,plat+pasz); col1=coul2.multiplier(col); fill(255-col1.x,col1.y,255-col1.z); vertex(aci.x,aci.y,aci.z+plat+pasz); vertex(ci.x,ci.y,ci.z+plat+pasz); col=scalcouleur(aci,ci,c2,plat+pasz,-plat); col1=coul1.multiplier(col); fill(col1.x,col1.y,col1.z); vertex(c2.x,c2.y,c2.z-plat); vertex(ac2.x,ac2.y,ac2.z-plat); endShape(); beginShape(QUAD_STRIP); col=scalcouleur(ac2,c2,c2,-plat,plat); col1=coul2.multiplier(col); fill(255-col1.x,255-col1.y,255-col1.z); vertex(c2.x,c2.y,c2.z-plat); vertex(ac2.x,ac2.y,ac2.z-plat); vertex(ac2.x,ac2.y,ac2.z+plat); vertex(c2.x,c2.y,c2.z+plat); endShape(); aci=ci; ac1=c1; ac2=c2; } pop(); } public float scalcouleur(Vecteur v1,Vecteur v2,Vecteur vi,float pl,float pin){ Vecteur tang=v2.soustraire(v1,pl,pl); Vecteur norm=vi.soustraire(v1,pl,pin); Vecteur ortho=norm.produitvectoriel(tang);ortho.normer(); return ortho.produitscalaire(lumiere);} } //////////////////////////////////////////////////// // CLASSE POSITION //////////////////////////////////////////////////// static class Position{ float rayon,pas; Vecteur position0,coordi,vnormal,coord; public Position(float p,float r,Vecteur v){ this.pas=p; this.rayon=r; this.position0=v; } public Vecteur calc(float tt,float cor,float deform){ coord=new Vecteur(); coord.x= position0.x+rayon*cor*(float)(Math.cos(tt))*(float)(1.5+Math.cos(tt/10)); coord.y= position0.y+rayon*cor*(float)Math.sin(tt)*(float)(1.5+Math.cos(tt/deform)); coord.z=position0.z+pas*tt/TWO_PI; return coord;} public Vecteur vnormal(float tt){ Vecteur vn=new Vecteur(0,0,0); vn.x= -(float)Math.cos(tt); vn.y=-(float)Math.sin(tt); vn.z=0; vn.normer(); return vn; } } //////////////////////////////////////////////////// // CLASSE VECTEUR //////////////////////////////////////////////////// static class Vecteur{ float x,y,z; Vecteur(float x1,float y1,float z1){ this.x=x1; this.y=y1; this.z=z1; } Vecteur(){x=0;y=0;z=0;} void normer(){ float lg=(float) Math.sqrt(x*x+y*y+z*z); if(lg!=0) { x/=lg;y/=lg; z/=lg;} } Vecteur anguler(){ float alfa=(float) Math.atan2(y,x); float beta=(float) Math.atan2(z,Math.sqrt(x*x+y*y)); return (new Vecteur(0,beta,alfa)); } float produitscalaire(Vecteur v){ return x*v.x+y*v.y+z*v.z;} Vecteur produitvectoriel(Vecteur w){ Vecteur p=new Vecteur(0,0,0); p.x=y*w.z-w.y*z; p.y=z*w.x-w.z*x; p.z=x*w.y-w.x*y; return p; } Vecteur multiplier(float m){ Vecteur res=new Vecteur(); m=(float) ((m*m)/(Math.sqrt(m*m/1.27+0.3))); res.x=(x*m)%255; res.y=(y*m)%255; res.z=(z*m)%255; return res; } Vecteur soustraire(Vecteur v,float dd,float ee){ Vecteur res=new Vecteur(); res.x=x-v.x; res.y=y-v.y; res.z=z-v.z+ee-dd; return res;} }