Created
June 28, 2012 11:34
-
-
Save binarytemple/3010809 to your computer and use it in GitHub Desktop.
doesnt' seem to display anything, should be fractal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.awt.{ Color, Graphics2D, Dimension } | |
import swing.{ SimpleSwingApplication, Panel, Frame } | |
import util.Random | |
object ASDFFADS extends SimpleSwingApplication { | |
class FernFractalFrame(transformFunction: (Double, Double) => (Double, Double), val width: Int, val height: Int, val max: Int) extends Frame { | |
contents = new Panel { | |
preferredSize = new Dimension(width, height) | |
opaque = true | |
override def paint(g: Graphics2D) { | |
g.setBackground(new Color(0, 0, 0)) | |
g.setColor(Color.GREEN) | |
g.drawLine(height / 2, width / 2, height / 2, width / 2) | |
drawFern((0, 1), max, g) | |
} | |
def paintPoint(p: (Double, Double), g: Graphics2D) = { | |
val scale = height / 11 | |
val y = (height - 25) - (scale * p._2) | |
val x = (width / 2) + (scale * p._1) | |
g.drawLine(x.toInt, y.toInt, x.toInt, y.toInt) | |
} | |
def drawFern(p: (Double, Double), max: Int, g: Graphics2D) { | |
paintPoint(p, g) | |
repaint() | |
if (max != 0) | |
drawFern(transformFunction(p._1, p._2), max - 1, g) | |
} | |
} | |
} | |
import scala.math._ | |
def top = new FernFractalFrame((a, b) => (pow(a, b), pow(b, 10)), 1000, 1000, 100000) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment