Pixels, Excel, Kotlin et un peu de nostalgie ...

Bonjour à tous! L'idée de cet article est venue il y a un mois, mais en raison de la charge de travail, le temps manquait cruellement. Un soir sur YouTube, je suis tombé sur une vidéo sur la création d'un jeu de plateforme en pixel art. Et puis je me suis souvenu de mes premiers cours d'informatique à l'école, où nous "dessinions en BASIC" et jouions "le corbeau mange des lettres".





Préface

C'était en 2000. La crise de 98 est terminée. J'étais en 8e année dans une école locale dans une petite ville. Avec la rentrée scolaire, un petit événement attendait tout le monde - une leçon d'informatique a été introduite. Beaucoup ont traité cela comme un autre sujet à enseigner, mais il y avait aussi ceux dont les yeux se sont éclairés. J'étais parmi ces derniers.





Il convient de noter que bien que l'informatique ait été introduite, ils ont oublié de «lancer de nouveaux ordinateurs» parce qu'il n'y avait pas d'argent à ces fins. À cette époque, notre école était desservie par des machines fabriquées en URSS - « Electronics MC 0511 » et plusieurs de leurs homologues légèrement plus modernes. Ils ne travaillaient que selon leurs propres lois, ou après l'arrivée d'un certain "Nikolai Vladimirovich" - un maître local.





photo du site - red-innovations.su
photo du site - red-innovations.su

"" - 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 , .





image aléatoire 1.) étape 3, RVB (11, 238, 229) 2.) étape 2, RVB (181, 19, 227)
1.) step 3, RGB (11, 238, 229) 2.) step 2, RGB (181, 19, 227)

- . . 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),
)
      
      



... . "" .





coeur de pixel
pixel heart

, " " , - , . , , .





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(), .





Éditeur de pixels dans Excel
Excel

- " " 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
}
      
      



, .





image rendue dans Excel.  basé sur les travaux de Mockingjay1701
Excel. Mockingjay1701

github. ? svg, (blur, glitch, glow, etc..), “ ” , xls (HSSF Color) . - , , - .





, " " (ctrl+c, ctrl+v), "" . , : , , - " ". , , , .





14 , , .





Même si dans quelques années "MS Electronics" a été remplacé par des homologues modernes basés sur Pentium, ces premières leçons sur de vieux ordinateurs resteront à jamais avec moi, car ce sont eux qui ont mis en moi mon amour pour les ordinateurs et tout ce qui y est lié. ..





Comment l'informatique a-t-elle commencé dans votre école?





Merci à tous! Au revoir tout le monde!








All Articles