線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:4711
推到 Plurk!
推到 Facebook!

爪哇或Java S c r i p t的原始碼轉成Delphi

缺席
stacker_liew
中階會員


發表:59
回覆:168
積分:65
註冊:2004-05-17

發送簡訊給我
#1 引用回覆 回覆 發表時間:2014-12-20 12:18:10 IP:183.171.xxx.xxx 訂閱
編輯記錄
stacker_liew 重新編輯於 2014-12-20 12:23:02, 註解 無‧
stacker_liew
中階會員


發表:59
回覆:168
積分:65
註冊:2004-05-17

發送簡訊給我
#2 引用回覆 回覆 發表時間:2014-12-20 12:24:57 IP:183.171.xxx.xxx 訂閱

===================引 用 stacker_liew 文 章===================

請版主幫我叫回這篇出來,我編輯文章時不小心按錯了。

aftcast
站務副站長


發表:81
回覆:1485
積分:1763
註冊:2002-11-21

發送簡訊給我
#3 引用回覆 回覆 發表時間:2014-12-20 16:13:20 IP:49.219.xxx.xxx 訂閱
沒辨法恢復,不是不願意!還麻煩你重發文吧。謝謝。
------


蕭沖
--All ideas are worthless unless implemented--

C++ Builder Delphi Taiwan G+ 社群
http://bit.ly/cbtaiwan
stacker_liew
中階會員


發表:59
回覆:168
積分:65
註冊:2004-05-17

發送簡訊給我
#4 引用回覆 回覆 發表時間:2014-12-21 12:40:54 IP:183.171.xxx.xxx 訂閱
請問有沒有人可以把爪哇或JavaS c r i p t版的原始碼翻成Delphi嗎?

爪哇版:

[CODE]
import java.applet.*;
import java.net.URL;
import java.net.MalformedURLException;
import java.awt.*;

//==============================================================================
// Main Class for applet Lake
//
//==============================================================================
public class Lake extends Applet implements Runnable
{
// THREAD SUPPORT:
// m_Lake is the Thread object for the applet
//--------------------------------------------------------------------------
Thread m_Lake = null;

// ANIMATION SUPPORT:
// m_Graphics used for storing the applet's Graphics context
// m_WaveGraphics used for storing the animation's Graphics context
// m_Image the original image
// m_WaveImage the image containing the wave animations
// m_nCurrImage the index of the next image to be displayed
// m_ImgWidth width of each image
// m_ImgHeight height of each image
// m_OvlWidth width of each overlay
// m_OvlHeight height of each overlay
// m_fAllLoaded indicates whether all images have been loaded
// m_tAnimate indicates that OK to do animation (changed by mouse
// click)
// NUM_FRAMES number of NUM_FRAMES used in the animation
//--------------------------------------------------------------------------
private Graphics m_Graphics, m_WaveGraphics;
private Image m_Image, m_Overlay, m_WaveImage;
private int m_nCurrImage;
private int m_nImgWidth = 0;
private int m_nImgHeight = 0;
private int m_nOvlWidth = 0;
private int m_nOvlHeight = 0;
private boolean m_fAllLoaded = false, m_tAnimate = true;
private final int NUM_FRAMES = 12;

// PARAMETER SUPPORT:
// Parameters allow an HTML author to pass information to the applet;
// the HTML author specifies them using the tag within the <APPLET><br /> // tag. The following variables are used to store the values of the
// parameters.
//--------------------------------------------------------------------------

// Members for applet parameters
// =
//--------------------------------------------------------------------------
private String m_ImageName = "";
private String m_OverlayName = "";
private URL m_HRef;
private String m_Frame = "_self";

// Parameter names. To change a name of a parameter, you need only make
// a single change. Simply modify the value of the parameter string below.
//--------------------------------------------------------------------------
private final String PARAM_image = "image";
private final String PARAM_overlay = "overlay";
private final String PARAM_href = "href";
private final String PARAM_target = "target";

// Lake Class Constructor
//--------------------------------------------------------------------------
public Lake()
{
// TODO: Add constructor code here
}

// APPLET INFO SUPPORT:
// The getAppletInfo() method returns a string describing the applet's
// author, copyright date, or miscellaneous information.
//--------------------------------------------------------------------------
public String getAppletInfo()
{
return "Name: Lake v3.0\r\n"
"Author: David Griffiths\r\n"
"Created with Microsoft Visual J Version 1.0";
}

// PARAMETER SUPPORT
// The getParameterInfo() method returns an array of strings describing
// the parameters understood by this applet.
//
// Lake Parameter Information:
// { "Name", "Type", "Description" },
//--------------------------------------------------------------------------
public String[][] getParameterInfo()
{
String[][] info =
{
{ PARAM_image, "String", "JPG or GIF file to reflect" },
{ PARAM_overlay, "String", "JPG or GIF file to use as overlay" },
{ PARAM_href, "URL", "URL to link to" },
{ PARAM_target, "String", "Target frame" },
};
return info;
}

// The init() method is called by the AWT when an applet is first loaded or
// reloaded. Override this method to perform whatever initialization your
// applet needs, such as initializing data structures, loading images or
// fonts, creating frame windows, setting the layout manager, or adding UI
// components.
//--------------------------------------------------------------------------
public void init()
{
// PARAMETER SUPPORT
// The following code retrieves the value of each parameter
// specified with the tag and stores it in a member
// variable.
//----------------------------------------------------------------------
String param;

// image: JPG of GIF file to reflect
//----------------------------------------------------------------------
param = getParameter(PARAM_image);
if (param != null)
m_ImageName = param;

// overlay: JPG of GIF file to use as overlay
//----------------------------------------------------------------------
param = getParameter(PARAM_overlay);
if (param != null)
m_OverlayName = param;

// href: URL to link to
//----------------------------------------------------------------------
param = getParameter(PARAM_href);
if (param != null)
try
{
m_HRef = new URL(getDocumentBase(), param);
}
catch (MalformedURLException e)
{
getAppletContext().showStatus("Bad URL: " param);
return;
}

// target: Target frame
//----------------------------------------------------------------------
param = getParameter(PARAM_target);
if (param != null)
m_Frame = param;
}

// Place additional applet clean up code here. destroy() is called when
// when you applet is terminating and being unloaded.
//-------------------------------------------------------------------------
public void destroy()
{
// TODO: Place applet cleanup code here
}

// ANIMATION SUPPORT:
// Draws the next image, if all images are currently loaded
//--------------------------------------------------------------------------
private void displayImage(Graphics g)
{
if (!m_fAllLoaded)
return;

// Draw frame of rippled lower half
//----------------------------------------------------------------------
if (m_WaveImage != null) {
g.drawImage (m_WaveImage, (-m_nCurrImage * m_nImgWidth), m_nImgHeight, this);
g.drawImage (m_WaveImage, ((NUM_FRAMES-m_nCurrImage) * m_nImgWidth),
m_nImgHeight, this);
}
// Draw the original in the tophalf.
//----------------------------------------------------------------------
g.drawImage (m_Image, 0, -1, this);
}

// Lake Paint Handler
//--------------------------------------------------------------------------
public void paint(Graphics g)
{
// ANIMATION SUPPORT:
// The following code displays a status message until all the
// images are loaded. Then it calls displayImage to display the current
// image.
//----------------------------------------------------------------------
if (m_fAllLoaded)
displayImage(g);
else
g.drawString("Loading images...", 10, 20);

// TODO: Place additional applet Paint code here
}

// The start() method is called when the page containing the applet
// first appears on the screen. The AppletWizard's initial implementation
// of this method starts execution of the applet's thread.
//--------------------------------------------------------------------------
public void start()
{
if (m_Lake == null)
{
m_Lake = new Thread(this);
m_Lake.start();
}
}

// The stop() method is called when the page containing the applet is
// no longer on the screen. The AppletWizard's initial implementation of
// this method stops execution of the applet's thread.
//--------------------------------------------------------------------------
public void stop()
{
if (m_Lake != null)
{
m_Lake.stop();
m_Lake = null;
}

}

// THREAD SUPPORT
// The run() method is called when the applet's thread is started. If
// your applet performs any ongoing activities without waiting for user
// input, the code for implementing that behavior typically goes here. For
// example, for an applet that performs animation, the run() method controls
// the display of images.
//--------------------------------------------------------------------------
public void run()
{
m_nCurrImage = 0;

// If re-entering the page, then the images have already been loaded.
// m_fAllLoaded == TRUE.
//----------------------------------------------------------------------
if (!m_fAllLoaded)
{
repaint();
m_Graphics = getGraphics();

// Now load up the image to be used in the animation. Rather than do
// this asynchronously with imageUpdate (which is a pain in the bum to
// use) we'll do it synchronously with a MediaTracker. This hangs
// around until the image is loaded. Using the waitForAll method, just
// in case we ever add other images to the applet.
//------------------------------------------------------------------
MediaTracker tracker = new MediaTracker(this);
String strImage;

m_Image = getImage(getDocumentBase(), m_ImageName);
if (!"".equals(m_OverlayName))
m_Overlay = getImage(getDocumentBase(), m_OverlayName);

tracker.addImage(m_Image, 0);
if (!"".equals(m_OverlayName))
tracker.addImage(m_Overlay, 1);

// Wait until all images are fully loaded
//------------------------------------------------------------------
try
{
tracker.waitForAll();
m_fAllLoaded = !tracker.isErrorAny();
}
catch (InterruptedException e) {}

if (!m_fAllLoaded)
{
stop();
m_Graphics.drawString("Error loading images!", 10, 40);
return;
}


// Can now set width and height straight away because the
// MediaTracker object has ensured this information is now available.
//--------------------------------------------------------------
m_nImgWidth = m_Image.getWidth(this);
m_nImgHeight = m_Image.getHeight(this);
if (!"".equals(m_OverlayName)) {
m_nOvlWidth = m_Overlay.getWidth(this);
m_nOvlHeight = m_Overlay.getHeight(this);
}

// Now create the animation of the rippling waves.
//--------------------------------------------------------------
createAnimation();
}
repaint();

while (true)
{
try
// Draw next image in animation
//--------------------------------------------------------------
if (m_tAnimate)
{
displayImage(m_Graphics);
if ( m_nCurrImage == NUM_FRAMES)
m_nCurrImage = 0;

Thread.sleep(50);
}
else
Thread.sleep(500);
catch (InterruptedException e)
stop();
}
}

// MOUSE SUPPORT:
// Clicking on the applet starts/stops it.
// Doesn't call 'stop()' directly because otherwise an InterruptedException
// is thrown. ..
//--------------------------------------------------------------------------
public boolean mouseUp(Event event, int i, int j)
{
boolean flag = super.mouseUp(event, i, j);
if (m_HRef == null)
m_tAnimate = !m_tAnimate; // Toggle m_tAnimate to start/stop animation.
else
{
showStatus("" m_HRef);
getAppletContext().showDocument(m_HRef, m_Frame);
}
return true;
}

// ANIMATION
// Create the animation within a single background image. We use a single
// image rather than the default multiple images because it's quicker.
//---------------------------------------------------------------------------
public void createAnimation ()
{
// Create inverted image of original loaded image.
// We create a background image (backImg) 1 pixel higher
// than the original because we'll need an extra line of
// pixels to play with when we flip the image upside down.
//--------------------------------------------------------
Image backImg = createImage (m_nImgWidth, m_nImgHeight 1);
Graphics backG = backImg.getGraphics();
// Copy the original image (m_Image) onto the background
// version.
//--------------------------------------------------------
backG.drawImage (m_Image, 0, 1, this);
// Now flip the image upside down.
//--------------------------------------------------------
for (int i = 0; i < (m_nImgHeight >> 1); i )
{
backG.copyArea (0, i, m_nImgWidth, 1, 0, m_nImgHeight - i);
backG.copyArea (0, m_nImgHeight - 1 - i, m_nImgWidth, 1,
0, -m_nImgHeight 1 (i << 1));
backG.copyArea (0, m_nImgHeight, m_nImgWidth, 1, 0, -1 - i);
}
// Now create the large (NUM_FRAMES 1 times the width) image
// that will store dithered copies of the inverted original.
//--------------------------------------------------------
m_WaveImage = createImage ((NUM_FRAMES 1) * m_nImgWidth, m_nImgHeight);
m_WaveGraphics = m_WaveImage.getGraphics();
m_WaveGraphics.drawImage (backImg, NUM_FRAMES * m_nImgWidth, 0, this);
// Now create dithered copies (sine displacement up or down) of the
// inverted original.
//--------------------------------------------------------
for (int phase = 0; phase < NUM_FRAMES; phase )
makeWaves (m_WaveGraphics, phase);
// Now, if there is an overlay image, draw the top half of it
// over the frame. (The bottom half of the overlay will be drawn over
// the rippled image)
//------------------------------------------------------------
backG.drawImage (m_Image, 0, 1, this);
if (!"".equals(m_OverlayName))
backG.drawImage (m_Overlay,
(m_nImgWidth - m_nOvlWidth) >> 1,
m_nImgHeight - (m_nOvlHeight >> 1), this);
m_Image = backImg;
}

// ANIMATION
// Take the initial (unwaved) image from the left-hand-side of the graphics
// and make NUM_FRAMES copies of it - the pixels rows of each one dithered
// up or down depending upon the dispy sine function.
//---------------------------------------------------------------------------
public void makeWaves (Graphics g, int phase)
{
double p1;
int dispx, dispy;
// Convert the phase into radians (by splitting 2*PI into
// NUM_FRAMES segments).
//--------------------------------------------------------
p1 = 2 * Math.PI * (double)phase / (double)NUM_FRAMES;
// dispx defines how far across the image has to be copied
// from the original LHS frame.
//--------------------------------------------------------
dispx = (NUM_FRAMES - phase) * m_nImgWidth;
// Now process each horizontal line of pixels. Copy across
// from original frame on the left-had-side and displacing
// up or down WRT the dispy sine function.
//--------------------------------------------------------
for (int i = 0; i < m_nImgHeight; i )
{
// dispy defines the vertical sine displacement. It
// attenuates higher up the image, for perspective.
//--------------------------------------------------------
dispy = (int)((m_nImgHeight/14) * ((double) i 28.0)
* Math.sin ((double)((m_nImgHeight/14)*(m_nImgHeight - i))
/(double)(i 1)
p1)
/ (double) m_nImgHeight);
// If no line dithers here then copy original.
//--------------------------------------------------------
if (i < -dispy)
g.copyArea (NUM_FRAMES * m_nImgWidth, i, m_nImgWidth, 1,
-dispx, 0);
else
// Else copy dithered line.
//--------------------------------------------------------
g.copyArea (NUM_FRAMES * m_nImgWidth, i dispy,
m_nImgWidth, 1, -dispx, -dispy);
}

// Now, if there is an overlay image, draw the bottom half of it
// over the frame. (The top half of the overlay will be drawn over
// the original image)
//------------------------------------------------------------
if (!"".equals(m_OverlayName))
g.drawImage (m_Overlay,
(phase * m_nImgWidth) ((m_nImgWidth - m_nOvlWidth) >> 1),
-m_nOvlHeight >> 1, this);
}
}
[/CODE]

