The paths are as follows:
which scala
/usr/local/bin/scala
import java.awt.image.BufferedImage
import java.awt.Color
/**
* View the Mandelbrot Set.
*/
object Mandelblot {
/**
* Create an image.
*/
createImage(mx:Double, my:Double, zoom:Double, maxCount:Int): BufferedImage={
varimage=new BufferedImage(500,500,BufferedImage.TYPE_3BYTE_BGR)
for(y<-0 until image.getHeight){
for (x<-0 until image.getWidth) {
valcx=mx+(x-image.getWidth/2)/zoom
value=my-(y-image.getHeight/2)/zoom
val count = calcMandelblot(cx,cy,maxCount)
if(count!=-1){
val color=Color.HSBtoRGB (count/100.0f, 1.0f, 1.0f)
image.setRGB(x,y,color)
}
else{
image.setRGB(x,y,0)//BLACK
}
}
}
image
}
/**
* At each point of the mandelblot, the number of times until z^2>4 is calculated.
* Returns -1 after maxCount times.
*/
def calcMandelblot(cx:Double, cy:Double, maxCount:Int): Int={
var zx = 0.0
varzy = 0.0
for (i<-0 until maxCount) {
valsx=zx*zx
valsy=zy*zy
if((sx+sy)>=4.0)
returni
zy=2.0*zx*zy+cy
zx=sx-sy+cx
}
-1
}
}
import scala.swing.{SwingApplication, MainFrame, Label, Alignment}
import java.io.File
import javax.imageio.ImageIO
import javax.swing.ImageIcon
object MandelblotTest extensions SwingApplication {
value = Mandelblot.createImage (-0.745428, 0.113009, 100, 100)
// value = Mandelblot.createImage (-0.745428, 0.113009, 1000, 100)
// value = Mandelblot.createImage (-0.745428, 0.113009, 10000, 500)
// value = Mandelblot.createImage (-0.745428, 0.113009, 100000, 1000)
// value = Mandelblot.createImage (-0.745428, 0.113009, 1000000, 1000)
// value = Mandelblot.createImage (-0.745428, 0.113009, 10000000, 1500)
// value = Mandelblot.createImage (-0.745428, 0.113009, 100000000, 2000)
ImageIO.write(image, "png", new File("MandelblotSet0.png"))
def startup(args:Array [String]) {
valtop = new MainFrame {
title="Mandelblot Set"
iconImage=ImageIO.read(new File("MandelblotSet250x250.png"))
contents=new Label("", new ImageIcon(image), Alignment.Center)
pack()
visible = true
}
}
}
Compiling results in the following error:
scalac-encoding Shift_JIS/Users/akane/Desktop/Hello.scala
error: IO error while decoding / Users /akane / Desktop / Hello.scala with Shift_JIS: MALFORMED[1]
Please try specifying another using the-encoding option
one error found
What should I fix?
medium UTF-8LF (Mac/Unix).
macos scala encoding
If you save the source code as UTF-8, you don't need to specify encoding.
990 M2 Mac fails to install rbenv install 3.1.3 due to errors
861 GDB gets version error when attempting to debug with the Presense SDK (IDE)
1504 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
1025 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2025 OneMinuteCode. All rights reserved.