We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › 3D sphere with two colors
Page Index Toggle Pages: 1
3D sphere with two colors? (Read 2263 times)
3D sphere with two colors?
Jan 3rd, 2008, 2:33am
 
How might I program a 3D sphere with two color halves. I am trying to develop a 3-Axis attitude gage like on an airplane, that shows roll, pitch and yaw.

The top half of the sphere is blue and bottom is green. The horizonal line (split between the two colors )is the horizon. I will over lay another horizontal line to match.

I greatly appreciate any assistance on the code.

Warmest regards,
Doyle
Re: 3D sphere with two colors?
Reply #1 - Jan 3rd, 2008, 8:22am
 
use a texture :
http://processing.org/reference/texture_.html
Re: 3D sphere with two colors?
Reply #2 - Jan 3rd, 2008, 1:27pm
 
You can use the surfaceLib library, which can handle all you needs. Creating a sphere and then adding an array of the colors you need for every horizontal stripe. Here is a small code example.

Quote:


import processing.opengl.*;

import surface.calculation.*;
import surface.*;

Sphere s;

void setup(){
 size(500,500, OPENGL);
 s=new Sphere(g, 51,51);
 int[] colors = new int[51];
 for(int i = 0; i<colors.length; i++){

   if(i < 25) {
     colors[i]=color(58, 102, 132);

   }
   if(i == 25) {
     colors[i]=color(125);
 
   }
   if(i > 25){
     colors[i]=color(102, 102, 0);

   }

 }
 s.initHorizontalColors(colors);

 noStroke();
 smooth();
 
}

void draw(){
 background(255);
 translate(width/2,height/2);
 rotateX(radians(frameCount));
 rotateY(radians(frameCount));
 s.setScale(mouseX);
 s.draw();
}



Or you to it like that and draw different parts of the sphere consecutively:

Quote:


import processing.opengl.*;
import surface.calculation.*;
import surface.*;

Sphere s;

void setup(){
 size(500,500, OPENGL);
 s=new Sphere(g, 51,51);
 noStroke();
 smooth();
}

void draw(){
 background(255);
 translate(width/2,height/2);
 rotateX(radians(frameCount));
 rotateY(radians(frameCount));
 s.setScale(mouseX);
 fill(58, 102, 132);
 s.drawPart(0,51,0,25);
 fill(125);
 s.drawPart(0,51,25,26);
 fill(102, 102, 0);
 s.drawPart(0,51,26,51);
}




Re: 3D sphere with two colors?
Reply #3 - Jan 4th, 2008, 2:24am
 
It appears that the code show errors at my end.

build23148.tmp/Temporary_9705_3441.java:1:62:1:80: Semantic Error: You need to modify your classpath, sourcepath, bootclasspath, and/or extdirs setup. Jikes could not find package "surface.calculation" in:

I am new to Processing and not sure how to fix this error.

Thanks,
Doyle
Re: 3D sphere with two colors?
Reply #4 - Jan 4th, 2008, 3:56pm
 
Ah ok, the surfaceLib is an additional library for processing. You have to download it here: http://www.eskimoblood.de/surfacelib/ . Copy the folder in your processingMainFolder/libaries folder and restart processing.
Re: 3D sphere with two colors?
Reply #5 - Jan 6th, 2008, 12:30am
 
Andreas,

  Thank you so much. This is perfect! You saved me many hours with the new library!

Regards,
Doyle
Re: 3D sphere with two colors?
Reply #6 - Apr 11th, 2010, 2:52am
 
Hi Guys.

Is it possible to make one half of the sphere semi transparent?  When I do this by just passing in an alpha value in the fill() statement, I get some pretty bad artifacting and corruption which I think is related to normals.  Does anyone know how to how to create a two coloured 3D sphere, with one half being (semi) transparent?

thanks
Jim
Re: 3D sphere with two colors?
Reply #7 - Apr 11th, 2010, 4:58am
 
you could add hint(ENABLE_DEPTH_SORT); in OPENGL mode to make it work correctly, but it really slows down your sketch. another way would be to use P3D, but you better turn of smooth for your sphere to make it look correct.



Code:

import processing.opengl.*;
import surface.calculation.*;
import surface.*;

Sphere s;

void setup(){
size(500,500, P3D);
s=new Sphere(g, 51,51);
noStroke();
// smooth();
//hint(ENABLE_DEPTH_SORT);
}

void draw(){
background(255);
translate(width/2,height/2);
rotateX(radians(frameCount));
rotateY(radians(frameCount));
s.setScale(mouseX);
fill(58, 102, 132,100);
s.drawPart(0,51,0,25);
fill(125);
s.drawPart(0,51,25,26);
fill(102, 102, 0);
s.drawPart(0,51,26,51);
}
Page Index Toggle Pages: 1