//cmd: +w300 +h300 +am2 +a0.01 #version 3.7; #global_settings {assumed_gamma 1} #default{ finish{ ambient 0.1 diffuse 0.9 }} background {rgb 0} #macro mapInit(DimX, DimY) #local Map = array[DimX][DimY]; mapFillSolid(Map, rgb<0,0,0>) Map #end #macro mapFillSolid(Map, Colour) mapFillRect(Map,<0,0>,, Colour) #end #macro mapFillRect(Map, RectLowerLeft, RectUpperRight, Colour) #for (X, RectLowerLeft.x, RectUpperRight.x - 1) #for (Y, RectLowerLeft.y, RectUpperRight.y - 1) #local Map[X][Y] = Colour; #end #end #end #macro mapSetPixel(Map, Pixel, Colour) #local Map[Pixel.x][Pixel.y] = Colour; #end #macro mapGetPixel(Map, Pixel) Map[Pixel.x][Pixel.y] #end #macro mapObject(Map) // to visualize the map, each pixel is rendered as a sphere #for (X,0,dimension_size(Map,1)-1) #for (Y,0,dimension_size(Map,2)-1) sphere{ , 0.5 pigment{colour Map[X][Y]} } #end #end #end //== Scene #declare DimX = 100; #declare DimY = 100; #declare ImgMap = mapInit(DimX, DimY); mapFillSolid(ImgMap, rgb<1, 0, 0>) mapSetPixel(ImgMap, <25,25>, rgb<1,1,1>) mapFillRect(ImgMap, <50,50>, <75,75>, rgb<0,0,1>) #debug concat("Colour at: <", vstr(2,<25,25>,", ",0,0),"> is: <", vstr(3, mapGetPixel(ImgMap, <25,25>),", ",0,0),">\n") mapObject(ImgMap) camera{ location look_at right x*image_width/image_height } light_source{ rgb 1 }