Olá pessoal! A ideia deste artigo surgiu há um mês, mas devido ao facto de estar muito ocupado no trabalho, o tempo estava a faltar. Uma noite, no YouTube, encontrei um vídeo sobre como fazer um jogo de plataforma pixel art. E então me lembrei das minhas primeiras aulas de ciência da computação na escola, onde nós "desenhamos no BASIC" e brincávamos de "o corvo come letras".
Prefácio
O ano era 2000. A crise de 98 acabou. Eu estava na 8ª série em uma escola local em uma pequena cidade. Com o início do ano letivo, um pequeno evento esperava a todos - foi apresentada uma aula de informática. Muitos trataram isso como mais um assunto que precisa ser ensinado, mas também houve aqueles cujos olhos brilharam. Eu estava entre os últimos.
Deve-se notar que embora a ciência da computação tenha sido introduzida, eles se esqueceram de "introduzir novos computadores" porque não havia dinheiro para esses fins. Naquela época, nossa escola era servida por máquinas fabricadas na URSS - " Eletrônica MC 0511 " e várias de suas contrapartes um pouco mais modernas. Eles trabalharam apenas de acordo com suas próprias leis, ou após a chegada de um certo "Nikolai Vladimirovich" - um mestre local.
"" - 26 , . . . , . , .
, , . - , , .
BufferedImage. , .
fun drawPixel(
x:Int, y:Int, red:Int, green:Int, blue: Int,
image: BufferedImage
) {
image.setRGB(x, y, Color(red,green,blue).rgb)
}
, . , - redRng, greenRng blueRng .
fun drawRandImage(
image: BufferedImage, stepSize: Int = 1,
redRng: Int = 255, greenRng: Int = 255, blueRng: Int = 255
) {
for(posX in 0 until image.width step stepSize){
for (posY in 0 until image.height step stepSize) {
val r = if (redRng <= 0) 0 else Random.nextInt(0, redRng)
val g = if (greenRng <= 0) 0 else Random.nextInt(0, greenRng)
val b = if (blueRng <= 0) 0 else Random.nextInt(0, blueRng)
drawPixel(posX, posY, r, g, b, image)
}
}
}
stepSize , .
- . . ImageIO. - , Thread.
fun writeImage(img: BufferedImage, file: String) {
val imgthread = Thread(Runnable {
ImageIO.write(img, File(file).extension, File(file))
})
try {
imgthread.start()
} catch (ex: Exception) {
ex.printStackTrace()
imgthread.interrupt()
}
}
, "" .
ArrayList<List<Int>>. "" drawTitle, "" drawPixel, "big pixel" .
fun drawTile(
startX: Int, startY: Int, size: Int,
red: Int, green: Int, blue: Int, image: BufferedImage
) {
for (posX in startX until startX+size) {
for (posY in startY until startY+size) {
drawPixel(posX,posY,red,green,blue,image)
}
}
}
. -. when 4 …
fun drawImage(pixels: ArrayList<List<Int>>, image: BufferedImage) {
pixels.forEachIndexed { posY, row ->
row.forEachIndexed { posX, col ->
when(col) {
1 -> drawTile(posX*10,posY*10,10,255,2,0,image)
2 -> drawTile(posX*10,posY*10,10,156,25,31,image)
3 -> drawTile(posX*10,posY*10,10,255,255,255,image)
else -> drawTile(posX*10,posY*10,10,23,0,44,image)
}
}
}
}
… , (1 = , 2 = -, 3 = , 4 = )
val map = arrayListOf(
listOf(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
listOf(0,0,0,1,1,1,0,0,0,1,2,2,0,0,0),
listOf(0,0,1,3,3,1,1,0,1,1,1,2,2,0,0),
listOf(0,1,3,3,1,1,1,1,1,1,1,1,2,2,0),
listOf(0,1,3,1,1,1,1,1,1,1,1,1,2,2,0),
listOf(0,1,1,1,1,1,1,1,1,1,1,1,2,2,0),
listOf(0,1,1,1,1,1,1,1,1,1,1,1,2,2,0),
listOf(0,0,1,1,1,1,1,1,1,1,1,2,2,0,0),
listOf(0,0,0,1,1,1,1,1,1,1,2,2,0,0,0),
listOf(0,0,0,0,1,1,1,1,1,2,2,0,0,0,0),
listOf(0,0,0,0,0,1,1,1,2,2,0,0,0,0,0),
listOf(0,0,0,0,0,0,1,2,2,0,0,0,0,0,0),
listOf(0,0,0,0,0,0,0,2,0,0,0,0,0,0,0),
listOf(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
)
... . "" .
, " " , - , . , , .
Excel
. JS (React JS), , JavaScript . - …
, Excel. - . . " " - , Apache POI - word, excel, pdf. , .
hex rgba, Color.
val toRGBA = { hex: String ->
val red = hex.toLong(16) and 0xff0000 shr 16
val green = hex.toLong(16) and 0xff00 shr 8
val blue = hex.toLong(16) and 0xff
val alpha = hex.toLong(16) and 0xff000000 shr 24
Color(red.toInt(),green.toInt(),blue.toInt(),alpha.toInt())
}
, .
fun getPixelColors(file: String, listName: String): ArrayList<List<String>> {
val table = FileInputStream(file)
val sheet = WorkbookFactory.create(table).getSheet(listName)
val rowIterator: Iterator<Row> = sheet.iterator()
val rowArray: ArrayList<Int> = ArrayList()
val cellArray: ArrayList<Int> = ArrayList()
while (rowIterator.hasNext()) {
val row: Row = rowIterator.next()
rowArray.add(row.rowNum)
val cellIterator = row.cellIterator()
while (cellIterator.hasNext()) {
val cell = cellIterator.next()
cellArray.add(cell.address.column)
}
}
val rowSize = rowArray.maxOf { el->el }
//...
//...
return pixelMatrix
}
( ). , , . .
, , . ...
val rows = sheet.lastRowNum
val cells = sheet.getRow(rows).lastCellNum // + rows
val pixArray = Array(rows+1) {Array(ccc+1) {""} }
... OutOfBounds. (row) , , . , "", . iterator.hasNext(), .
- " " BufferedImage. , - TYPE_INT_ARGB, .
fun renderImage(pixels: ArrayList<List<String>>): BufferedImage {
val resultImage = BufferedImage(
pixels[0].size*10,
pixels.size*10,
BufferedImage.TYPE_INT_ARGB
)
pixels.forEachIndexed { posY, row ->
row.forEachIndexed { posX, col ->
drawTile(
(posX)*10,(posY)*10, 10,
toRGBA(col).red, toRGBA(col).green,toRGBA(col).blue,
toRGBA(col).alpha, resultImage
)
}
}
return resultImage
}
, .
github. ? svg, (blur, glitch, glow, etc..), “ ” , xls (HSSF Color) . - , , - .
, " " (ctrl+c, ctrl+v), "" . , : , , - " ". , , , .
14 , , .
Mesmo que em alguns anos "MS Electronics" fosse substituído por equivalentes modernos baseados em Pentium, aquelas primeiras lições em computadores antigos permanecerão para sempre comigo, porque foram eles que colocaram em mim meu amor por computadores e tudo o que está relacionado a eles. ..
Como a ciência da computação começou na sua escola?
Obrigado a todos! Tchau todo mundo!