text cutting-off and changing sketch colours.
in
Programming Questions
•
2 years ago
hi,
i have named one of the spheres, but the top of the text looks cut off; ideas why?
Also i think i've got ordering of code wrong, as when i change colour of text it changes colour of spheres...
j
- boolean over1 = false;
- boolean selected1 = false;
- boolean over2 = false;
- boolean selected2 = false;
- int pos1X, pos1Y,pos2X,pos2Y;
- int offset1X, offset1Y,offset2X,offset2Y;
- float radius = 22.0f;
- void setup()
- {
- size(512, 512,P3D);
- textFont (createFont ("SanSerif",12));
- pos1X = width/2-50;
- pos1Y = height/2;
- pos2X = width/2+50;
- pos2Y = height/2;
- smooth();
- noStroke();
- lights();
- textSize (11);
- textAlign (CENTER,CENTER);
- }
- void draw()
- {
- background(0);
- ambientLight(20, 20, 20);
- directionalLight(255,155,40, -1, 0.5, -0.8);
- pushMatrix();
- translate (pos1X,pos1Y,0);
- sphere (radius);
- fill (255,30,80);
- popMatrix ();
- {
- float valP = map(pos1X, 0, width, -1, 1);
- float valG = map(pos1Y, 0, height, 6, -48);
- pushMatrix();
- translate (pos2X,pos2Y,0);
- sphere (radius);
- fill (255,129,100);
- text("Globe1",5,40,radius-20);
- popMatrix();
- valP = map(pos2X, 0, width, -1, 1);
- valG = map(pos2Y, 0, height, 6, -48);
- }
- {
- }
- }
- void stop()
- {
- }
- void mouseMoved() {
- over1 = false;
- if (sqrt(sq(mouseX-pos1X)+sq(mouseY-pos1Y))<=radius) {
- over1 = true;
- }
- over2 = false;
- if (sqrt(sq(mouseX-pos2X)+sq(mouseY-pos2Y))<=radius) {
- over2 = true;
- }
- }
- void mousePressed() {
- if (over1) {
- selected1 = true;
- offset1X = pos1X-mouseX;
- offset1Y = pos1Y-mouseY;
- }
- if (over2) {
- selected2 = true;
- offset2X = pos2X-mouseX;
- offset2Y = pos2Y-mouseY;
- }
- }
- void mouseReleased() {
- selected1 = false;
- selected2 = false;
- }
- void mouseDragged()
- {
- if (selected1) {
- pos1X = max(0,min(mouseX+offset1X,width));
- pos1Y = max(0,min(mouseY+offset1Y,height));
- }
- if (selected2) {
- pos2X = max(0,min(mouseX+offset2X,width));
- pos2Y = max(0,min(mouseY+offset2Y,height));
- }
- }
1