Simplifying Graphics With Java and Threads (轉)
Simplifying Graphics With and Threads
By Alex Chaffee and John Papageorge
July 1997
Here's some code that Earth's Alex Chaffee likes to use as an example of how Java can be used to simplify algorithms by combining graphics with threading to render complex graphics.
Basically there are three threads: a Renderer, which performs a complex calculation; an Animator, which wakes up periodically and draws the current image to the screen; and of course the default User Interface thread, which responds to user events and changes the display as appropriate.
The Renderer runs at a low priority—just grinding away forever, or at least until it's done; it shouldn't interfere with the other two threads. The Animator only comes to life every 500 msec or so, to avoid the expense of drawing each pixel.
To perfoa specific calculation, subclass the Renderer to make a Mandelbrot function. Note the -oriented design: this way, the Mandelbrot subclass only needs to overr the Run method and doesn't have to worry about the threading implementation, which is handled by its superclass. Of course, in this example, the threading implementation is trivial, but this is a teaching exercise.
Other items of note are the use of an offscreen Graphics buffer, and the use of progressive rendering. The code makes several rough passes over the image, calculating the value in each quadrant, then gradually refines the view. Unlike scape's rendering of progressive gifs, this program treats a calculated pixel as the "center" of a square of color, not as the top corner or a pixel-wide stripe, and so avoids that odd venetian-blind scrolling-up effect. With a laugh, Chaffee says, "But maybe I'm the only one in the world who thought Netscape's gif-rendering algorithm looked funny." now , see Chaffee's code
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/10748419/viewspace-1002866/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- CLR Threads and Windows ThreadsthreadWindows
- Java 8 併發: Threads 和 ExecutorsJavathread
- 使用java繪圖類Graphics繪製圓圈Java繪圖
- Java 21 新特性:虛擬執行緒(Virtual Threads)Java執行緒thread
- Qt Graphics View 框架QTView框架
- 執行緒 threads執行緒thread
- Common threads: Awk by examplethread
- Android 2D Graphics學習(一)、android.graphics介紹Android
- Python安裝graphics庫Python
- C# 2.0 Graphics 畫雪人C#
- MySQL 5.5 -- innodb_purge_threadsMySqlthread
- Threads in Node 10.5.0: a practical introthread
- android ddms裡邊看threadsAndroidthread
- Qt 之 Graphics View Framework 簡介QTViewFramework
- CorelDRAW Graphics Suite 2022UI
- iOS開發——Core Graphics繪圖iOS繪圖
- Android 使用graphics.Camera類實現自定義旋轉飄落Android
- Android Guide Dev 之Processes and ThreadsAndroidGUIIDEdevthread
- 奇怪的All threads (200) are currently busythread
- Astute Graphics for Mac ai創意外掛合集ASTMacAI
- CorelDRAW Graphics Suite 2022 for MacUIMac
- One of the mosting interesting threads on theserversideRESTthreadServerIDE
- 有關threads中message的問題thread
- 論文解讀(NGCF)《LightGCN: Simplifying and Powering Graph Convolution Network for Recommendation》GC
- Node.js 真·多執行緒 Worker Threads 初探Node.js執行緒thread
- NID-00135: There are 1 active threads錯誤thread
- Threads Versus Greenlets in Python Networking Library GeventthreadPython
- Android中的Activitys, Threads和記憶體洩露Androidthread記憶體洩露
- Introduction to processes and threads(執行緒與程式的區別)thread執行緒
- mysql 5.5引數--innodb_read(write)_io_threadsMySqlthread
- Astute Graphics for Mac(ai2021創意外掛合集)ASTMacAI
- Bitmap回收—Canvas: trying to use a recycled bitmap android.graphicsCanvasAndroid
- Core Graphics框架 :仿射變換與齊次座標框架
- 《Pro Android Graphics》讀書筆記之第一節Android筆記
- 《Pro Android Graphics》讀書筆記之第六節Android筆記
- 《Pro Android Graphics》讀書筆記之第三節Android筆記
- 《Pro Android Graphics》讀書筆記之第四節Android筆記
- 《Pro Android Graphics》讀書筆記之第五節Android筆記