问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

求一个彩色3D分形山的MATLAB或Java或vb源程序

发布网友 发布时间:2022-08-19 23:40

我来回答

1个回答

热心网友 时间:2023-10-28 12:17

我这里有。要加分哦。兄弟。下面就是JAVA的源码:

// 3D painted fractal mountains, Evgeny Demidov 12 Oct 2001
import java.awt.*;
import java.awt.event.*;
import java.util.StringTokenizer;
public class MountainC extends java.applet.Applet
implements MouseListener, MouseMotionListener {
int n = 16, n1, h,w,h2,w2, mx0,my0, xPol[],yPol[], iCol[][][];
double rnd, fiX = .2, fiY = .3, dfi = .01, scale = .8, m20,m21,m22;
double vert[][][], vert1[][][], Norm[][][][], Norm1z[][][], M[];
Image buffImage; Graphics buffGraphics;
Color col[][];
boolean painted;

public void init(){
w = getSize().width; h = getSize().height; w2 = w/2; h2 = h/2;
String s=getParameter("N"); if (s != null) n = Integer.parseInt(s);
xPol = new int[3]; yPol = new int[3];
buffImage = createImage(w, h); buffGraphics = buffImage.getGraphics();
col = new Color[4][256];
for (int i = 0; i < 256; i++){
col[0][i] = new Color(0, 0, i);
col[1][i] = new Color(0, (i*220)/256, 0);
col[2][i] = new Color((i*150)/256, (i*150)/256, (i*50)/256);
col[3][i] = new Color(i, i, i);}
s = getParameter("bgColor"); if (s != null){
StringTokenizer st = new StringTokenizer(s);
int red = Integer.parseInt(st.nextToken());
int green = Integer.parseInt(st.nextToken());
int blue = Integer.parseInt(st.nextToken());
setBackground( new Color(red, green, blue));}
else setBackground(new Color(255,255,255));
addMouseListener(this);
addMouseMotionListener(this);
setup();
}

public double R(){ return rnd*(Math.random()-.5);}

public void setup(){
rnd = 1;
n1 = n+1;
iterate();
vert = new double[n1][n1][3]; vert1 = new double[n1][n1][2];
double dx = w/(double)n;
int t = 0;
for (int i = 0; i < n1; i++)
for (int j = 0; j < n1; j++){
vert[i][j][0] = dx*i - w2; vert[i][j][2] = dx*j - w2;
double mi = M[t++];
if (mi < 0) mi = .01*Math.random();
vert[i][j][1] = w*mi - w2/2;}
Norm = new double[n1][n1][2][3]; Norm1z = new double[n1][n1][2];
iCol = new int[n][n][2];
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++){
double s =
((vert[i][j][1] + vert[i+1][j][1] + vert[i+1][j+1][1])/3 + w2/2)/w;
if (s < .01) iCol[i][j][0] = 0;
else if (s+.1*Math.random() > .35) iCol[i][j][0] = 3;
else if (s+.1*Math.random() > .15) iCol[i][j][0] = 2;
else iCol[i][j][0] = 1;
s = ((vert[i][j][1] + vert[i][j+1][1] + vert[i+1][j+1][1])/3 + w2/2)/w;
if (s < .01) iCol[i][j][1] = 0;
else if (s+.1*Math.random() > .35) iCol[i][j][1] = 3;
else if (s+.1*Math.random() > .15) iCol[i][j][1] = 2;
else iCol[i][j][1] = 1;
Norm[i][j][0][0] = vert[i][j][1] - vert[i+1][j][1];
Norm[i][j][0][1] = dx;
Norm[i][j][0][2] = vert[i+1][j][1] - vert[i+1][j+1][1];
double mod = Math.sqrt(Norm[i][j][0][0]*Norm[i][j][0][0] + Norm[i][j][0][1]*
Norm[i][j][0][1] + Norm[i][j][0][2]*Norm[i][j][0][2]) / 255.5;
Norm[i][j][0][0] /= mod; Norm[i][j][0][1] /= mod; Norm[i][j][0][2] /= mod;
Norm[i][j][1][0] = vert[i][j+1][1] - vert[i+1][j+1][1];
Norm[i][j][1][1] = dx;
Norm[i][j][1][2] = vert[i][j][1] - vert[i][j+1][1];
mod = Math.sqrt(Norm[i][j][1][0]*Norm[i][j][1][0] + Norm[i][j][1][1]*
Norm[i][j][1][1] + Norm[i][j][1][2]*Norm[i][j][1][2]) / 255.5;
Norm[i][j][1][0] /= mod; Norm[i][j][1][1] /= mod; Norm[i][j][1][2] /= mod;}
rotate();
}

