Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,15 @@
import java.awt.image.BufferedImage
import java.awt.Color
class RgbBitmap(val width:Int, val height:Int) {
val image=new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR)
def fill(c:Color)={
val g=image.getGraphics()
g.setColor(c)
g.fillRect(0, 0, width, height)
}
def setPixel(x:Int, y:Int, c:Color)=image.setRGB(x, y, c.getRGB())
def getPixel(x:Int, y:Int)=new Color(image.getRGB(x, y))
}

View file

@ -0,0 +1,8 @@
val img=new RgbBitmap(50, 50);
img.fill(Color.CYAN)
img.setPixel(5, 5, Color.BLUE)
assert(img.getPixel(1,1)==Color.CYAN)
assert(img.getPixel(5,5)==Color.BLUE)
assert(img.width==50)
assert(img.height==50)

View file

@ -0,0 +1,42 @@
import java.awt.image.BufferedImage
import java.awt.Color
object RgbBitmap extends App {
class RgbBitmap(val dim: (Int, Int)) {
def width = dim._1
def height = dim._2
private val image = new BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR)
def apply(x: Int, y: Int) = new Color(image.getRGB(x, y))
def update(x: Int, y: Int, c: Color) = image.setRGB(x, y, c.getRGB)
def fill(c: Color) = {
val g = image.getGraphics
g.setColor(c)
g.fillRect(0, 0, width, height)
}
}
object RgbBitmap {
def apply(width: Int, height: Int) = new RgbBitmap(width, height)
}
/** Even Javanese style testing is still possible.
*/
private val img0 = new RgbBitmap(50, 60) { // Wrappers to enable adhoc Javanese style
def getPixel(x: Int, y: Int) = this(x, y)
def setPixel(x: Int, y: Int, c: Color) = this(x, y) = c
}
img0.fill(Color.CYAN)
img0.setPixel(5, 6, Color.BLUE)
// Testing in Java style
assert(img0.getPixel(0, 1) == Color.CYAN)
assert(img0.getPixel(5, 6) == Color.BLUE)
assert(img0.width == 50)
assert(img0.height == 60)
println("Tests successfully completed with no errors found.")
}