Example #1
0
def processAttractor(AttractorNum):
	MAP = {
		'__date' : datetime.today().strftime("%Y, %b %d"),
		'__order': 2,
		'__code' : "",
		'__iterations' : 0,
		'__dimension' : 2,
		'__lyapunov' : 0.0,
		'__link' : "",
		'__x_polynom' : "",
		'__y_polynom' : "",
		'__z_polynom' : "",
		'__time' : "",
		'__type' : "polynomial",
	}
	maxFileNameLength = os.statvfs('/').f_namemax
	dt = REFERENCE_DATE + timedelta(days=attractorNum-1)
	MAP['__date'] = dt.strftime("%Y, %b %d")
	t = AttractorNum % 7
	if t == 0:
		MAP['__type'] = "dejong"
	else:
		MAP['__type'] = "polynomial"
	MAP['__order'] = t + 1

	subsampling = 3
	colorscheme = random.choice(('light', 'dark'))
	dimension = 2 if MAP['__type'] == "dejong" or MAP['__order'] > 4 else random.choice((2,3))
	logging.info("Today is %s. %s attractor generation starts." % (MAP['__date'], numeral(attractorNum)))
	logging.info("We have a %s attractor (order %d, dimension %d)." % (MAP['__type'], MAP['__order'], dimension))
	logging.info("Color scheme used: " + colorscheme)

	while True:
		done = False
		at = createAttractor(MAP['__type'], MAP['__order'], dimension)
		for parameters in ( {'geometry': (1000, 1000), 'directory': '/tmp'}, ):
			t0 = time()
			iterations = util.getIdealIterationNumber(MAP['__type'], parameters['geometry'], subsampling)
			logging.debug("Num iterations: %d", iterations)
			at.iterations = iterations
			r = render.Renderer(bpc=8,
				geometry=parameters['geometry'],
				subsample=subsampling,
				colormode=colorscheme,
				dimension=dimension)
			a = at.createFrequencyMap(r.geometry, args.nthreads)
			if not r.isNice(a):
				logging.debug("Attractor too thin. Trying to find a better one.")
				break
			a = r.renderAttractor(a)
			if a == None: break

			suffix = '_8.png'
			if len(at.code) < maxFileNameLength - len(suffix):
				filePath = at.code + suffix
			else:
				filePath = at.code[:maxFileNameLength-len(suffix)-1] + '#' + suffix
			# TODO: we should check that full path is not too long
			fname = os.path.join(parameters['directory'], filePath)
			r.writeAttractorPNG(a, fname)
			done = True
			t1 = time()
		if done: break

	MAP['__code'] = at.code
	if MAP['__type'] == 'polynomial':
		MAP['__order'] = str(at.order)
	else:
		MAP['__order'] = 'irrelevant'

	if dimension == 3:
		MAP['__x_polynom'], MAP['__y_polynom'], MAP['__z_polynom'] = at.humanReadable(isHTML=True)
	else:
		MAP['__x_polynom'], MAP['__y_polynom'] = at.humanReadable(isHTML=True)

	MAP['__iterations'] = str(at.iterations)
	MAP['__dimension'] = "%.3f" % (at.fdim)
	MAP['__lyapunov'] = "%.3f" % (at.lyapunov['ly'])
	MAP['__link'] = filePath
	MAP['__prev'] = "#" if attractorNum == 1 else "%d.xhtml" % (attractorNum-1)
	MAP['__time'] = sec2hms(t1-t0)
	return MAP
Example #2
0
        type=str,
        choices=("polynomial", "dejong"),
    )
    args = parser.parse_args()
    if args.code and args.code[0] == "j":
        args.type = "dejong"
    return args


# ----------------------------- Main loop ----------------------------- #

args = parseArgs()
logging.basicConfig(stream=sys.stderr, level=LOGLEVELS[args.loglevel])
random.seed()

g = [int(x) for x in args.geometry.split("x")]
# TODO - check validity of g

idealIter = util.getIdealIterationNumber(args.type, g, args.subsample)
if args.iter == None:
    args.iter = idealIter
    logging.debug("Setting iteration number to %d." % (args.iter))
elif args.iter < idealIter:
    logging.warning("For better rendering, you should use at least %d iterations." % idealIter)

if args.code or args.sequence:
    args.number = 1

for i in xrange(0, args.number):
    generateAttractor(g, args.threads)
Example #3
0
def processAttractor(AttractorNum):
    MAP = {
        "__date": datetime.today().strftime("%Y, %b %d"),
        "__order": 2,
        "__code": "",
        "__iterations": 0,
        "__dimension": 2,
        "__lyapunov": 0.0,
        "__link": "",
        "__x_polynom": "",
        "__y_polynom": "",
        "__time": "",
        "__type": "polynomial",
    }

    dt = REFERENCE_DATE + timedelta(days=attractorNum - 1)
    MAP["__date"] = dt.strftime("%Y, %b %d")
    t = AttractorNum % 7
    if t == 0:
        MAP["__type"] = "dejong"
    else:
        MAP["__type"] = "polynomial"
    MAP["__order"] = t + 1

    subsampling = 3
    logging.info("Today is %s. %s attractor generation starts." % (MAP["__date"], numeral(attractorNum)))
    logging.info("We have a %s attractor (order %d)." % (MAP["__type"], MAP["__order"]))

    while True:
        done = False
        at = createAttractor(MAP["__type"], MAP["__order"])
        filePath = at.code + "_8.png"
        for parameters in (
            {"geometry": (800, 600), "directory": "png_thumb", "type": "thumbnail"},
            {"geometry": (1920, 1080), "directory": "png", "type": "main"},
        ):
            t0 = time()
            iterations = util.getIdealIterationNumber(MAP["__type"], parameters["geometry"], subsampling)
            logging.debug("Num iterations: %d", iterations)
            at.iterations = iterations
            r = render.Renderer(bpc=8, mode="greyscale", geometry=parameters["geometry"], subsample=subsampling)
            a = at.createFrequencyMap(r.geometry, args.nthreads)
            if not r.isNice(a) and parameters["type"] == "thumbnail":
                break
            a = r.renderAttractor(a)
            if a == None:
                break
            r.writeAttractorPNG(a, os.path.join(parameters["directory"], filePath))
            if parameters["type"] == "main":
                done = True
            t1 = time()
        if done:
            break

    MAP["__code"] = at.code
    if MAP["__type"] == "polynomial":
        MAP["__order"] = str(at.order)
    else:
        MAP["__order"] = "irrelevant"

    MAP["__x_polynom"], MAP["__y_polynom"] = at.humanReadable(isHTML=True)
    MAP["__iterations"] = str(at.iterations)
    MAP["__dimension"] = "%.3f" % (at.fdim)
    MAP["__lyapunov"] = "%.3f" % (at.lyapunov["ly"])
    MAP["__link"] = filePath
    MAP["__prev"] = "#" if attractorNum == 1 else "%d.xhtml" % (attractorNum - 1)
    MAP["__time"] = sec2hms(t1 - t0)
    return MAP