i start by creating a 2d array all with a value of 2. then setting a few values from the bottom right of the array to 5
var map = Array.fill(5, 10)(2);
map(4)(9) = 5
map(3)(9) = 5
map(4)(8) = 5
map(3)(8) = 5
this array will be represented by an image. each number 2 should be a blue square. the rest should just be white
import scala.io.Source
import java.io._
import java.awt.image.BufferedImage
import java.awt.{Graphics2D,Color,Font,BasicStroke}
import java.awt.geom._
object DRAWPROB {
def draw(map : Array[Array[Int]]){
val size = (30 * (map(0).length-1), 30 * (map.length-1))
val canvas = new BufferedImage(size._1, size._2, BufferedImage.TYPE_INT_RGB)
val g = canvas.createGraphics()
g.setColor(Color.WHITE)
g.fillRect(0, 0, canvas.getWidth, canvas.getHeight)
g.setRenderingHint(java.awt.RenderingHints.KEY_ANTIALIASING,java.awt.RenderingHints.VALUE_ANTIALIAS_ON)
var d = 0;
for(d <- 0 to map.length-1){
var e = 0;
for(e <- 0 to map(0).length-1){
g.setColor(Color.BLUE)
if(map(d)(e) == 2){ g.fill(new Rectangle2D.Double(d*30.0, e*30.0, 30.0, 30.0));} // ill find a way to do this once i can load the image
else {println("not at "+ d + " " + e)}
}
}
g.dispose()
javax.imageio.ImageIO.write(canvas, "png", new java.io.File("island_drawing.png"))
}
it just makes 1 large blue square but i wanted a section missing from the bottom right
why am i getting this