JavaScript版:
[CODE]
(function($) {
jQuery.fn.lake = function(options) {
var settings = $.extend({
'speed': 1,
'scale': 1,
'waves': 10,
'image': true
}, options);

var waves = settings['waves'];
var speed = settings['speed']/4;
var scale = settings['scale']/2;

var ca = document.createElement('canvas');
var c = ca.getContext('2d');

var img = this.get(0);
var img_loaded = false;

img.insertBefore(ca, img);

var w, h, dw, dh;

var offset = 0;
var frame = 0;
var max_frames = 0;
var frames = [];

img.onload = function() {
c.save();

c.canvas.width = this.width;
c.canvas.height = this.height*2;

c.drawImage(this, 0, 0);

c.scale(1, -1);
c.drawImage(this, 0, -this.height*2);

img_loaded = true;

c.restore();

w = c.canvas.width;
h = c.canvas.height;
dw = w;
dh = h/2;

var id = c.getImageData(0, h/2, w, h).data;
var end = false;

// precalc frames
// image displacement
c.save();
while (!end) {
// var odd = c.createImageData(dw, dh);
var odd = c.getImageData(0, h/2, w, h);
var od = odd.data;
// var pixel = (w*4) * 5;
var pixel = 0;
for (var y = 0; y < dh; y ) {
for (var x = 0; x < dw; x ) {
// var displacement = (scale * dd[pixel]) | 0;
var displacement = (scale * 10 * (Math.sin((dh/(y/waves)) (-offset)))) | 0;
var j = ((displacement y) * w x displacement)*4;

// horizon flickering fix
if (j < 0) {
pixel = 4;
continue;
}

// edge wrapping fix
var m = j % (w*4);
var n = scale * 10 * (y/waves);
if (m < n || m > (w*4)-n) {
var sign = y < w/2 ? 1 : -1;
od[pixel] = od[pixel 4 * sign];
od[ pixel] = od[pixel 4 * sign];
od[ pixel] = od[pixel 4 * sign];
od[ pixel] = od[pixel 4 * sign];
pixel;
continue;
}

if (id[j 3] != 0) {
od[pixel] = id[j];
od[ pixel] = id[ j];
od[ pixel] = id[ j];
od[ pixel] = id[ j];
pixel;
} else {
od[pixel] = od[pixel - w*4];
od[ pixel] = od[pixel - w*4];
od[ pixel] = od[pixel - w*4];
od[ pixel] = od[pixel - w*4];
pixel;
// pixel = 4;
}
}
}

if (offset > speed * (6/speed)) {
offset = 0;
max_frames = frame - 1;
// frames.pop();
frame = 0;
end = true;
} else {
offset = speed;
frame ;
}
frames.push(odd);
}
c.restore();
if (!settings.image) {
c.height = c.height/2;
}
};


setInterval(function() {
if (img_loaded) {
if (!settings.image) {
c.putImageData(frames[frame], 0, 0);
} else {
c.putImageData(frames[frame], 0, h/2);
}
// c.putImageData(frames[frame], 0, h/2);
if (frame < max_frames) {
frame ;
} else {
frame = 0;
}
}
}, 33);
return this;
}
})(jQuery);
[/CODE]
系統時間:2024-04-19 21:38:18
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!