--- a/LINKS Fri Jun 22 13:34:05 2018 +0100
+++ b/LINKS Tue Jun 26 01:49:32 2018 +0100
@@ -116,4 +116,18 @@
---------------------
Scala resources
-https://danielwestheide.com/scala/neophytes.html
\ No newline at end of file
+https://danielwestheide.com/scala/neophytes.html
+
+
+
+
+
+
+
+functional programming
+----------------------
+Functional Data Structures
+https://cs.uwaterloo.ca/~plragde/flaneries/FDS/index.html
+
+Okasaki
+http://www.cs.cmu.edu/~rwh/theses/okasaki.pdf
\ No newline at end of file
Binary file handouts/pep-ho.pdf has changed
--- a/handouts/pep-ho.tex Fri Jun 22 13:34:05 2018 +0100
+++ b/handouts/pep-ho.tex Tue Jun 26 01:49:32 2018 +0100
@@ -214,21 +214,23 @@
\begin{figure}[p]
\begin{boxedminipage}{\textwidth}
+
+A Scala programm for generating pretty pictures of the Mandelbrot Set
+(\url{https://en.wikipedia.org/wiki/Mandelbrot_set}):
\begin{center}
\begin{tabular}{c}
-\includegraphics[scale=0.15]{../pics/mand1.png}\\
+\includegraphics[scale=0.12]{../pics/mand1.png}
\end{tabular}
-
-Wellknown Mandelbrot program for generating pretty pictures due to
-Benoit Mandelbrot. (\url{https://en.wikipedia.org/wiki/Mandelbrot_set})
-\bigskip
+\end{center}
+\begin{center}
+\begin{tabular}{@{}p{0.45\textwidth}|p{0.45\textwidth}@{}}
+ \bf sequential version: & \bf parallel version: (on 4 cores)\smallskip\\
-\begin{tabular}{@{}p{6cm}|p{6cm}@{}}
- \includegraphics[scale=0.15]{../pics/mand4.png} &
- \includegraphics[scale=0.15]{../pics/mand3.png} \\
-\footnotesize
-{\begin{lstlisting}
+ {\hfill\includegraphics[scale=0.12]{../pics/mand4.png}\hfill} &
+ {\hfill\includegraphics[scale=0.12]{../pics/mand3.png}\hfill} \\
+
+{\footnotesize\begin{lstlisting}[xleftmargin=-1mm]
for (y <- (0 until H)) {
for (x <- (0 until W)) {
@@ -243,11 +245,32 @@
}
viewer.updateUI()
}
-\end{lstlisting}}
-& \\
+\end{lstlisting}}
+&
+{\footnotesize\begin{lstlisting}[xleftmargin=0mm]
+for (y <- (0 until H).par) {
+ for (x <- (0 until W).par) {
+
+ val c = start +
+ (x * d_x + y * d_y * i)
+ val iters = iterations(c, max)
+ val col =
+ if (iters == max) black
+ else colours(iters % 16)
+
+ pixel(x, y, col)
+ }
+ viewer.updateUI()
+}
+\end{lstlisting}}\\
+
+\centering\includegraphics[scale=0.5]{../pics/cpu2.png} &
+\centering\includegraphics[scale=0.5]{../pics/cpu1.png}\\
+
+
\end{tabular}
\end{center}
-\caption{Test \label{mand}}
+\caption{Test \label{mand}}
\end{boxedminipage}
\end{figure}
Binary file pics/cpu1.png has changed
Binary file pics/cpu2.png has changed
Binary file pics/mand3.png has changed
Binary file pics/mand4.png has changed
--- a/progs/mandelbrot.scala Fri Jun 22 13:34:05 2018 +0100
+++ b/progs/mandelbrot.scala Tue Jun 26 01:49:32 2018 +0100
@@ -1,3 +1,6 @@
+// Mandelbrot pictures
+// see https://en.wikipedia.org/wiki/Mandelbrot_set
+
import java.awt.Color
import java.awt.Dimension
import java.awt.Graphics
@@ -19,9 +22,10 @@
def abs() = Math.sqrt(this.re * this.re + this.im * this.im)
}
+// to allow the notation n + m * i
object i extends Complex(0, 1)
+implicit def double2complex(re: Double) = Complex(re, 0)
-implicit def double2complex(re: Double): Complex = Complex(re, 0)
// some customn colours for the "sliding effect"
val colours = List(
@@ -84,6 +88,8 @@
}
// main function
+// start and end are the upper-left and lower right corners
+// max is the number of maximum iterations
def mandelbrot(start: Complex, end: Complex, max: Int) : Unit = {
viewer.clearCanvas(black)
@@ -91,8 +97,8 @@
val d_x = (end.re - start.re) / W
val d_y = (end.im - start.im) / H
- for (y <- (0 until H).par) {
- for (x <- (0 until W).par) {
+ for (y <- (0 until H)) {
+ for (x <- (0 until W)) {
val c = start +
(x * d_x + y * d_y * i)
@@ -107,6 +113,7 @@
}
}
+
// Examples
//==========