Add tasks for all the new languages

This commit is contained in:
Tina Müller 2016-12-05 23:44:36 +01:00
parent 9dc3c2bb62
commit bba7bfd280
13208 changed files with 134745 additions and 0 deletions

View file

@ -0,0 +1,10 @@
Buff(768)→Pic1
Fill(Pic1,768,255)
Pxl-Off(45,30,Pic1)
.Display the bitmap to demonstrate
Copy(Pic1)
DispGraph
Pause 4500
Disp pxl-Test(50,50,Pic1)▶Dec,i

View file

@ -0,0 +1,32 @@
(lib 'plot)
(define width 600)
(define height 400)
(plot-size width height) ;; set image size
(define (blue x y) (rgb 0.0 0.0 1.0)) ;; a constant function
(plot-rgb blue 1 1) ;; blue everywhere
(lib 'types) ;; uint32 and uint8 vector types
;; bit-map pixel access
(define bitmap (pixels->uint32-vector)) ;; screen to vector of int32
→ 240000
(define (pix-at x y) (vector-ref bitmap (+ x (* y width))))
(rgb->list (pix-at 100 200)) → (0 0 255 255) ;; rgb blue
;; writing to bitmap
(define (set-color-xy x y col) (vector-set! bitmap (+ x (* y width)) col))
(for* ((x 100)(y 200)) (set-color-xy x y (rgb 1 1 0))) ;; to bitmap
(vector->pixels bitmap) ;; bitmap to screen
;; bit-map color components (r g b a) = index (0 1 2 3) access
(define bitmap (pixels->uint8-clamped-vector)) ;; screen to vector of uint8
(vector-length bitmap)
→ 960000
(define (blue-at-xy x y) (vector-ref bitmap (+ x 3 (* y width)))) ;; 3 = blue component
(blue-at-xy 100 200)
→ 255

View file

@ -0,0 +1,11 @@
-- Creates a new image object of size 640x480 pixel and 32-bit color depth
img = image(640, 480, 32)
-- Fills image with plain red
img.fill(img.rect, rgb(255,0,0))
-- Gets the color value of the pixel at point (320, 240)
col = img.getPixel(320, 240)
-- Changes the color of the pixel at point (320, 240) to black
img.setPixel(320, 240, rgb(0,0,0))

View file

@ -0,0 +1,61 @@
{.experimental.}
import unsigned
type
Luminance = uint8
Index = int
Pixel = tuple
r, g, b: Luminance
Image = object
w, h: Index
pixels: seq[Pixel]
Point = tuple
x, y: Index
proc px(r, g, b): Pixel =
result.r = r.uint8
result.g = g.uint8
result.b = b.uint8
proc img(w, h: int): Image =
result.w = w
result.h = h
result.pixels.newSeq(w * h)
const
Black = px( 0, 0, 0)
White = px(255, 255, 255)
iterator indices(img: Image): tuple[x, y: int] =
for x in 0 .. < img.w:
for y in 0 .. < img.h:
yield (x,y)
proc `[]`(img: Image, x, y: int): Pixel =
img.pixels[y * img.w + x]
proc `[]=`(img: var Image, x, y: int, c: Pixel) =
img.pixels[y * img.w + x] = c
proc fill(img: var Image, color: Pixel) =
for x,y in img.indices:
img[x,y] = color
proc print(img: Image) =
using stdout
for x,y in img.indices:
if img[x,y] == White:
write ' '
else:
write 'H'
write "\n"
when isMainModule:
var x = img(64, 64)
x.fill px(255,255,255)
x[1,2] = px(255, 0, 0)
x[3,4] = x[1,2]

View file

@ -0,0 +1,20 @@
-- Some colour constants:
constant black = #000000,
-- blue = #0000FF,
-- green = #00FF00,
-- red = #FF0000,
white = #FFFFFF
-- Create new image filled with some colour
function new_image(integer width, integer height, integer fill_colour=black)
return repeat(repeat(fill_colour,height),width)
end function
-- Usage example:
sequence image = new_image(800,600)
-- Set pixel color:
image[400][300] = white
-- Get pixel color
integer colour = image[400][300] -- Now colour is #FF0000

View file

@ -0,0 +1,38 @@
RGB ::= (R: int(0), G: int(0), B: int(0));
newBitmap: int * int -> RGB(2);
newBitmap(width, height)[y, x] :=
(R: 0, G: 0, B: 0)
foreach y within 1 ... height,
x within 1 ... width;
fill: RGB(2) * RGB -> RGB(2);
fill(bitmap(2), color)[y, x] :=
color
foreach y within 1 ... size(bitmap),
x within 1 ... size(bitmap[y]);
setColorAt: RGB(2) * int * int * RGB -> RGB(2);
setColorAt(bitmap(2), x, y, color)[Y, X] :=
color when Y = y and X = x
else
bitmap[Y, X];
getColorAt: RGB(2) * int * int -> RGB;
getColorAt(bitmap(2), x, y) := bitmap[y, x];
lightGreen := (R: 51, G: 255, B: 51);
lightRed := (R: 255, G: 51, B: 51);
main(args(2)) :=
let
width := 1920;
height := 1200;
cleanImage := newBitmap(width, height);
filledGreen := fill(cleanImage, lightGreen);
redCenter := setColorAt(filledGreen, width / 2, height / 2, lightRed);
in
getColorAt(redCenter, width / 2, height / 2);