public void iterate(){
int nc=n, Max=n1*n1, ncn1;
double Min=-1;
M = new double[Max];
for (int i=n+2; i < n*n1-1; i++) M[i] = Min;
for (int i=2*n1; i < n*n1; i += n1) M[i] = M[i-1] = 0;
while ( (nc /= 2) >= 1){
ncn1 = nc*n1;
for (int j=ncn1; j < Max; j += ncn1+ncn1){
for (int i= nc; i < n; i += nc+nc){
if (M[i+j]==Min)
M[i+j] = (M[i+j+nc-ncn1] + M[i+j-nc+ncn1])/2.+R();
if (M[i+j+nc]==Min)
M[i+j+nc] = (M[i+j+nc+ncn1] + M[i+j+nc-ncn1])/2.+R();
if (M[i+j+ncn1]==Min)
M[i+j+ncn1] = (M[i+j-nc+ncn1] + M[i+j+nc+ncn1])/2.+R(); }}
rnd /= 2.;}
}

public void destroy() {
removeMouseListener(this);
removeMouseMotionListener(this);
}
public void mouseClicked(MouseEvent e){} // event handling
public void mousePressed(MouseEvent e) {
mx0 = e.getX(); my0 = e.getY();
if ( e.isControlDown() ){
setup();
repaint();}
if ( e.isAltDown() ){
if ( e.isShiftDown() ){ n /= 2; if (n < 1) n = 1;}
else n *= 2;
setup();
repaint();}
e.consume();
}
public void mouseReleased(MouseEvent e){}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
public void mouseDragged(MouseEvent e) {
int x1 = e.getX(); int y1 = e.getY();
if ( e.isShiftDown() ) scale *= Math.exp(-(y1 - my0)/(double)w);
else fiX += dfi*(y1 - my0);
fiY += dfi*(x1 - mx0); mx0 = x1; my0 = y1;
rotate();
repaint();
e.consume();
}

public void rotate(){
double ct = Math.cos(fiX), cf = Math.cos(fiY),
st = Math.sin(fiX), sf = Math.sin(fiY),
m00 = scale*cf, m02 = scale*sf,
m10 = scale*st*sf, m11 = scale*ct, m12 = -scale*st*cf;
m20 = -ct*sf; m21 = st; m22 = ct*cf;
for (int i = 0; i < n1; i++)
for (int j = 0; j < n1; j++){
vert1[i][j][0] = m00*vert[i][j][0] + m02*vert[i][j][2];
vert1[i][j][1] = m10*vert[i][j][0] + m11*vert[i][j][1] + m12*vert[i][j][2];}
for (int i = 0; i < n; i++)
for (int j = 0; j < n; j++)
for (int k = 0; k < 2; k++)
Norm1z[i][j][k] = m20*Norm[i][j][k][0] + m21*Norm[i][j][k][1] +
m22*Norm[i][j][k][2];
painted = false;
}

public void mouseMoved(MouseEvent e) {}

