import processing.core._ import PConstants._ import PApplet._ object font_may21Runner { def main(args: Array[String]) { PApplet.main(Array("font_may21")) } } class font_may21 extends spde.core.SApplet { lazy val px = new DrawProxy { val squareDim = 500 val precision = 65536 val base = 16 def stringify(x: Int) = x.toHexString def isNeg(x: Double): String = if(x < 0) "-" else "" val hexFloatLen: Int = Math.round(Math.log(precision) / Math.log(base)) val leftmargin = 140 size(squareDim, squareDim) val font = loadFont("AmericanTypewriter-24.vlw") textFont(font) def draw() { background(0) fill(30) ellipse(width/2,height/2,squareDim,squareDim) stroke(80) line(width /2, 0, width/2, height) line(0, height/2, width, height/2) fill(255) val toWrite = Math.round(Math.atan2(-mouseY + height/2, mouseX - width/2)*precision).toDouble/precision text("base 10", 20, 35) text(toWrite.toString, leftmargin, 35) val toWriteAsHex = Math.abs(toWrite) val lessTOne = stringify(Math.round((toWriteAsHex % 1) *precision)) text("base 16", 20, 65) text( isNeg(toWrite) + Math.floor(toWriteAsHex).toInt.toHexString + "." + "0"*(hexFloatLen - lessTOne.length) + lessTOne, leftmargin, 65) } } }