Julia set

Julia draws a julia set in little window. Julia demonstrates how to spawn a thread for drawing and do some RPN expressions to plot the pixels to window. Written in plain Ano script, no C involved.

Compilation

Easiest way to get Julia running is to go to examples directory in package root, and run:

$ ./build.sh gui_julia

build.sh script compiles Ano script to C, copies source files in place and pops up instructions what to do next. Follow them. Check also examples/README for more info.

Screenshots

Julia set

Preview

;
; @ANO_SCRIPT_NAME		gui_julia
; @ANO_SCRIPT_VERSION		0.0.3
; @ANO_SCRIPT_DESCRIPTION	Example how to plot some pixels to window
;
; @ANO_FLAGS_VAR_NAME_SUBS	[x]
; @ANO_FLAGS_VAR_WARN_UNUSED	[ ]
;
; Copyright (c) 2016-2023, Jani Salonen <salojan at goto10 piste co>
; All rights reserved.
;

	; Global uninitialized variables
	var	[handle] handle_window_main

	; Global pre-initialized variables
	mov	win_w ([uint] 640)
	mov	win_h ([uint] 400)

	; Initialize windowing system
	window_init

	; Open main window
	window_open ("Julia", NULL, \
		[handle] @0, [uint] 0, [uint] 0, [uint] 1, \
		[int] -1, [int] -1, win_w, win_h, \
		NULL, NULL, NULL, NULL, NULL, NULL, \
		NULL, NULL, "cb_destroy", \
		NULL, NULL, NULL, "cb_open")
	end

callback cb_open (_hnd) {
	mov	handle_window_main (_hnd)

	; Map main window
	window_map (handle_window_main)

	; Create drawing thread
	thread_spawn ("Julia thread", "julia_thread")
}

callback cb_destroy {
	window_close (handle_window_main)

	exit
}

thread julia_thread {
	call	"julia_draw" (1.0, [int] 120, [int] 0, [int] 0)
}

function julia_draw (_zoom, _maxiterations, _posx, _posy) {
	var	[color] _c

	mov	_ce (-0.7)
	mov	_cm (0.27015)

	loop (mov _y (0); _y < win_h; inc _y) {
		loop (mov _x (0); _x < win_w; inc _x) {
			mov	_ne (1.5 * (_x - win_w / 2.0) / (0.5 * _zoom * win_w) + _posx)
			mov	_nf ((_y - win_h / 2.0) / (0.5 * _zoom * win_h) + _posy)

			mov	_i ([int] 0)

		: "julia_loop_c"
			mov	_oe (_ne)
			mov	_of (_nf)

			mov	_ne (_oe * _oe - _of * _of + _ce)
			mov	_nf (2.0 * _oe * _of + _cm)

			mov	_t (_ne * _ne + _nf * _nf)
			cmp	_t (4)
			jae	"julia_loop_d"

			inc	_i
			cmp	_i (_maxiterations)
			jb	"julia_loop_c"

		: "julia_loop_d"
			; Plot the pixel adjusting colors a bit
			mov	_c (# 0)
			add	_c.green (_i * 2.0)
			draw_pixel (handle_window_main, _x, _y, _c)
		}
	}
}

Copyright © 2023, Jani Salonen <salojan at goto10 piste co>. Piste is finnish word and means dot. All rights reserved.