We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi. I have to make a project to school in processing. It's ok but I have a problem. I have a menu so if I press '1' draw figure1 and if I press '2' draw figure 2. So I create a function mousePressed so if I press I = zoom in and O = zoom out. The figur zooming in or out but I don't rotate and translate it until I press 1,or 2 for refresh it.![1]
void figure()
{
if(key=='1')
{
background(103,105,111);
PFont font=loadFont("AnonymousPro-30.vlw");
fill(255);
text("H20",100,80);
drawSphere1();
var="one";
}
if(key=='2')
{
background(103,105,111);
PFont font=loadFont("AnonymousPro-30.vlw");
fill(255);
text("H2SO4",100,80);
drawSphere2();
var="two";
}
}
void drawSphere1() { transforms(); fill(255,0,0); sphere(60); fill(255); translate(40,40,30); sphere(60); translate(-80,0,-30); sphere(60); }
void transforms()
{
translate(tx,ty,tz);
noStroke();
rotateX(radians(rotationX));
rotateY(radians(rotationY));
rotateZ(radians(rotationZ));
scale(zoom);
rotationX=rotationX+velocityX;
rotationY=rotationX+velocityY;
rotationZ=rotationX+velocityZ;
velocityX =0.9;
velocityY *=0.9;
velocityZ *=0.9;
if(mousePressed)
{
if(mouseButton==LEFT)
{
velocityX=velocityX+(mouseY-pmouseY)0.05;
velocityY=velocityY-(mouseX-pmouseX)0.05;
velocityZ=velocityZ-(mouseX-pmouseX)0.05;
}
if(mouseButton==RIGHT)
{
tx=tx+(mouseX-pmouseX);
ty=ty+(mouseY-pmouseY);
tz=tz+(mouseY-pmouseY);
}
}
}
void keyPressed()
{
background(103,105,111);
if(key=='i')
{
if(var=="one")
drawSphere1();
else if(var=="two")
drawSphere2();
zoom=zoom+0.2;
}
if(key=='o')
{
if(var=="one")
drawSphere1();
else if(var=="two")
drawSphere2();
zoom=zoom-0.2;
}
}
Answers
Please format the code.
Runnable examples are better.
Load fonts in setup ().
Do you have a skype account,because I want to sent this project and I can explain