Page 1 of 1
How to draw a star by using sin() cos() ?
Posted: Wed Sep 21, 2005 11:08 pm
by Ralf
how to draw a star with sin() or cos() like in old demos end of the 90th?
the stars are available in the RSI demomaker package and looks something like this (bad example):
often seen with 8 lines (like an + and an x joined)
Code: Select all
#
#
#
######
############
##########################
############
######
#
#
#
Posted: Thu Sep 22, 2005 8:53 am
by Psychophanta
viewtopic.php?t=13037
Here is a working demo of that function:
Code: Select all
;Cogged function:
; Author: Psychophanta
; Date: 5 Nov 2004
;-INITS:
bitplanes.b=32:RX.w=1024:RY.w=768:#PI=3.14159265
If InitMouse()=0 Or InitSprite()=0 Or InitKeyboard()=0
MessageRequester("Error","Can't access DirectX",0)
End
EndIf
While OpenScreen(RX.w,RY.w,bitplanes.b,"")=0
If bitplanes.b>16:bitplanes.b-8
ElseIf RY.w>600:RX.w=800:RY.w=600
ElseIf RY.w>480:RX.w=640:RY.w=480
ElseIf RY.w>400:RX.w=640:RY.w=400
ElseIf RY.w>240:RX.w=320:RY.w=240
ElseIf RY.w>200:RX.w=320:RY.w=200
Else:MessageRequester("VGA","Can't open Screen!",0):End
EndIf
Wend
Procedure Star(x.l,y.l,intrad.l,extrad.l,n.l,inclination.l,phase.f,color.l)
alpha.f=2*#PI/n
i.f=inclination/20-1/2
For t.l=1 To n:d1.f=(t-1)*alpha+phase:d2.f=t*alpha+phase:d3.f=(t+i)*alpha+phase
LineXY(x+intrad*Cos(d1),y+intrad*Sin(d1),x+extrad*Cos(d3),y+extrad*Sin(d3),color)
LineXY(x+intrad*Cos(d2),y+intrad*Sin(d2),x+extrad*Cos(d3),y+extrad*Sin(d3),color)
Next
EndProcedure
r1.l=70:r2.l=90:p.l=3
;-MAIN:
MouseLocate(333,333)
Repeat
ClearScreen(0,0,0)
ExamineKeyboard()
ExamineMouse():mx.l=MouseX():my.l=MouseY()
StartDrawing(ScreenOutput())
Star(RX/2,RY/2,r1.l,r2.l,p,0,pha.f,$aaaaaa)
pha+MouseDeltaX()*0.01:r2-MouseDeltaY()
If MouseButton(1):While MouseButton(1):Delay(16):ExamineMouse():Wend
p+1:If p>80:p=80:EndIf
EndIf
If MouseButton(2):While MouseButton(2):Delay(16):ExamineMouse():Wend
p-1:If p<2:p=2:EndIf
EndIf
StopDrawing()
FlipBuffers():Delay(16)
Until KeyboardPushed(#PB_Key_Escape)
You can test changing inclination parameter, etc.
Posted: Fri Sep 23, 2005 8:11 pm
by Ralf
i need a routine that plot a star like the one on this screenshot
http://strider.mjjprod.free.fr/dck/ryuse1.gif (without the long line)
version 1) looks like " + "
version 2) looks like " + " and " x " merged

:roll:
Posted: Sat Sep 24, 2005 3:56 pm
by va!n
@Ralf:
maybe you can find such an algo/routine using google and search for any old skool related coding stuff

maybe someone here knows how to do such old coding stuff!?

