Quadratic Beziersplines Demo
Übersicht

![]() |
FirstdeathmakerBetreff: Quadratic Beziersplines Demo |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hier ne kleine Spielerrei zu quadratischen Bezierkurven (Keine Kubischen!). Könnte man auch als Bildschirmschoner missbrauchen ![]() Die Idee für den kleinen grafischen Effekt stammt von der Echtzeitblurdemo im 3D Bereich, hier nur eben angewand auf ein Bild. ![]() ![]() Code: [AUSKLAPPEN] Rem
Code by Christian Geißler alias Firstdeathmaker (c) 2006 Quadratic Beziersplines gfx-demo End Rem SuperStrict Const GFX_X:Int = 1280 Const GFX_Y:Int = 1024 Graphics GFX_X,GFX_Y,32 SeedRnd MilliSecs() Type TBezierSpline Field TNodeList:TList Method New() Self.TNodeList = New TList End Method Method AddNode:TBezierNode(X1:Float,Y1:Float,X2:Float,Y2:Float) Return TBezierNode.Create(X1,Y1,X2,Y2,Self) End Method Method AddFNode:TBezierNode(X1:Float,Y1:Float) Return TBezierNode.CreateF(X1,Y1,Self) End Method Method Update() For Local TBN:TBezierNode = EachIn Self.TNodeList:TList TBN.Update() Next End Method Method Draw() For Local TBN:TBezierNode = EachIn Self.TNodeList:TList TBN.Draw(20) Next End Method End Type Type TBezierNode Field Px:Float[2]' 0=Startpoint 1=Directionpoint Field Py:Float[2]' 0=Startpoint 1=Directionpoint Field Direction:Float Field Speed:Float Field _link:TLink Function Create:TBezierNode(X1:Float,Y1:Float,X2:Float,Y2:Float,BS:TBezierSpline) Local TBN:TBezierNode = New TBezierNode TBN.Px[0] = X1 TBN.Py[0] = Y1 TBN.Px[1] = X2 TBN.Py[1] = Y2 TBN.Direction = Rand(0,360) TBN.Speed = Rnd(0.5,2.5) TBN._link = BS.TNodeList.Addlast(TBN) Return TBN End Function Function CreateF:TBezierNode(X1:Float,Y1:Float,BS:TBezierSpline) Local TBNprev:TBezierNode = TBezierNode(BS.TNodeList.Last()) Local X2:Float = X1 - (TBNprev.Px[1] - X1) Local Y2:Float = Y1 - (TBNprev.Py[1] - Y1) Return TBezierNode.Create(X1,Y1,X2,Y2,BS) End Function Method Move(X1:Float,Y1:Float) Local prevLink:TLink = Self._link.PrevLink() If prevLink <> Null Local TBNprev:TBezierNode = TBezierNode(prevLink.Value()) Local X2:Float = X1 - (TBNprev.Px[1] - X1) Local Y2:Float = Y1 - (TBNprev.Py[1] - Y1) Self.Px[0] = X1 Self.Py[0] = Y1 Self.Px[1] = X2 Self.Py[1] = Y2 EndIf End Method Method Update() Local Xn:Float = Px[0] + Sin(Self.Direction) * Self.Speed Local Yn:Float = Py[0] - Cos(Self.Direction) * Self.Speed If Xn < GFX_X*3/8 Self.Direction = Self.Direction - 180 Xn = GFX_X*3/8 ElseIf Xn > GFX_X*5/8 Self.Direction = Self.Direction - 180 Xn = GFX_X*5/8 ElseIf Yn < GFX_Y*3/8 Self.Direction = Self.Direction - 180 Yn = GFX_Y*3/8 ElseIf Yn > GFX_Y*5/8 Self.Direction = Self.Direction - 180 Yn = GFX_Y*5/8 EndIf Self.Move(Xn,Yn) End Method Method Draw(Resolution:Int = 10) Local sw:Float = 1.0 / Resolution ' sw = Step Width Local After:TLink = Self._link.Nextlink() If After = Null'Select Firt Object in List Local First:TLink = Self._link.PrevLink() While First.PrevLink() <> Null First = First.PrevLink() Wend After = First EndIf If After <> Null Local TBN:TBezierNode = TBezierNode(After.Value()) For Local i:Int = 0 To (Resolution-1) Local t1:Float = i * sw Local t2:Float = t1 + sw Local x1:Float = (1 - t1)^2 * Px[0] + 2*t1*(1 - t1)*Px[1] + t1^2 * TBN.Px[0] Local y1:Float = (1 - t1)^2 * Py[0] + 2*t1*(1 - t1)*Py[1] + t1^2 * TBN.Py[0] Local x2:Float = (1 - t2)^2 * Px[0] + 2*t2*(1 - t2)*Px[1] + t2^2 * TBN.Px[0] Local y2:Float = (1 - t2)^2 * Py[0] + 2*t2*(1 - t2)*Py[1] + t2^2 * TBN.Py[0] DrawLine x1,y1,x2,y2 Next EndIf End Method End Type '### Init ### Global Spline:TBezierSpline = New TBezierSpline Spline.AddNode(0,0,0,0) Global Actual:TBezierNode Global BGImage:TImage = CreateImage(GFX_X/4,GFX_Y/4,1,DYNAMICIMAGE) MidHandleImage BGImage For Local i:Int = 0 To 5 Actual = Spline.AddFNode(GFX_X/2,GFX_Y/2) Next Global CounterR:Int = 255 Global CounterG:Int = 245 Global CounterB:Int = 245 Global MODE:Byte = 0 HideMouse '### MAINLOOP ### Repeat Cls 'Select actual draw-color If CounterR = 255 And CounterG < 255 CounterG:+1 CounterB:-1 ElseIf CounterG = 255 And CounterB < 255 CounterB:+1 CounterR:-1 Else CounterR:+1 CounterG:-1 EndIf 'draw inner image SetAlpha 0.99 SetScale 1.1,1.1 SetColor CounterR,CounterG,CounterB DrawImage BGImage,GFX_X/2,GFX_Y/2 SetColor 255,255,255 SetScale 1,1 SetAlpha 1 Spline.Update()'Update Splinecoord´s Spline.Draw()'Draw Splines GrabImage BGIMage,GFX_X*3/8,GFX_Y*3/8 'Select and execute different graphic modes If KeyHit(KEY_SPACE) MODE = (MODE + 1) Mod 3 Select MODE Case 1 SetScale 4,4 DrawImage BGImage,GFX_X/2,GFX_Y/2 SetScale 1,1 Case 2 SetBlend Alphablend SetScale 4,4 DrawImage BGImage,GFX_X/2,GFX_Y/2 SetScale 1,1 End Select 'Inforect upper left corner SetBlend alphablend SetColor 0,0,0 SetAlpha 0.5 DrawRect 8,8,220,35 SetColor 255,255,255 SetAlpha 1 DrawText "Hit 'Space' to change mode",10,10 DrawText "By Firstdeathmaker Mode: "+MODE,10,25 SetBlend lightblend Flip Until KeyHit(KEY_ESCAPE) End |
||
www.illusion-games.de
Space War 3 | Space Race | Galaxy on Fire | Razoon Gewinner des BCC #57 User posted image |
![]() |
tft |
![]() Antworten mit Zitat ![]() |
---|---|---|
Hi ...
BMax onlie |
||
TFT
https://www.sourcemagic.ch Monkey,HTML5,CSS3,W 10 64 Bit, 32 GB Ram, GTX Titan, W8 ist Müll !!!!!! |
![]() |
Firstdeathmaker |
![]() Antworten mit Zitat ![]() |
---|---|---|
Ja sicher, deshalb steht es ja auch im BMax Codearchiv. | ||
www.illusion-games.de
Space War 3 | Space Race | Galaxy on Fire | Razoon Gewinner des BCC #57 User posted image |
Übersicht


Powered by phpBB © 2001 - 2006, phpBB Group