import java.applet.Applet; import java.awt.*; import com.sun.j3d.utils.geometry.*; import com.sun.j3d.utils.universe.SimpleUniverse; import javax.media.j3d.*; import javax.vecmath.*; public class Varvimuutus extends Applet { public Varvimuutus() { setLayout(new BorderLayout()); Canvas3D c = new Canvas3D(SimpleUniverse.getPreferredConfiguration()); add(c, BorderLayout.CENTER); BranchGroup juur = new BranchGroup(); Cone k1=new Cone(); Appearance valimus=new Appearance(); Material materjal=new Material( new Color3f(Color.black), //hajuvalgus new Color3f(Color.black), //eralduv new Color3f(Color.red), //peegelduv valgus new Color3f(Color.black), 1 //läige ); materjal.setCapability(Material.ALLOW_COMPONENT_WRITE); valimus.setMaterial(materjal); k1.setAppearance(valimus); DirectionalLight suundvalgus=new DirectionalLight(); suundvalgus.setInfluencingBounds(new BoundingSphere()); juur.addChild(suundvalgus); ColorInterpolator varvimuutja=new ColorInterpolator(new Alpha(-1, 2000), materjal, new Color3f(Color.red), new Color3f(Color.green)); varvimuutja.setSchedulingBounds(new BoundingSphere()); juur.addChild(varvimuutja); juur.addChild(k1); juur.compile(); SimpleUniverse u = new SimpleUniverse(c); u.getViewingPlatform().setNominalViewingTransform(); u.addBranchGraph(juur); } public static void main(String[] args) { Frame f=new Frame("Värvi muutev koonus"); f.add(new Varvimuutus()); f.setSize(300, 300); f.setVisible(true); } }