Skip to content

Latest commit

 

History

History
41 lines (32 loc) · 2.91 KB

Readme.md

File metadata and controls

41 lines (32 loc) · 2.91 KB

Some simple Scala examples for beginners

Tools setup

The easiest way to install all necessary Scala tools on your system is by using a tool called Coursier. See the getting started instructions on the Scala website for how to install this. Once you have Coursier installed, doing cs setup should install everything else that you need, including scala-cli and sbt. Running cs update regularly will keep your Scala tools up-to-date.

Examples

In roughly increasing order of complexity:

  • e.scala - compute e from its series expansion (for loop)
  • prime.scala - test if a given number is prime (tail-recursive function)
  • factor.scala - compute a prime factorisation (lists)
  • sqrt.scala - compute square roots with Newton's method (nested tail-recursive function)
  • sin.scala - compute sine using a trig identity (non-tail-recursive function)
  • stats.scala - compute mean and sd of some numbers (read lines from stdin)
  • statse.scala - compute mean and sd of some numbers (extension methods)
  • statsb.scala - compute mean and sd using Breeze (Breeze scientific library)
  • canvas1.scala - minimal image/canvas app (set pixels) (case classes, writing a file)
  • canvas2.scala - minimal image/canvas app (lines and triangles) (folds)
  • canvas3.scala - minimal image/canvas app (Sierpinski triangles) (parametrised extension)
  • canvas4.scala - minimal image/canvas app (circles and thick lines)
  • canvas5.scala - minimal image/canvas app (fractal fern)
  • canvas6.scala - minimal image/canvas app (Mandelbrot set) (complex numbers from Spire)
  • canvas7.scala - minimal image/canvas app (Lorenz attractor with Euler integration) (LazyLists)
  • canvas8.scala - minimal image/canvas app (save Mandelbrot as PNG) (BufferedImage)
  • mand.scala - draw a Mandelbrot set directly on a BufferedImage (WriteableRaster)
  • sierp.scala - draw a Sierpinski directly on a BufferedImage (Graphics2D)
  • lorenz.scala - integrate the Lorenz system with Breeze and plot in a window on the console (breeze-viz)
  • window.scala - draw a Mandelbrot set in a window on the console (Swing)
  • agglom - simple multi-file application to animate an agglomeration process (sbt project)

Some links