def mandelbrot(): MaxIterations = 200 SampleWidth = 3.2 SampleHeight = 2.5 OffsetX = -2.1 OffsetY = -1.25 ImageWidth = 480 ImageHeight = int(SampleHeight * ImageWidth / SampleWidth) query = integers(0, ImageHeight).select(lambda y: (y * SampleHeight) / ImageHeight + OffsetY) \ .select_many_with_correspondence( lambda y: integers(0, ImageWidth).select(lambda x: (x * SampleWidth) / ImageWidth + OffsetX), lambda y, x: (x, y)) \ .select(lambda real_imag: complex(*real_imag)) \ .select(lambda c: query(generate(c, lambda x: x * x + c)) .take_while(lambda x: x.real ** 2 + x.imag ** 2 < 4) .take(MaxIterations) .count()) \ .select(lambda c: ((c * 7) % 255, (c * 5) % 255, (c * 11) % 255) if c != MaxIterations else (0, 0, 0)) data = q.to_list() image = Image.new("RGB", (ImageWidth, ImageHeight)) image.putdata(data) image.show()
def test_range(self): b = integers(54, 7).to_list() self.assertEqual(b, [54, 55, 56, 57, 58, 59, 60])
def test_range_negative_count(self): self.assertRaises(ValueError, lambda: integers(0, -1))
def test_range_count_zero(self): b = integers(7, 0).to_list() self.assertEqual(b, [])
def test_range(self): b = integers(-3, 6).to_list() self.assertEqual(b, [-3, -2, -1, 0, 1, 2])