Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
43
Task/Mandelbrot-set/Scala/mandelbrot-set-1.scala
Normal file
43
Task/Mandelbrot-set/Scala/mandelbrot-set-1.scala
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
import org.rosettacode.ArithmeticComplex._
|
||||
import java.awt.Color
|
||||
|
||||
object Mandelbrot
|
||||
{
|
||||
def generate(width:Int =600, height:Int =400)={
|
||||
val bm=new RgbBitmap(width, height)
|
||||
|
||||
val maxIter=1000
|
||||
val xMin = -2.0
|
||||
val xMax = 1.0
|
||||
val yMin = -1.0
|
||||
val yMax = 1.0
|
||||
|
||||
val cx=(xMax-xMin)/width
|
||||
val cy=(yMax-yMin)/height
|
||||
|
||||
for(y <- 0 until bm.height; x <- 0 until bm.width){
|
||||
val c=Complex(xMin+x*cx, yMin+y*cy)
|
||||
val iter=itMandel(c, maxIter, 4)
|
||||
bm.setPixel(x, y, getColor(iter, maxIter))
|
||||
}
|
||||
bm
|
||||
}
|
||||
|
||||
def itMandel(c:Complex, imax:Int, bailout:Int):Int={
|
||||
var z=Complex()
|
||||
for(i <- 0 until imax){
|
||||
z=z*z+c;
|
||||
if(z.abs > bailout) return i
|
||||
}
|
||||
imax;
|
||||
}
|
||||
|
||||
def getColor(iter:Int, max:Int):Color={
|
||||
if (iter==max) return Color.BLACK
|
||||
|
||||
var c=3*math.log(iter)/math.log(max-1.0)
|
||||
if(c<1) new Color((255*c).toInt, 0, 0)
|
||||
else if(c<2) new Color(255, (255*(c-1)).toInt, 0)
|
||||
else new Color(255, 255, (255*(c-2)).toInt)
|
||||
}
|
||||
}
|
||||
6
Task/Mandelbrot-set/Scala/mandelbrot-set-2.scala
Normal file
6
Task/Mandelbrot-set/Scala/mandelbrot-set-2.scala
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
import scala.swing._
|
||||
import javax.swing.ImageIcon
|
||||
val imgMandel=Mandelbrot.generate()
|
||||
val mainframe=new MainFrame(){title="Test"; visible=true
|
||||
contents=new Label(){icon=new ImageIcon(imgMandel.image)}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue