Dreieck-Berechnungen

Übersicht BlitzBasic Codearchiv

Neue Antwort erstellen

blitzmaster

Betreff: Dreieck-Berechnungen

BeitragMo, Mai 16, 2005 16:55
Antworten mit Zitat
Benutzer-Profile anzeigen
Dieses Programm stellt ein Dreieck dar, welches man verändert. Es werden viele Werte berechnet. Seht es euch doch selber an:
BlitzBasic: [AUSKLAPPEN]
Graphics 640,480
SetBuffer BackBuffer()
HidePointer()
AppTitle \"Dreieck-Simulation\"

Global aX# = 100
Global aY# = 100
Global bX# = 300
Global bY# = 200
Global cX# = 80
Global cY# = 100
Global x = 320
Global y = 240
Global a#
Global b#
Global c#
Global alpha# ;Cosinus-Wert
Global beta# ;Cosinus-Wert
Global gamma# ;Cosinus-Wert
Global AF# ;Fläche
Global hC# ;Höhe auf C

Repeat
Cls

;Grafik zeichnen
Line aX#,aY#,bX#,bY#
Line bX#,bY#,cX#,cY#
Line cX#,cY#,aX#,aY#

;Punkte bezeichnen
Text bX#+15,bY#-10, \"B\"
Text aX#+15,aY#-10, \"A\"
Text cX#+15,cY#-10, \"C\"

;Seitenlängen berechnen
a# = GetSideA()
b# = GetSideB()
c# = GetSideC()

;Seiten beschriften
DrawInfoSites()

;Mausposition Feststellen und Klicks verwerten
DoMouse()

;Informationen Zeichnen
DrawInfo()

;Winkel-Info's zeichnen
DrawInfoAngle()

;Flächeninhalt anzeigen
DrawInfoFlaeche()

;Button zeichnen
DrawButtons()


Flip
Color 255,255,255
Until KeyDown(1)

End

Function DoMouse()

;Maus erneuern
x = MouseX()
y = MouseY()

;Maus zeichnen
Rect x,y,10,10

If RectsOverlap(x,y,5,5,aX#,aY#,5,5) Then
Oval aX#-5,ay#-5,10,10,0
Color 0,0,255
Text aX#+15,aY#-10, \"A\"
If MouseDown(1) Then
Oval aX#-5,aY#-5,10,10
PressA = 1
EndIf
EndIf

If PressA = 1 Then
aX# = MouseX()
aY# = MouseY()
If MouseDown(1) = 0 Then
PressA = 0
EndIf
EndIf

If RectsOverlap(x,y,5,5,bX#,bY,5,5) Then
Oval bX#-5,by#-5,10,10,0
Color 0,0,255
Text bX#+15,bY#-10, \"B\"
If MouseDown(1) Then
Oval bX#-5,bY#-5,10,10
PressB = 1
EndIf
EndIf

If PressB = 1 Then
bX# = MouseX()
bY# = MouseY()
If MouseDown(1) = 0 Then
PressB = 0
EndIf
EndIf

If RectsOverlap(x,y,5,5,cX#,cY,5,5) Then
Oval cX#-5,cy#-5,10,10,0
Color 0,0,255
Text cX#+15,cY#-10, \"C\"
If MouseDown(1) Then
Oval cX#-5,cY#-5,10,10
PressC = 1
EndIf
EndIf

If PressC = 1 Then
cX# = MouseX()
cY# = MouseY()
If MouseDown(1) = 0 Then
PressC = 0
EndIf
EndIf
Color 255,255,255
End Function


Function DrawInfo()

Text 125,400, \"A(\"+(aX#)+\"|\"+(aY#)+\")\"
Text 125,412, \"B(\"+(bX#)+\"|\"+(bY#)+\")\"
Text 125,424, \"C(\"+(cX#)+\"|\"+(cY#)+\")\"

Text 1,400, \"a=\"+(a#*0.353)+\"mm\"
Text 1,412, \"b=\"+(b#*0.353)+\"mm\"
Text 1,424, \"c=\"+(c#*0.353)+\"mm\"

End Function




Function GetSideA()

SideA = cX# - bX#
If SideA < 0 Then
SideA = SideA*-1
EndIf

SideB = cY#-bY#
If SideB < 0 Then
SideB = SideB*-1
EndIf

Return Sqr((SideA^2) + (SideB^2) )

End Function





Function GetSideB()

SideA = cX# - aX#
If SideA < 0 Then
SideA = SideA*-1
EndIf

SideB = cY#-aY#
If SideB < 0 Then
SideB = SideB*-1
EndIf

Return Sqr((SideA^2) + (SideB^2) )

End Function





Function GetSideC()

SideA = aX# - bX#
If SideA < 0 Then
SideA = SideA*-1
EndIf

SideB = aY#-bY#
If SideB < 0 Then
SideB = SideB*-1
EndIf

Return Sqr((SideA^2) + (SideB^2) )

End Function


Function DrawInfoSites()

;a
xLine = (cx#+bx#)/2
yLine = (cy#+by#)/2
Text xLine,yLine, \"a\"
;b
xLine = (cx#+ax#)/2
yLine = (cy#+ay#)/2
Text xLine,yLine, \"b\"
;c
xLine = (ax#+bx#)/2
yLine = (ay#+by#)/2
Text xLine,yLine, \"c\"

End Function

Function DrawInfoAngle()

alpha# = (((b^2)+(c^2)-(a^2))/(2*b*c))

Text 1,436, \"Alpha=\"+ACos(alpha#)+\"°\"

beta# = (((c^2)+(a^2)-(b^2))/(2*c*a))

Text 1,448, \"Beta=\"+ACos(beta#)+\"°\"

gamma# = (((a^2)+(b^2)-(c^2))/(2*b*a))

Text 1,460, \"Gamma=\"+ACos(gamma#)+\"°\"

End Function





Function DrawInfoFlaeche()

hC# = b#*Sin(ACos(alpha#))
AF#=(hC#*c)/2
Text 400,400, \"Fläche=\"+AF#+\"mm²\"

End Function




Function SetRight()

aX# = 100
bX# = 100
cX# = 300

aY# = 100
bY# = 300
cY# = 300

End Function


Function SetDouble()

aX# = 100
bX# = 300
cX# = 200

aY# = 300
bY# = 300
cY# = 100

End Function


Function SetGleich()
aX# = 100
bX# = 300
cX# = 200

aY# = 300
bY# = 300
cY# = 127
End Function


Function DrawButtons()

Rect 400,20,200,20,0
Text 402,22, \"Rechtwinkeliges Dreieck\"
If RectsOverlap(x,y,1,1,400,20,200,20) Then
Color 0,0,255
Rect 400,20,200,20,0
If MouseDown(1) Then
Color 0,255,0
Rect 400,20,200,20,0
SetRight()
EndIf
EndIf
Color 255,255,255
Rect 400,50,220,20,0
Text 402,52, \"Gleichschenkeliges Dreieck\"
If RectsOverlap(x,y,1,1,400,50,220,20) Then
Color 0,0,255
Rect 400,50,220,20,0
If MouseDown(1) Then
Color 0,255,0
Rect 400,50,220,20,0
SetDouble()
EndIf
EndIf
Color 255,255,255
Rect 400,100,200,20,0
Text 402,100, \"Gleichseitiges Dreieck\"
If RectsOverlap(x,y,1,1,400,100,200,20) Then
Color 0,0,255
Rect 400,100,200,20,0
If MouseDown(1) Then
Color 0,255,0
Rect 400,100,200,20,0
SetGleich()
EndIf
EndIf


End Function


Arrow Erweiterungen kommen noch!
***************
Blitzmaster
  • Zuletzt bearbeitet von blitzmaster am Mo, Mai 16, 2005 18:27, insgesamt einmal bearbeitet
 

Schnuff

BeitragMo, Mai 16, 2005 17:51
Antworten mit Zitat
Benutzer-Profile anzeigen
also entweder du baust
BlitzBasic: [AUSKLAPPEN]
HidePointer

ein
oder du nimst das Quadrat unter der Maus raus Smile
 

CodeMaster

BeitragMo, Mai 16, 2005 18:18
Antworten mit Zitat
Benutzer-Profile anzeigen
Das Ziehen mit der Maus ist noch verbesserungsbedürftig...
Dies ist ein Text, der an jeden Beitrag von dir angehängt werden kann. Es besteht eine Limit von 500 Buchstaben.

Zuletzt bearbeitet von CodeMaster am Mo Apr 01, Parse error: syntax error, unexpected ';' in htdocs\viewtopic.php on line 102

Neue Antwort erstellen


Übersicht BlitzBasic Codearchiv

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group