How to resolve the algorithm Voronoi diagram step by step in the BASIC256 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Voronoi diagram step by step in the BASIC256 programming language

Table of Contents

Problem Statement

A Voronoi diagram is a diagram consisting of a number of sites. Each Voronoi site s also has a Voronoi cell consisting of all points closest to s.

Demonstrate how to generate and display a Voroni diagram.

See algo K-means++ clustering.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Voronoi diagram step by step in the BASIC256 programming language

Source code in the basic256 programming language

global ancho, alto
ancho = 500 : alto = 500

clg
graphsize ancho, alto

function hypot(a, b)
	return sqr(a^2+b^2)
end function

subroutine Generar_diagrama_Voronoi(ancho, alto, num_celdas)
	dim nx(num_celdas+1)
	dim ny(num_celdas+1)
	dim nr(num_celdas+1)
	dim ng(num_celdas+1)
	dim nb(num_celdas+1)

	for i = 0 to num_celdas
		nx[i] = int(rand * ancho)
		ny[i] = int(rand * alto)
		nr[i] = int(rand * 256) + 1
		ng[i] = int(rand * 256) + 1
		nb[i] = int(rand * 256) + 1
	next i
	for y = 1 to alto
		for x = 1 to ancho
			dmin = hypot(ancho-1, alto-1)
			j = -1
			for i = 1 to num_celdas
				d = hypot(nx[i]-x, ny[i]-y)
				if d < dmin then dmin = d : j = i
			next i
			color rgb(nr[j], ng[j], nb[j])
			plot (x, y)
		next x
	next y
end subroutine

call Generar_diagrama_Voronoi(ancho, alto, 25)
refresh
imgsave "Voronoi_diagram.jpg", "jpg"
end

  

You may also check:How to resolve the algorithm Write language name in 3D ASCII step by step in the Plain English programming language
You may also check:How to resolve the algorithm Polymorphism step by step in the Clojure programming language
You may also check:How to resolve the algorithm Character codes step by step in the Elena programming language
You may also check:How to resolve the algorithm Humble numbers step by step in the C# programming language
You may also check:How to resolve the algorithm Zsigmondy numbers step by step in the Phix programming language