Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
31
Task/Draw-a-pixel/Kotlin/draw-a-pixel.kotlin
Normal file
31
Task/Draw-a-pixel/Kotlin/draw-a-pixel.kotlin
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
// Version 1.2.41
|
||||
|
||||
import java.awt.Color
|
||||
import java.awt.Graphics
|
||||
import java.awt.image.BufferedImage
|
||||
|
||||
class BasicBitmapStorage(width: Int, height: Int) {
|
||||
val image = BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR)
|
||||
|
||||
fun fill(c: Color) {
|
||||
val g = image.graphics
|
||||
g.color = c
|
||||
g.fillRect(0, 0, image.width, image.height)
|
||||
}
|
||||
|
||||
fun setPixel(x: Int, y: Int, c: Color) = image.setRGB(x, y, c.getRGB())
|
||||
|
||||
fun getPixel(x: Int, y: Int) = Color(image.getRGB(x, y))
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val bbs = BasicBitmapStorage(320, 240)
|
||||
with (bbs) {
|
||||
fill(Color.white) // say
|
||||
setPixel(100, 100, Color.red)
|
||||
// check it worked
|
||||
val c = getPixel(100, 100)
|
||||
print("The color of the pixel at (100, 100) is ")
|
||||
println(if (c == Color.red) "red" else "white")
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue