September 2017 Update
This commit is contained in:
parent
bba7bfd280
commit
ba8067c3b7
14570 changed files with 153136 additions and 63871 deletions
|
|
@ -1,4 +1,6 @@
|
|||
{{omit from|AWK}}
|
||||
{{omit from|PARI/GP}}
|
||||
|
||||
Show a basic storage type to handle a simple RGB raster graphics image,
|
||||
and some primitive associated functions.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
package Bitmap_Store is
|
||||
type Luminance is mod 2**8;
|
||||
type Pixel is record
|
||||
R, G, B : Luminance;
|
||||
R, G, B : Luminance := Luminance'First;
|
||||
end record;
|
||||
Black : constant Pixel := (others => 0);
|
||||
White : constant Pixel := (others => 255);
|
||||
Black : constant Pixel := (others => Luminance'First);
|
||||
White : constant Pixel := (others => Luminance'Last);
|
||||
type Image is array (Positive range <>, Positive range <>) of Pixel;
|
||||
|
||||
procedure Fill (Picture : in out Image; Color : Pixel);
|
||||
|
|
|
|||
|
|
@ -4,22 +4,14 @@ package body Bitmap_Store is
|
|||
|
||||
procedure Fill (Picture : in out Image; Color : Pixel) is
|
||||
begin
|
||||
for I in Picture'Range (1) loop
|
||||
for J in Picture'Range (2) loop
|
||||
Picture (I, J) := Color;
|
||||
end loop;
|
||||
end loop;
|
||||
for p of Picture loop x:= Color;end loop;
|
||||
end Fill;
|
||||
|
||||
procedure Print (Picture : Image) is
|
||||
begin
|
||||
for I in Picture'Range (1) loop
|
||||
for J in Picture'Range (2) loop
|
||||
if Picture (I, J) = White then
|
||||
Put (' ');
|
||||
else
|
||||
Put ('H');
|
||||
end if;
|
||||
Put (if Picture (I, J) = White then ' ' else 'H');
|
||||
end loop;
|
||||
New_Line;
|
||||
end loop;
|
||||
|
|
|
|||
36
Task/Bitmap/Crystal/bitmap.crystal
Normal file
36
Task/Bitmap/Crystal/bitmap.crystal
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
class RGBColor
|
||||
getter red, green, blue
|
||||
|
||||
def initialize(@red = 0_u8, @green = 0_u8, @blue = 0_u8)
|
||||
end
|
||||
|
||||
RED = new(red: 255_u8)
|
||||
GREEN = new(green: 255_u8)
|
||||
BLUE = new(blue: 255_u8)
|
||||
BLACK = new
|
||||
WHITE = new(255_u8, 255_u8, 255_u8)
|
||||
end
|
||||
|
||||
class Pixmap
|
||||
getter width, height
|
||||
@data : Array(Array(RGBColor))
|
||||
|
||||
def initialize(@width : Int32, @height : Int32)
|
||||
@data = Array.new(@width) { Array.new(@height, RGBColor::WHITE) }
|
||||
end
|
||||
|
||||
def fill(color)
|
||||
@data.each &.fill(color)
|
||||
end
|
||||
|
||||
def [](x, y)
|
||||
@data[x][y]
|
||||
end
|
||||
|
||||
def []=(x, y, color)
|
||||
@data[x][y] = color
|
||||
end
|
||||
end
|
||||
|
||||
bmap = Pixmap.new(5, 5)
|
||||
pp bmap
|
||||
|
|
@ -19,5 +19,5 @@ image = new_image(800,600,black)
|
|||
image[400][300] = red
|
||||
|
||||
-- Get pixel color
|
||||
sequence color
|
||||
atom color
|
||||
color = image[400][300] -- Now color is #FF0000
|
||||
|
|
|
|||
35
Task/Bitmap/Kotlin/bitmap.kotlin
Normal file
35
Task/Bitmap/Kotlin/bitmap.kotlin
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
// version 1.1.4-3
|
||||
|
||||
import java.awt.Color
|
||||
import java.awt.Graphics
|
||||
import java.awt.image.BufferedImage
|
||||
|
||||
class BasicBitmapStorage(width: Int, height: Int) {
|
||||
val image = BufferedImage(width, height, BufferedImage.TYPE_3BYTE_BGR)
|
||||
|
||||
fun fill(c: Color) {
|
||||
val g = image.graphics
|
||||
g.color = c
|
||||
g.fillRect(0, 0, image.width, image.height)
|
||||
}
|
||||
|
||||
fun setPixel(x: Int, y: Int, c: Color) = image.setRGB(x, y, c.getRGB())
|
||||
|
||||
fun getPixel(x: Int, y: Int) = Color(image.getRGB(x, y))
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val width = 640
|
||||
val height = 480
|
||||
val bbs = BasicBitmapStorage(width, height)
|
||||
with (bbs) {
|
||||
fill(Color.cyan)
|
||||
setPixel(width / 2, height / 2, Color.black)
|
||||
val c1 = getPixel(width / 2, height / 2)
|
||||
val c2 = getPixel(20, 20)
|
||||
print("The color of the pixel at (${width / 2}, ${height / 2}) is ")
|
||||
println(if (c1 == Color.black) "black" else "unknown")
|
||||
print("The color of the pixel at (120, 120) is ")
|
||||
println(if (c2 == Color.cyan) "cyan" else "unknown")
|
||||
}
|
||||
}
|
||||
|
|
@ -1,37 +1,37 @@
|
|||
/*REXX pgm demonstrates how to handle a simple RGB raster graphics image*/
|
||||
red = '00000000 00000000 11111111'b /*define a red value. */
|
||||
blue = '11111111 00000000 00000000'b /*define a blue value. */
|
||||
blue = 'ff 00 00'x /*another way to define blue. */
|
||||
image.= /*"allocate" an "array" to nulls.*/
|
||||
call RGBfill red /*set the entire image to red. */
|
||||
call RGBset 10,40,blue /*set a pixel to blue. */
|
||||
/*REXX program demonstrates how to process/display a simple RGB raster graphics image.*/
|
||||
red = '00000000 00000000 11111111'b /*define a red value. */
|
||||
blue = '11111111 00000000 00000000'b /* " " blue " */
|
||||
blue = 'ff 00 00'x /*another way to define a blue value.*/
|
||||
image.= /*"allocate" an "array" to nulls. */
|
||||
call RGBfill red /*set the entire image to red. */
|
||||
call RGBset 10, 40, blue /*set a pixel to blue. */
|
||||
|
||||
x=10; y=40; pix=RGBget(x,y) /*get the color of a pixel. */
|
||||
hexv = c2x(pix) /*get hex value of pix's color*/
|
||||
binv = x2b(hexv) /* " binary " " " " */
|
||||
x=10; y=40; pix=RGBget(x, y) /*get the color of a pixel. */
|
||||
hexv = c2x(pix) /*get hex value of pix's color. */
|
||||
binv = x2b(hexv) /* " binary " " " " */
|
||||
|
||||
say 'pixel' x","y '=' binv /*show the binary value of 20,50 */
|
||||
bin3v = left(binv,8) substr(binv,9,8) right(binv,8)
|
||||
say 'pixel' x","y '=' bin3v /*show again, but with spaces. */
|
||||
say /*show a blank between bin & hex.*/
|
||||
say 'pixel' x","y '=' hexv /*show again, but in hexadecimal.*/
|
||||
hex3v = left(hexv,2) substr(hexv,3,2) right(hexv,2)
|
||||
say 'pixel' x","y '=' hex3v /*show again, but with spaces. */
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────RGBFILL subroutine──────────────────*/
|
||||
say 'pixel' x","y '=' binv /*show the binary value of 20,50 */
|
||||
bin3v = left(binv, 8) substr(binv, 9, 8) right(binv, 8)
|
||||
say 'pixel' x","y '=' bin3v /*show again, but with spaces. */
|
||||
say /*show a blank between binary and hex. */
|
||||
say 'pixel' x","y '=' hexv /*show again, but in hexadecimal. */
|
||||
hex3v = left(hexv, 2) substr(hexv, 3, 2) right(hexv, 2)
|
||||
say 'pixel' x","y '=' hex3v /*show again, but with spaces. */
|
||||
exit /*stick a fork in it, we're all done. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
RGBfill: procedure expose image.; image.=arg(1); return
|
||||
/*──────────────────────────────────RGBGET subroutine───────────────────*/
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
RGBget: procedure expose image.; parse arg Xpixel,Ypixel
|
||||
return image.Xpixel.Ypixel /*get & return the pixel's color.*/
|
||||
/*──────────────────────────────────RGBRASTER subroutine────────────────*/
|
||||
return image.Xpixel.Ypixel /*obtain and return the pixel's color. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
RGBraster: procedure expose image.; parse arg Xsize,Ysize,color; RGB=
|
||||
do x=1 to Xsize; _= /*build raster 1 line at a time. */
|
||||
do y=1 to Ysize /* " a line " pixel " " " */
|
||||
_=_ || image.x.y /*append single pixel to the line*/
|
||||
end /*y*/ /* [↑] all done building a line.*/
|
||||
RGB=RGB || _ /*append a single line to raster.*/
|
||||
end /*x*/ /* [↑] all done building raster.*/
|
||||
return RGB /*return RGB raster to invoker. */
|
||||
/*──────────────────────────────────RGBSET subroutine───────────────────*/
|
||||
do x=1 to Xsize; _= /*build raster one line at a time. */
|
||||
do y=1 to Ysize /* " a line " pixel " " " */
|
||||
_=_ || image.x.y /*append single pixel to the line. */
|
||||
end /*y*/ /* [↑] all done building a line. */
|
||||
RGB=RGB || _ /*append a single line to raster. */
|
||||
end /*x*/ /* [↑] all done building raster. */
|
||||
r return RGB /*return RGB raster to the invoker. */
|
||||
/*──────────────────────────────────────────────────────────────────────────────────────*/
|
||||
RGBset: procedure expose image.; parse arg Xpixel,Ypixel,color
|
||||
image.Xpixel.Ypixel=color; return /*define pixel, return to invoker*/
|
||||
image.Xpixel.Ypixel=color; return /*define pixel, return to the invoker. */
|
||||
|
|
|
|||
|
|
@ -10,5 +10,5 @@ const proc: main is func
|
|||
clear(myPixmap, light_green);
|
||||
point(myPixmap, 20, 30, color(256, 512, 768));
|
||||
myColor := getPixelColor(myPixmap, 20, 30);
|
||||
writeln(myColor.red_part <& " " <& myColor.green_part <& " " <& myColor.blue_part);
|
||||
writeln(myColor.redLight <& " " <& myColor.greenLight <& " " <& myColor.blueLight);
|
||||
end func;
|
||||
|
|
|
|||
19
Task/Bitmap/Zkl/bitmap-1.zkl
Normal file
19
Task/Bitmap/Zkl/bitmap-1.zkl
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
class PPM{ // (0,0) is logically bottom left
|
||||
fcn init(width,height){
|
||||
sz:=width*height*3;
|
||||
var [const]
|
||||
data=sz.pump(Data(sz),0), // initialize to Black (RGB=000)
|
||||
w=width, h=height;
|
||||
}
|
||||
fcn fill(rgb){
|
||||
sz:=data.len()/3;
|
||||
data.clear(); sz.pump(data,T(Void,rgb.toBigEndian(3)));
|
||||
}
|
||||
fcn __sGet(x,y) { data.toBigEndian(3*y*w + 3*x,3); } //ppm[x,y]
|
||||
fcn __sSet(rbg,x,y){ data[3*y*w + 3*x,3]=rbg.toBigEndian(3); } //ppm[x,y]=rgb
|
||||
fcn write(out){ // write bottom to top to move (0,0) from bottom left to bottom left
|
||||
out.write("P6\n#rosettacode PPM\n%d %d\n255\n".fmt(w,h));
|
||||
[h-1..0, -1].pump(out,'wrap(h){ data.seek(3*h*w); data.read(3*w) });
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
5
Task/Bitmap/Zkl/bitmap-2.zkl
Normal file
5
Task/Bitmap/Zkl/bitmap-2.zkl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
ppm:=PPM(256,256);
|
||||
ppm.fill(0x00FF88);
|
||||
foreach x in ([50..200]){ ppm[x,50]=0xff|00|00; } // horizontal red line
|
||||
|
||||
ppm.write(File("foo.ppm","wb"));
|
||||
Loading…
Add table
Add a link
Reference in a new issue