Voronoi - Transformation

Übersicht BlitzBasic Codearchiv

Neue Antwort erstellen

TimBo

Betreff: Voronoi - Transformation

BeitragDo, Jul 09, 2015 23:11
Antworten mit Zitat
Benutzer-Profile anzeigen
Hallo,

für eine Hausaufgabe musste ich eine Punktewolke Voronoi - Transformieren.
ist ziemlich dirty, aber vielleicht kann jemand den Code gebrauchen.
https://de.wikipedia.org/wiki/Voronoi-Diagramm


BlitzBasic: [AUSKLAPPEN]
Graphics (1024, 786, 32, 2)
Local timer = CreateTimer(60)

Local texWidth = 700
Local texHeight = 700
Local pointCount = 10
Dim Points(pointCount,2)

Points(0,0) = 77
Points(0,1) = 106
Points(0,2) = toARGB(255,255,255)

Points(1,0) = 286
Points(1,1) = 80
Points(1,2) = toARGB(0,255,255)

Points(2,0) = 544
Points(2,1) = 56
Points(2,2) = toARGB(255,0,255)

Points(3,0) = 93
Points(3,1) = 264
Points(3,2) = toARGB(255,255,0)

Points(4,0) = 292
Points(4,1) = 321
Points(4,2) = toARGB(0,0,0)

Points(5,0) = 394
Points(5,1) = 206
Points(5,2) = toARGB(128,0,0)

Points(6,0) = 570
Points(6,1) = 174
Points(6,2) = toARGB(0,128,0)

Points(7,0) = 160
Points(7,1) = 500
Points(7,2) = toARGB(0,0,128)

Points(8,0) = 395
Points(8,1) = 471
Points(8,2) = toARGB(128,128,0)

Points(9,0) = 617
Points(9,1) = 441
Points(9,2) = toARGB(128,0,128)


img = CreateImage(texWidth,texHeight)
imgBuffer = ImageBuffer(img)
SetBuffer imgBuffer


Local currentDistance
Local minDistance
Local minIndex

LockBuffer imgBuffer
For x=0 To texWidth
For y=0 To texHeight

minIndex = 0
minDistance = 0

For c=0 To pointCount-1
currentDistance = (x-Points(c,0))*(x-Points(c,0)) + (y-Points(c,1))*(y-Points(c,1))
If ((minDistance > currentDistance) Or (minDistance = 0))
minDistance = currentDistance
minIndex = c
EndIf
Next
WritePixelFast x,y,Points(minIndex,2),imgBuffer
Next
Next
UnlockBuffer imgBuffer

SetBuffer BackBuffer()

Repeat
DrawImage(img,0,0)

Color 255,0,0
For i=0 To pointCount-1
Oval Points(i,0)-2, Points(i,1)-2, 4, 4
Next

WaitTimer(timer)
Flip(0):Cls
Until(KeyHit(1))


Function toARGB(r, g, b, a=255)
Return a*$1000000 + r*$10000 + g*$100 + b
End Function


Grüße,
TimBo
mfg Tim Borowski // CPU: Ryzen 2700x GPU: Nvidia RTX 2070 OC (Gigabyte) Ram: 16GB DDR4 @ 3000MHz OS: Windows 10
Stolzer Gewinner des BCC 25 & BCC 31
hat einen ersten Preis in der 1. Runde beim BWInf 2010/2011 & 2011/12 mit BlitzBasic erreicht.
 

Matthias

BeitragFr, Jul 10, 2015 12:25
Antworten mit Zitat
Benutzer-Profile anzeigen
Very Happy

Das ist ja mal eine richtig Coole Sache.

Damit könnte ich ein Heighmap-Generator programmieren wo dann die einzelnen Quadtranten Insel sind.

Neue Antwort erstellen


Übersicht BlitzBasic Codearchiv

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group