sc2.rar

  • PUDN用户
    了解作者
  • Java
    开发工具
  • 4KB
    文件大小
  • rar
    文件格式
  • 0
    收藏次数
  • 1 积分
    下载积分
  • 7
    下载次数
  • 2005-08-23 22:29
    上传日期
利用2D图形显示3D的效果.这个是一个旋转的圆锥体,虽然边缘的显示效果不是很好,不过很有三维的感觉
sc2.rar
  • www.pudn.com.txt
    218B
  • SC2.html
    112B
  • SC2.java.bak
    4KB
  • SC2.class
    3.2KB
  • SC2.java
    4.1KB
内容介绍
import java.awt.Color; import java.awt.Graphics; import java.awt.Image; import java.io.Serializable; public class SC2 extends java.applet.Applet implements Serializable { private Graphics offScreenBuffer=null; private Image offScreenImage=null; private int width=800; private int height=500; private int basePointX=200; private int basePointY=200; private int maxCount=200; private int rectangleWidth=512; private int rectangleHeight=384; private int eHeight=rectangleHeight/2; private int eWidth=eHeight/8; private int rVal=0; private int gVal=0; private int bVal=0; private int iTheta=0; private int wedgeCount=8; private double currX=0; private int[] wedgeAngle=new int [wedgeCount]; private Color[] wedgeColors={Color.red,Color.green,Color.blue,Color.yellow, Color.magenta,Color.white,Color.darkGray}; public SC2() { }; public void init() { offScreenImage=this.createImage(width,height); offScreenBuffer=offScreenImage.getGraphics(); initializeWedges(); } public void initializeWedges() //用来对每个椭圆弧形的角度进行初始化 { for(int w=0;w<wedgeCount;w++) { wedgeAngle[w]=w*360/wedgeCount; } } public void update(Graphics gc) { paint(gc); } public void paint(Graphics gc) { offScreenBuffer.setColor(Color.lightGray); offScreenBuffer.fillRect(0,0,width,height); for(int tick=0;tick<maxCount;tick++) { drawEllipseGradient(offScreenBuffer,gc,tick); } //gc.drawImage(offScreenImage,0,0,this); } public void drawEllipseGradient(Graphics gc,Graphics gcMain,int count) //重复绘制具有旋转效果的柱面体图形 { for(int currY=-rectangleHeight/2;currY<rectangleHeight/2;currY++) { gc.setColor(Color.lightGray); gc.fillRect(0,0,width,height); colorOne(gc,currY,rectangleHeight/2,count); colorTwo(gc,-rectangleHeight/2,currY,count); drawWedges(gc); gcMain.drawImage(offScreenImage,0,0,this); } } public void drawWedges(Graphics gc) //用来绘制一组椭圆弧形 { if(--iTheta<-360){iTheta=0;} for(int w=0;w<wedgeCount;w++) { gc.setColor(wedgeColors[w%6]); gc.fillArc(basePointX-eWidth/2,basePointY-eHeight/2, eWidth,eHeight,wedgeAngle[w]+iTheta,360/wedgeCount); } } public void colorOne(Graphics gc,int startY,int endY,int count) { rVal=0; gVal=0; bVal=0; double currX=0; for(int currY=startY;currY<endY;currY++) { if(count%2==0) { rVal=(currY+rectangleHeight/2)*255/rectangleHeight; } else { gVal=(currY+rectangleHeight/2)*255/rectangleHeight; } currX=calculateEllipseXValue(currY); gc.setColor(new Color(rVal,gVal,bVal)); if(currY<0) { gc.drawArc(basePointX, basePointY+currY, rectangleWidth, -currY, 180, 90); } else { gc.drawArc(basePointX, basePointY, rectangleWidth, currY, 90, 90); } } } public double calculateEllipseXValue(int y) //根据点Y的坐标来计算对应椭圆点的坐标值 { double result=0; double offsetX1=0; double offsetX2=0; offsetX1=(eHeight/2)*(eHeight/2)-y*y; offsetX2=offsetX1*eWidth/(2*eHeight); result=Math.sqrt(offsetX2); return(result); } public void colorTwo(Graphics gc,int startY,int endY,int count) { double currX=0; rVal=0; gVal=0; bVal=0; for(int currY=startY;currY<endY;currY++) { if(count%2==0) { gVal=(currY+rectangleHeight/2)*255/rectangleHeight; } else { rVal=(currY+rectangleHeight/2)*255/rectangleHeight; } currX=calculateEllipseXValue(currY); gc.setColor(new Color(rVal,gVal,bVal)); if(currY<0) { gc.drawArc(basePointX, basePointY+currY, rectangleWidth, -currY, 180, 90); } else { gc.drawArc(basePointX, basePointY, rectangleWidth, currY, 90, 90); } } } }
评论
    相关推荐