curve bank project baravelle spiral robert lai cs491
Post on 21-Dec-2015
218 views
TRANSCRIPT
![Page 1: Curve Bank Project Baravelle Spiral Robert Lai CS491](https://reader031.vdocument.in/reader031/viewer/2022032201/56649d565503460f94a33df9/html5/thumbnails/1.jpg)
Curve Bank ProjectBaravelle Spiral
Robert LaiCS491
![Page 2: Curve Bank Project Baravelle Spiral Robert Lai CS491](https://reader031.vdocument.in/reader031/viewer/2022032201/56649d565503460f94a33df9/html5/thumbnails/2.jpg)
Recall
• Fractal• Curves within curves
• Patterns within patterns
• Iterations within iterations
• Not actually a curved design, the spiral effect comes from the way the structure is drawn
• How to draw the Baravelle Spiral
![Page 3: Curve Bank Project Baravelle Spiral Robert Lai CS491](https://reader031.vdocument.in/reader031/viewer/2022032201/56649d565503460f94a33df9/html5/thumbnails/3.jpg)
Recall (count.)• FINITE AREA
• INIFINTE PERIMETER or FRACTALe.g. Koch Snowflake, Mandelbrot Set
• Geometric Series• Converges, area
• Harmonic Series• Diverges, fractal
![Page 4: Curve Bank Project Baravelle Spiral Robert Lai CS491](https://reader031.vdocument.in/reader031/viewer/2022032201/56649d565503460f94a33df9/html5/thumbnails/4.jpg)
![Page 5: Curve Bank Project Baravelle Spiral Robert Lai CS491](https://reader031.vdocument.in/reader031/viewer/2022032201/56649d565503460f94a33df9/html5/thumbnails/5.jpg)
Baravelle Spiral• Two different format
• Application• Allow user to download and run on their own co
mputer• jar format• jar cvfm <jar file name> mymanifest <dir>
• Applet• Allow user to see and run it on the web browser
![Page 6: Curve Bank Project Baravelle Spiral Robert Lai CS491](https://reader031.vdocument.in/reader031/viewer/2022032201/56649d565503460f94a33df9/html5/thumbnails/6.jpg)
Multithreading
• One action at a time?• Programming step by step
• Difficult to do.• e.g. human body
• We need multithreading
![Page 7: Curve Bank Project Baravelle Spiral Robert Lai CS491](https://reader031.vdocument.in/reader031/viewer/2022032201/56649d565503460f94a33df9/html5/thumbnails/7.jpg)
Multithreading (2)• Describes a program that is designed to
have parts of its code execute concurrently
• Concurrent Programming
• OS:
• Preemptive multithreading
• Cooperative multithreading
![Page 8: Curve Bank Project Baravelle Spiral Robert Lai CS491](https://reader031.vdocument.in/reader031/viewer/2022032201/56649d565503460f94a33df9/html5/thumbnails/8.jpg)
Preemptive multithreading • The operating system to determine whe
n a context switch should occur
• The system may make a context switch at an inappropriate time
• Causing priority inversion• Priority inversion: scenario where a low priority tas
k holds a shared resource that is required by a high priority task
![Page 9: Curve Bank Project Baravelle Spiral Robert Lai CS491](https://reader031.vdocument.in/reader031/viewer/2022032201/56649d565503460f94a33df9/html5/thumbnails/9.jpg)
Cooperative multithreading • Relies on the threads themselves to reli
nquish control once they are at a stopping point
• Create problems if a thread is waiting for a resource to become available
![Page 10: Curve Bank Project Baravelle Spiral Robert Lai CS491](https://reader031.vdocument.in/reader031/viewer/2022032201/56649d565503460f94a33df9/html5/thumbnails/10.jpg)
Baravelle Spiral• Application
• SwingWorker
• Applet• Thread
![Page 11: Curve Bank Project Baravelle Spiral Robert Lai CS491](https://reader031.vdocument.in/reader031/viewer/2022032201/56649d565503460f94a33df9/html5/thumbnails/11.jpg)
SwingWorker • 3rd Version
• An object creates a thread to execute a time-consuming operation
• Is not in the Swing release• http://java.sun.com/docs/books/tutorial/uis
wing/misc/threads.html
![Page 12: Curve Bank Project Baravelle Spiral Robert Lai CS491](https://reader031.vdocument.in/reader031/viewer/2022032201/56649d565503460f94a33df9/html5/thumbnails/12.jpg)
• private static class ThreadVar{…}• Class to maintain reference to current worker thre
ad under separate synchronization control.
• protected synchronized Object getValue(){…}• Get the value produced by the worker thread, or n
ull if it hasn't been constructed yet.
• private synchronized void setValue(Object x){…}• Set the value produced by worker thread
• public abstract Object construct();
![Page 13: Curve Bank Project Baravelle Spiral Robert Lai CS491](https://reader031.vdocument.in/reader031/viewer/2022032201/56649d565503460f94a33df9/html5/thumbnails/13.jpg)
• public void interrupt(){…}• public Object get(){…}
• Return the value created by the construct method.• Returns null if either the constructing thread or the
current thread was interrupted before a value was produced.
• public SwingWorker(){…}• Start a thread that will call the construct method an
d then exit.
• public void start(){…}• Start the worker thread.
![Page 14: Curve Bank Project Baravelle Spiral Robert Lai CS491](https://reader031.vdocument.in/reader031/viewer/2022032201/56649d565503460f94a33df9/html5/thumbnails/14.jpg)
Thread• A thread is a thread of execution in a program
• Allows the JVM to run an application to have multiple threads of
execution running concurrently
• private Thread timerThread;• public void actionPerformed( ActionEvent actionEvent )
{ …check the event taken … startThread(); … }
• private void stopThread() {
if(timerThread.currentThread() != null)
timerThread.currentThread().interrupt();
timerThread = null;
}
![Page 15: Curve Bank Project Baravelle Spiral Robert Lai CS491](https://reader031.vdocument.in/reader031/viewer/2022032201/56649d565503460f94a33df9/html5/thumbnails/15.jpg)
• private void startThread() {
stopThread();
Runnable r = new Runnable() {
public void run() { runWork(); }
};
timerThread = new Thread(r);
timerThread.start();
}• private void runWork() { … my working procedure … }
![Page 16: Curve Bank Project Baravelle Spiral Robert Lai CS491](https://reader031.vdocument.in/reader031/viewer/2022032201/56649d565503460f94a33df9/html5/thumbnails/16.jpg)
• Runnable• Interface• is designed to provide a common protocol for obje
cts that wish to execute code• implemented by class Thread
![Page 17: Curve Bank Project Baravelle Spiral Robert Lai CS491](https://reader031.vdocument.in/reader031/viewer/2022032201/56649d565503460f94a33df9/html5/thumbnails/17.jpg)
Conclusion• More understanding of graph
programming
• Give me another way to understand math concept
![Page 18: Curve Bank Project Baravelle Spiral Robert Lai CS491](https://reader031.vdocument.in/reader031/viewer/2022032201/56649d565503460f94a33df9/html5/thumbnails/18.jpg)
DEMO