File: mkimage_gradient.castlescript

package info (click to toggle)
castle-game-engine 6.4%2Bdfsg1-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 194,520 kB
  • sloc: pascal: 364,585; ansic: 8,606; java: 2,851; objc: 2,601; cpp: 1,412; xml: 851; makefile: 725; sh: 563; php: 26
file content (19 lines) | stat: -rw-r--r-- 685 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
{ Make a simple image with radial gradient (middle of the image is yellow,
  borders are blue). }

function main()
  result := image(100, 100, 3);

  { y = maximum distance of image pixel from the middle of the image. }
  y := sqrt(sqr(image_width(result)/2) +
            sqr(image_height(result)/2));

  for (i, 0, image_width(result) - 1,
    for (j, 0, image_height(result) - 1,
      { x = number between 0...1 corresponding to distance of (i, j)
        from image middle. }
      x := sqrt(sqr(i - image_width(result)/2) +
                sqr(j - image_height(result)/2)) / y;
      image_set_color(result, i, j,
        vector(1, 1, 0) * x +
        vector(0, 0, 1) * (1-x))))