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 Kloonimine extends Applet { public Kloonimine() { 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.green), //eralduv new Color3f(Color.green), //peegelduv valgus new Color3f(Color.black), 1 //läige ); valimus.setMaterial(materjal); k1.setAppearance(valimus); Transform3D t2=new Transform3D(); t2.setTranslation(new Vector3f(0.5f, 0, 0)); TransformGroup tg2=new TransformGroup(t2); juur.addChild(tg2); Node k2=k1.cloneTree(); //Koonusest luuakse koopia juur.addChild(k1); tg2.addChild(k2); //koopia lisatakse isendipuusse juur.compile(); SimpleUniverse u = new SimpleUniverse(c); u.getViewingPlatform().setNominalViewingTransform(); u.addBranchGraph(juur); } public static void main(String[] args) { Frame f=new Frame("Roheline koonus"); f.add(new Kloonimine()); f.setSize(300, 300); f.setVisible(true); } }