一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

PHP教程|ASP.NET教程|Java教程|ASP教程|編程技術(shù)|正則表達(dá)式|C/C++|IOS|C#|Swift|Android|JavaScript|易語(yǔ)言|

服務(wù)器之家 - 編程語(yǔ)言 - Java教程 - java實(shí)現(xiàn)水波紋擴(kuò)散效果

java實(shí)現(xiàn)水波紋擴(kuò)散效果

2021-07-13 15:23gloomyfish Java教程

這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)水波紋擴(kuò)散效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

一、原理

模擬水波紋效果,最常見的是sine或者cosn的函數(shù),周期性變化,貼近自然。

當(dāng)水波紋中中間開始向四周擴(kuò)散的時(shí)候,一般都是慢慢的失去能量,振幅也是越來(lái)越小,所以程序要模擬這個(gè)過(guò)程時(shí)候,要加上一個(gè)能量遞減因子。然后用公式 y = a*sine(bx + c)來(lái)表示波紋公式。

二、程序?qū)崿F(xiàn)

最重要的一步是計(jì)算水波紋的振幅。在任意一點(diǎn)確定水波的中心位置,可以是鼠標(biāo)隨機(jī)選取,對(duì)半徑范圍內(nèi)的像素位置實(shí)現(xiàn)水波生成,然后轉(zhuǎn)換為位置,對(duì)位置實(shí)現(xiàn)浮點(diǎn)數(shù)取整,然后使用適當(dāng)?shù)牟逯邓惴ǎ纠褂秒p線性插值。

三、程序效果

java實(shí)現(xiàn)水波紋擴(kuò)散效果

四、濾鏡完全源代碼

這次我寫了些中文注解,不給源代碼的博文不是好博文

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package com.gloomyfish.filter.study;
 
import java.awt.image.bufferedimage;
 
public class waterfilter extends abstractbufferedimageop {
 private float wavelength = 16;
 private float amplitude = 10;
 private float phase = 0;
 private float centrex = 0.5f;
 private float centrey = 0.5f;
 private float radius = 50;
 
 private float radius2 = 0;
 private float icentrex;
 private float icentrey;
 
 public waterfilter() {
 
 }
 
 @override
 public bufferedimage filter(bufferedimage src, bufferedimage dest) {
 int width = src.getwidth();
  int height = src.getheight();
 
  if ( dest == null )
   dest = createcompatibledestimage( src, null );
 
  int[] inpixels = new int[width*height];
  int[] outpixels = new int[width*height];
  getrgb( src, 0, 0, width, height, inpixels );
 icentrex = width * centrex;
 icentrey = height * centrey;
 if ( radius == 0 )
 radius = math.min(icentrex, icentrey);
 radius2 = radius*radius;
  int index = 0;
  float[] out = new float[2];
  for(int row=0; row<height; row++) {
   for(int col=0; col<width; col++) {
   index = row * width + col;
   
   // 獲取水波的擴(kuò)散位置,最重要的一步
   generatewaterripples(col, row, out);
 int srcx = (int)math.floor( out[0] );
 int srcy = (int)math.floor( out[1] );
 float xweight = out[0]-srcx;
 float yweight = out[1]-srcy;
 int nw, ne, sw, se;
 
 // 獲取周圍四個(gè)像素,插值用,
 if ( srcx >= 0 && srcx < width-1 && srcy >= 0 && srcy < height-1) {
  // easy case, all corners are in the image
  int i = width*srcy + srcx;
  nw = inpixels[i];
  ne = inpixels[i+1];
  sw = inpixels[i+width];
  se = inpixels[i+width+1];
 } else {
  // some of the corners are off the image
  nw = getpixel( inpixels, srcx, srcy, width, height );
  ne = getpixel( inpixels, srcx+1, srcy, width, height );
  sw = getpixel( inpixels, srcx, srcy+1, width, height );
  se = getpixel( inpixels, srcx+1, srcy+1, width, height );
 }
 
 // 取得對(duì)應(yīng)的振幅位置p(x, y)的像素,使用雙線性插值
 /*if(xweight >=0 || yweight >= 0)
 {
  outpixels[index] = imagemath.bilinearinterpolate(xweight, yweight, nw, ne, sw, se); 
 }
 else
 {
  outpixels[index] = inpixels[index];
 }*/
 outpixels[index] = imagemath.bilinearinterpolate(xweight, yweight, nw, ne, sw, se);
   }
  }
 
  setrgb( dest, 0, 0, width, height, outpixels );
  return dest;
 }
 
 private int getpixel(int[] pixels, int x, int y, int width, int height) {
 if (x < 0 || x >= width || y < 0 || y >= height) {
 return 0; // 有點(diǎn)暴力啦,懶得管啦
 }
 return pixels[ y*width+x ];
 }
 
 protected void generatewaterripples(int x, int y, float[] out) {
 float dx = x-icentrex;
 float dy = y-icentrey;
 float distance2 = dx*dx + dy*dy;
 // 確定 water ripple的半徑,如果在半徑之外,就直接獲取原來(lái)位置,不用計(jì)算遷移量
 if (distance2 > radius2) {
 out[0] = x;
 out[1] = y;
 } else {
 // 如果在radius半徑之內(nèi),計(jì)算出來(lái)
 float distance = (float)math.sqrt(distance2);
 // 計(jì)算改點(diǎn)振幅
 float amount = amplitude * (float)math.sin(distance / wavelength * imagemath.two_pi - phase);
 // 計(jì)算能量損失,
 amount *= (radius-distance)/radius; // 計(jì)算能量損失,
 if ( distance != 0 )
 amount *= wavelength/distance;
 // 得到water ripple 最終遷移位置
 out[0] = x + dx*amount;
 out[1] = y + dy*amount;
 }
 }
 
}

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持服務(wù)器之家。

原文鏈接:https://blog.csdn.net/jia20003/article/details/13159535

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 亚洲妇熟xxxxx妇色黄 | 免费网站国产 | 污网站免费观看在线高清 | 日本嫩小xxxxhd | 国产欧美一区二区三区精品 | 特级一级全黄毛片免费 | 校花被强迫np肉高h 校服下的白嫩小乳尖h1v1 | 小草观看免费高清视频 | 亚欧日韩 | 香蕉久久ac一区二区三区 | 色综合天天网 | 欧美一区二区三区大片 | 色愉拍亚洲偷自拍 | 免费观看俄罗斯特黄特色 | 窝窝午夜精品一区二区 | 国产小视频在线免费观看 | 国内精品一区二区在线观看 | 日韩精品一区二区三区免费视频 | 大学生初次破苞免费视频 | 亚洲天堂影院在线观看 | 日韩一级片在线免费观看 | 草莓视频在线观看免费 | 午夜一区二区免费视频 | 男生的j桶女人屁免费视频 男生操男生 | 69成人影院 | 久久热这里面只有精品 | 日韩欧免费一区二区三区 | 日本精品久久久久中文字幕 1 | 91国内精品久久久久影院优播 | 3d欧美人禽交 | 国产一区二区三区四 | 好猛好紧好硬使劲好大刺激视频 | 午夜精品久久久久久久99蜜桃 | 午夜免费无码福利视频麻豆 | 97综合| 胸奶好大好紧好湿好爽 | 日本国产一区二区三区 | 女明星放荡高h日常生活 | 亚洲四虎 | 暖暖的视频完整视频韩国免费 | 91大神在线精品播放 |