Animierte Rechtecke & Linien - Cool! -Update mit BindEvent

Hier könnt Ihr gute, von Euch geschriebene Codes posten. Sie müssen auf jeden Fall funktionieren und sollten möglichst effizient, elegant und beispielhaft oder einfach nur cool sein.
walbus
Beiträge: 137
Registriert: 03.03.2013 20:50

Animierte Rechtecke & Linien - Cool! -Update mit BindEvent

Beitrag von walbus »

:)
Zuletzt geändert von walbus am 08.02.2015 23:35, insgesamt 24-mal geändert.
Benutzeravatar
alen
Beiträge: 107
Registriert: 09.04.2007 17:38
Computerausstattung: Main Hardware: AMD Ryzen 5 1600 - 6 Core / Gigabyte B450 Aorus Pro / Sapphire RX580 8GB
PB 5.61 and earlier @ Manjaro Linux XFCE x64/ Fedora Linux Cinnamon x64 / Windows 10 x64 on various Hardware Platforms
Wohnort: Duisburg
Kontaktdaten:

Re: Bitweise animiertes Auswahlrechteck - cool !

Beitrag von alen »

Hallo walbus,

sehr geil, das gefällt mir gut !
Jetzt muss ich es nur noch verstehen ;-)

Habe es auf einer Linux Maschine mit Linux (Debian 7 / XFCE) getestet.

Grüße
Alen
---
Main Hardware: AMD Ryzen 5 1600 - 6 Core / Asus B350M-A / Nvidia GTX650
PB 5.61 and earlier @ Manjaro Linux XFCE x64/ Fedora Linux Cinnamon x64 / Windows 10 x64
on various Hardware Platforms (Notebook and Desktop)
Benutzeravatar
NicTheQuick
Ein Admin
Beiträge: 8812
Registriert: 29.08.2004 20:20
Computerausstattung: Ryzen 7 5800X, 64 GB DDR4-3200
Ubuntu 24.04.2 LTS
GeForce RTX 3080 Ti
Wohnort: Saarbrücken

Re: Bitweise animiertes Auswahlrechteck - cool !

Beitrag von NicTheQuick »

Ich habe den Code noch etwas angepasst:
- AddWindowTimer() statt ElapsedMilliseconds()-Konstruktion
- Swap statt tmp-Variable
- Rotation der shift-Variable simuliert
- Ein paar Leerzeichen in die Parameterlisten eingebaut.
- Linie()-Funktion verkürzt

Code: Alles auswählen

EnableExplicit

Procedure Linie(x.i, y.i, xx.i, yy.i, maske.a, color.l, lr.i)
	
	; Angepasster Linienalgorithmus den Udo Kessler 2006 hier im Board postete
	; ( Lineare Interpolation )
	; Danke dafür !
	
	; Achtung Plot unterstützt kein Clipping
	
	Protected a.i, dx.i, dy.i, addval.i = 1, shift.i = maske
	Protected *plotX.Integer = @xx, *plotY.Integer = @yy
	
	If Abs(x - xx) <= Abs(y - yy) ; Winkel größer 45°
		Swap x, y
		Swap xx, yy
		*plotX = @yy
		*plotY = @xx
	EndIf
		
	If x < xx
		Swap x, xx
		Swap y, yy
	EndIf
	
	If y < yy
		y = 2 * yy - y
		addval = -1
	EndIf
	
	dy = 2 * (y - yy)
	a  = x - xx
	dx = 2 * a
	
	While xx <= x
		
		If shift & 1
			Plot(*plotX\i, *plotY\i, color)
		EndIf
		
		If lr
			shift = (shift << 1) | ((shift >> 7) & $7f)
		Else
			shift = ((shift >> 1) & $7F) | (shift << 7)
		EndIf
		
		xx + 1
		a - dy
		If a <= 0
			a + dx
			yy + addval
		EndIf
	Wend
	
EndProcedure

;-------------------------------------------

Procedure Liniego(x.i, y.i, xx.i, yy.i, color.l, move.i, lr.i)
	
	Select move
		Case 0
			Linie(x, y, xx, yy, %11100111, color, lr)
		Case 1
			Linie(x, y, xx, yy, %11111001, color, lr)
		Case 2
			Linie(x, y, xx, yy, %10011111, color, lr)
	EndSelect
	
EndProcedure

;-------------------------------------------

Procedure Boxgo(x.i, y.i, xx.i, yy.i, color.l, move.i)
	
	xx - 1 : yy - 1
	Liniego(x, y, x + xx, y, color, move, 1)
	Liniego(x + xx, y, x + xx, y + yy, color, move, 1)
	Liniego(x, y + yy, x + xx, y + yy, color, move, 0)
	Liniego(x, y + yy, x, y, color, move, 0)
	
EndProcedure

; --------Loop-----------------------------

Define.i move = 0

ExamineDesktops()

If OpenWindow (0, DesktopWidth(0) / 2 - 200, DesktopHeight(0) / 2 - 250, 500, 250, "")
	
	CanvasGadget(0, 0, 0, 500 , 400)
	AddWindowTimer(0, 0, 100)
	
	Repeat
		Select WaitWindowEvent()
			Case #PB_Event_CloseWindow:
				Break
			
			Case #PB_Event_Timer
				If EventTimer() = 0
					If StartDrawing(CanvasOutput(0))
						DrawingMode(#PB_2DDrawing_Outlined) ; Zeichnen von Flächen erfolgt nicht ausgefüllt
						Box   (150, 70, 200, 100, $FFFFFF)
						Box   (149, 69, 202, 102, $FFFFFF)
						Box   (144, 64, 212, 112, $FFFFFF)
						Boxgo (150, 70, 200, 100, $FF, move)
						Boxgo (149, 69, 202, 102, $FF, move)
						Boxgo (144, 64, 212, 112, $0 , move)
					
						StopDrawing()
					EndIf
			
					move + 1 ; Animations Counter für bewegte Linien
					If move > 2
						move = 0
					EndIf
				EndIf
			
		EndSelect
		
	ForEver
	
EndIf
Benutzeravatar
ts-soft
Beiträge: 22292
Registriert: 08.09.2004 00:57
Computerausstattung: Mainboard: MSI 970A-G43
CPU: AMD FX-6300 Six-Core Processor
GraKa: GeForce GTX 750 Ti, 2 GB
Memory: 16 GB DDR3-1600 - Dual Channel
Wohnort: Berlin

Re: Bitweise animiertes Auswahlrechteck - cool !

Beitrag von ts-soft »

:allright:
Sehr schön, kann ich bestimmt mal gebrauchen!

Danke auch an NicTheQuick für die Erhöhung der Lesbarkeit :D
PureBasic 5.73 LTS | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Nutella hat nur sehr wenig Vitamine. Deswegen muss man davon relativ viel essen.
Bild
Antworten