Chaos game: Difference between revisions

Content added Content deleted
(Replaced "bitmap" and "bresenham" with "imageman".)
Line 1,496: Line 1,496:


==={{header|Writing result into an image}}===
==={{header|Writing result into an image}}===
{{libheader|imageman}}
We use the module “bitmap” from the task “Bitmap”, the module “bresenham” from the task “Bitmap/Bresenham's line algorithm” and the module “ppm_write” from the task “Bitmap/Write a PPM file”.


<lang Nim># Image management.
<lang Nim>import math
import bitmap
import bresenham
import ppm_write

import math
import random
import random

import imageman


const
const
Line 1,548: Line 1,545:
const
const
Iterations = 50_000
Iterations = 50_000
Black = ColorRGBU [byte 0, 0, 0]
PointColor = color(255, 255, 0) # Color for points.
White = ColorRGBU [byte 255, 255, 255]
PointColor = ColorRGBU [byte 255, 255, 0] # Color for points.


# Points in image coordinates.
# Points in image coordinates.
Line 1,558: Line 1,557:


randomize()
randomize()
let image = newImage(Width, Height)
var image = initImage[ColorRGBU](Width, Height)
image.fill(Black)
image.fill(Black)


Line 1,575: Line 1,574:
p = ((p.x + T[idx].x) / 2, (p.y + T[idx].y) / 2)
p = ((p.x + T[idx].x) / 2, (p.y + T[idx].y) / 2)


image.writePPM("x.ppm")</lang>
image.savePNG("chaos_game.png")</lang>


=={{header|PARI/GP}}==
=={{header|PARI/GP}}==