Pixels、Excel、Kotlin、そしてちょっとした懐かしさ...

みなさん、こんにちは!この記事のアイデアは1か月前に思いついたものですが、仕事で忙しいため、時間がひどく不足していました。ある晩、YouTubeで、ピクセルアートプラットフォーマーゲームの作成に関するビデオに出くわしました。そして、学校での最初のコンピュータサイエンスのレッスンを思い出しました。そこでは、「BASICで描画」し、「カラスは文字を食べる」を演奏しました。





序文

年は2000年でした。98年の危機は終わりました。私は小さな町の地元の学校で8年生でした。学年の初めに、小さなイベントが皆を待っていました-コンピュータサイエンスのレッスンが導入されました。多くの人がこれを教える必要のある別の主題として扱いましたが、目を輝かせた人もいました。私は後者の中にいました。





コンピュータサイエンスは導入されましたが、これらの目的のためのお金がなかったため、「新しいコンピュータを導入する」ことを忘れていたことに注意する必要があります。当時、私たちの学校には、ソ連製の機械「ElectronicsMC0511」とその少し現代的な対応物がいくつかありました。彼らは彼ら自身の法律に従って、または特定の「ニコライ・ウラジミロヴィッチ」(地元のマスター)の到着後にのみ働きました。





サイトからの写真-red-innovations.su
サイトからの写真-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 , .





ランダム画像1.)ステップ3、RGB(11、238、229)2。)ステップ2、RGB(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),
)
      
      



... . "" .





ピクセルハート
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(), .





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
}
      
      



, .





Excelでレンダリングされた画像。 Mockingjay1701の作品に基づいています
Excel. Mockingjay1701

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





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





14 , , .





数年後に「MSElectronics」が最新のPentiumベースの対応物に置き換えられたとしても、古いコンピューターに関する最初のレッスンは永遠に私に残ります。なぜなら、コンピューターとそれに関連するすべてのものに対する私の愛を私に与えたのは彼らだったからです。 ..





あなたの学校でコンピュータサイエンスはどのように始まったのですか?





ありがとうございます!みなさん、さようなら!








All Articles