Posted: Sat Sep 24, 2005 4:52 pm
by Psychophanta
Ralf:
I gave you a versatile function to draw a star: at
viewtopic.php?t=13037
Use a little bit your imagination.
This is a fast example:
Code: Select all
;-INITS:
bitplanes.b=32:RX.w=1024:RY.w=768:#PI=3.14159265
If InitMouse()=0 Or InitSprite()=0 Or InitKeyboard()=0
MessageRequester("Error","Can't access DirectX",0)
End
EndIf
While OpenScreen(RX.w,RY.w,bitplanes.b,"")=0
If bitplanes.b>16:bitplanes.b-8
ElseIf RY.w>600:RX.w=800:RY.w=600
ElseIf RY.w>480:RX.w=640:RY.w=480
ElseIf RY.w>400:RX.w=640:RY.w=400
ElseIf RY.w>240:RX.w=320:RY.w=240
ElseIf RY.w>200:RX.w=320:RY.w=200
Else:MessageRequester("VGA","Can't open Screen!",0):End
EndIf
Wend
Procedure Star(x.l,y.l,intrad.l,extrad.l,n.l,inclination.l,phase.f,color.l)
alpha.f=2*#PI/n
i.f=inclination/20-1/2
For t.l=1 To n:d1.f=(t-1)*alpha+phase:d2.f=t*alpha+phase:d3.f=(t+i)*alpha+phase
LineXY(x+intrad*Cos(d1),y+intrad*Sin(d1),x+extrad*Cos(d3),y+extrad*Sin(d3),color)
LineXY(x+intrad*Cos(d2),y+intrad*Sin(d2),x+extrad*Cos(d3),y+extrad*Sin(d3),color)
Next
EndProcedure
;-MAIN:
MouseLocate(333,333)
ClearScreen(0,0,0)
StartDrawing(ScreenOutput())
r1.f=0
For t.l=50 To 1 Step -1
r1.f+0.3:r2.f=r1.f*5
Star(RX/2,RY/2,r1.f,r2.f,8,0,#PI/8,t*$050403)
Next
StopDrawing()
FlipBuffers(0)
Repeat:ExamineKeyboard():Delay(16)
Until KeyboardPushed(#PB_Key_Escape)
Posted: Sat Sep 24, 2005 7:50 pm
by dobro
super!!
it's a pity that the triangle is not aligned on the square!!
to direct in degree rotation?
but :
currently the superposition of a triangle and a cross-section shows:
whereas it am cool to have:
to direct in degree rotation?
Thank you
Posted: Sun Sep 25, 2005 7:54 pm
by dobro
multi-polygone whit the rotation in Degres
Code: Select all
#dobro=1
#Police=1
#Sprite=1
#PI=3.1415926
Declare polygone(x.l,y.l,taille.l,angle.l,rotation.f,color.l,t)
; ***********************************
Resultat = InitSprite()
FontID = LoadFont(#Police, "arial", 18, #PB_Font_Bold )
EcranX = GetSystemMetrics_(#SM_CXSCREEN):;=largeur de l'ecran
EcranY = GetSystemMetrics_(#SM_CYSCREEN):;=hauteur de l'ecran
WindowID = OpenWindow(1, 0, 0, EcranX, EcranY, #PB_Window_SystemMenu|#PB_Window_BorderLess |#PB_Window_ScreenCentered , "hello")
WindowID = WindowID(1)
Result = OpenWindowedScreen(WindowID,0,0,800, 600, 1, 0,0)
Resultat = InitMouse()
Repeat
ExamineMouse()
Event=WindowEvent()
If MouseButton(2)
End
EndIf
;Star(x.l,y.l,intrad.l,n.l,phase.f,color.l)
x.l=400 ;location x
y.l=300 ; location y
taille.l=100
angle.l=4 ; pour un triangle 4 pour un carre , 8 pour un octogone ect ...
rotation.f=180
color.l=RGB($FF,$FF,$80)
For t=0 To 360
; Delay (200)
rotation.f=t
polygone(x.l,y.l,taille.l,angle.l,rotation.f,color.l,t)
FlipBuffers():; affiche l'ecran
ClearScreen(0,0,0)
ExamineMouse()
Event=WindowEvent()
If MouseButton(2)
End
EndIf
Next t
Until Event=#PB_Event_CloseWindow
Procedure polygone(x.l,y.l,taille.l,angle.l,rotation.f,color.l,t)
If angle.l=4
Else
EndIf
rotation.f= rotation.f*0.01745329
StartDrawing(ScreenOutput() )
DrawText(StrF( t))
alpha.f=2*(#PI/angle)
For t.l=1 To angle
d1.f=(t-1)*alpha+rotation.f
d3.f=t*alpha+rotation.f
LineXY(x+taille*Sin(d1),y+taille*Cos(d1),x+taille*Sin(d3),y+taille*Cos(d3),color)
Next
StopDrawing()
EndProcedure