public void paint(Graphics g) {
if ( !painted ){
buffGraphics.clearRect(0, 0, w, h);
int ib=0, ie=n, sti=1, jb=0, je=n, stj=1;
if (m20 < 0){ ib = n; ie = -1; sti = -1;}
if (m22 < 0){ jb = n; je = -1; stj = -1;}
for (int i = ib; i != ie; i += sti)
for (int j = jb; j != je; j += stj){
if (Norm1z[i][j][0] > 0){
xPol[0] = w2 + (int)vert1[i][j][0];
xPol[1] = w2 + (int)vert1[i+1][j][0];
xPol[2] = w2 + (int)vert1[i+1][j+1][0];
yPol[0] = h2 - (int)vert1[i][j][1];
yPol[1] = h2 - (int)vert1[i+1][j][1];
yPol[2] = h2 - (int)vert1[i+1][j+1][1];
buffGraphics.setColor(col[iCol[i][j][0]][(int)(Norm1z[i][j][0])]);
buffGraphics.fillPolygon(xPol,yPol, 3);}
if (Norm1z[i][j][1] > 0){
xPol[0] = w2 + (int)vert1[i][j][0];
xPol[1] = w2 + (int)vert1[i][j+1][0];
xPol[2] = w2 + (int)vert1[i+1][j+1][0];
yPol[0] = h2 - (int)vert1[i][j][1];
yPol[1] = h2 - (int)vert1[i][j+1][1];
yPol[2] = h2 - (int)vert1[i+1][j+1][1];
buffGraphics.setColor(col[iCol[i][j][1]][(int)(Norm1z[i][j][1])]);
buffGraphics.fillPolygon(xPol,yPol, 3);} }
painted = true;}
g.drawImage(buffImage, 0, 0, this);
showStatus( "n=" + n);
}
public void update(Graphics g){ paint(g); }

}
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
什么是Medical Literature Analysis and Retrieval System (NLM)的缩 ... 医学工作者的因特网内容简介 2002年的一篇文章英文摘要被《医学文献联机数据库》(MEDLINE)收录,是否... 医学器具medline啥意思 民国市与县的关系是怎样的,市与县分别又是什么? 历代兵制中国民国兵制 冰箱运行时有水流声怎么回事? ud牛郎眼影真假判断 爆闪/没有平替❌ 牛郎眼影真假鉴别方法 鉴别❗️衰败城市牛郎眼影真假,粉质肉眼差距 同花顺空中加油买卖提示公式怎么编 神州屏式电脑M20 D1无线网卡什么型号哪里下驱动 c语言程序,帮我看看错在哪里了? 华为招非全日制本科吗 华为校招高校档次划分:华为公司最低学历要求?附华为校招高校名单 三角恋吧,两男一女 飞机票我选完座位了,却显示未选座,但是点进去就显示我的客票状态是 我在拼多多上购买商品,当时按照订单价格下单,接单,第二天商家要我追加差价,不? 用什么方法把水泥粘到木板上,400多平米的木板栅栏,想弄一层水泥上去,不知道用什么方法。 木板上的水泥怎么办? 木板上有水泥.怎样能弄掉&gt; 害怕工作 害怕接触社会 不敢面试 不敢工作不想工作不想接触社会害怕人际关系 我要怎么办 不想上班就想宅在家里不想接触人感觉很自卑怎么办 不想接触社会怎么办 我不想上班,也不想去接触这个社会该怎么办 安检现场防爆桶防爆毯等辅助器材应处于什么 公司发劳保用品,帮老板娘问问一般公司都发哪些劳保用品 一斤苦瓜泡多少酒 我发微信说了很多,可对方发流汗的表情,是什么意思? 梦幻HS怎么加点最好? 3d里面渲染为什么会出现很强的光影,求高手解答,ps我的3d是2012的~ 3D渲染为什么天花有光影 3d光影布膜广告是什么广告? 3D渲染时出现光影跟踪信息问题 heavy英语单词怎么读 写汉语! 农商银行可以办ETC吗 赤芍的功效与作用 赤芍和白芍有何区别 苏宁易购如何防止牛鞭效应的? 怎么申请新的 注册一个新的怎么注册 《火影忍者》中的须佐能乎(スサノオ)怎么念? 梦华录周几更新 梦华录多久更新 怎样注册新 怎么申请注册新账号 申请新怎么申请? 暖宫石是什么石头? 梦见弟弟穿着红裤头 宝宝两岁,前面四个牙齿都烂了,怎么办