Hi,
mir war grad fad in der Schule, hab ich jetzt noch bissl ausgebaut mit ner Triangle Funktion ausm BB.com Codearchiv...
BlitzBasic: [AUSKLAPPEN] [EINKLAPPEN] Const gw = 1024 Const gh = 768 Const radius = 100 Const speed = 2
Type star Field x, y, rot Field r, g, b End Type
Graphics gw, gh, 32, 1 SetBuffer BackBuffer()
rot = 0
SeedRnd MilliSecs()
x = gw/2 y = gh/2 xspeed = speed yspeed = speed
Repeat fp = fp+1 If MilliSecs()-lasttime > 1000 Then lasttime = MilliSecs() fps = fp fp = 0 End If If MilliSecs()-lasttime2 > 20 Then rot = rot+1 x = x+xspeed y = y+yspeed If x-radius <= 0 Then xspeed = speed If y-radius <= 0 Then yspeed = speed If x+radius >= gw Then xspeed = -speed If y+radius >= gh Then yspeed = -speed CreateStar(x, y, rot) For s.star = Each star s\r = s\r - 5 s\g = s\g - 5 s\b = s\b - 5 Next lasttime2 = MilliSecs() End If For s.star = Each star Color s\r, s\g, s\b DrawStar(s\x, s\y, radius, 39, s\rot, 5, (s\r/255)) If s\r <= 10 Then Delete s Next Color 0, 0, 255 Text x, y, fps, 1, 1 Flip 0 Cls Until KeyDown(1)
End
Function DrawStar(x#, y#, r1#, r2#, r# = 90, segs# = 5, full = 0) segr# = 360/segs If full Then For i=0 To segs-1 DrawTriangle x, y, x+Cos(i*segr+r)*r1, y+Sin(i*segr+r)*r1, x+Cos((i+.5)*segr+r)*r2, y+Sin((i+.5)*segr+r)*r2 DrawTriangle x, y, x+Cos((i+.5)*segr+r)*r2, y+Sin((i+.5)*segr+r)*r2, x+Cos((i+1)*segr+r)*r1, y+Sin((i+1)*segr+r)*r1 Next Else For i=0 To segs-1 Line x+Cos(i*segr+r)*r1, y+Sin(i*segr+r)*r1, x+Cos((i+.5)*segr+r)*r2, y+Sin((i+.5)*segr+r)*r2 Line x+Cos((i+.5)*segr+r)*r2, y+Sin((i+.5)*segr+r)*r2, x+Cos((i+1)*segr+r)*r1, y+Sin((i+1)*segr+r)*r1 Next End If End Function
Function CreateStar(x, y, rot) s.star = New star s\x = x s\y = y s\rot = rot s\r = 260 s\g = 260 s\b = 260 End Function
Function DrawTriangle(x1,y1,x2,y2,x3,y3) Local topx,topy,midx,midy,botx,boty,mstep1#,mstep2#,x#,y#,fromy,toy#,edge1,edge2 If y1 <= y2 If y2 <= y3 topx = x1 : topy = y1 : midx = x2 : midy = y2 : botx = x3 : boty = y3 Else If y1 <= y3 topx = x1 : topy = y1 : midx = x3 : midy = y3 : botx = x2 : boty = y2 Else topx = x3 : topy = y3 : midx = x1 : midy = y1 : botx = x2 : boty = y2 End If End If Else If y2 <= y3 If y1 <= y3 topx = x2 : topy = y2 : midx = x1 : midy = y1 : botx = x3 : boty = y3 Else topx = x2 : topy = y2 : midx = x3 : midy = y3 : botx = x1 : boty = y1 End If Else topx = x3 : topy = y3 : midx = x2 : midy = y2 : botx = x1 : boty = y1 EndIf End If If botx-topx=0 mstep1# = 0 Else If boty-topy=0 mstep1# = 0 Else mstep1# = Float#(botx-topx)/Float#(boty-topy) End If End If x# = topx fromy = topy toy = boty If fromy<0 x# = x#+(mstep1#*Abs(toy)) fromy = 0 End If For y = fromy To toy edge1 = x# If edge1 < 0 edge1 = 0 End If If y < midy If midx-topx=0 mstep2# = 0 Else If midy-topy=0 mstep2# = 0 Else mstep2# = Float#(midx-topx)/Float#(midy-topy) End If End If edge2 = topx + (mstep2# * (y-topy)) If edge2 < 0 edge2 = 0 End If Else If botx-midx=0 mstep2# = 0 Else If boty-midy=0 mstep2# = 0 Else mstep2# = Float#(botx-midx)/Float#(boty-midy) End If End If edge2 = midx + (mstep2# * (y-midy)) If edge2 < 0 edge2 = 0 End If End If If edge1 <> edge2 Line edge1,y,edge2,y x#=x#+mstep1# Next End Function
Mfg Xenon/Skate
|