Guidance
指路人
g.yi.org
software / rapidq / Examples / Graphics & Animation / fungen / ellipse.bas

Register 
新用户注册
Search 搜索
首页 
Home Home
Software
Upload

  

'                    Computer generated Ellipses

' The program generates two ellipses in a bitmap field of 400 x 400
' pixels using polar co-ordinates centered at the (200,200). For each
' angle, move to that point on the 1st ecllipse and draw to that angles
' point on the 2nd ellipse's curve. Each ellipse's width and height can
' be changed. The connecting point on the 2nd curve can be skewed with
' respect to the 1st curve by a selected number of degrees. The angular
' destance between points on the curve can be selected and finally the
' entire second ellipse can be co-ordinate rotated in respect to its
' original in phase position. Additionally, any bitmap worth saving can
' be downloaded into the windows/desktop directory as a bump#.bmp file.
'
' The program is interrupt driven with two subs, one to update the
' Qcanvas on each Qbitmap paint. The second services a mouse interrupt
' to update the Qbitmap and display the pattern to the Qcanvas.
' The variable assignments are done with keyboard inputs to the
' Qedit object.

' Diming the objects vice Creating them and the prolific use of DIMing
' the variables seems best for me now. I will surely develope different
' codeing methods with practice. Any valid inputs will be appreciated.
'                                            Written by Ruth and old bob.
'
'_______________________Start______________________
     $INCLUDE "rapidq.inc"
     $TYPECHECK ON

'_____________________declare variables____________

'  values provided in program
     DIM N$     AS STRING   ' scratch string
     DIM n      AS SINGLE   ' scratch numeric
     DIM Fname$ AS STRING   ' SAVE filename
     DIM x1     AS SINGLE   ' bitmap pset arguments
     DIM y1     AS SINGLE
     DIM x2     AS SINGLE   ' working co-ordinate
     DIM y2     AS SINGLE
     DIM x3     AS SINGLE   ' bitmap line argument
     DIM y3     AS SINGLE
     DIM angle  AS SINGLE   ' for/next loop angle
     DIM theta  AS SINGLE   ' angle plus skew


'  Initially needed values for compiling
     DIM s1  AS SINGLE         ' for/next step value
     s1  =  1
     DIM skew   AS SINGLE      ' point shift angle
     skew = 0
     DIM tilt   AS SINGLE      ' phase shift angle
     tilt = 0
     DIM Rad AS SINGLE         ' degrees per radians
     Rad =  3.1415927/180
     DIM w1  AS SINGLE         ' width and heights
     w1  =  100            ' ellipse1 width
     DIM h1  AS SINGLE
     h1  =  200            ' ellipse1 height
     DIM w2  AS SINGLE
     w2  =  200            ' ellipse2 width
     DIM h2  AS SINGLE
     h2  =  100            ' ellipse2 height
     DIM FN  AS SINGLE         ' Bump suffix in filename
     FN  = 0               ' Begin with one

     DIM Hue     AS SINGLE     ' color of lines
     Hue     =  &H2FDCE0   ' Gold
     DIM BmpCol  AS SINGLE     ' bitmap color
     BmpCol  =  &H4D764B   ' Dark  Green
     DIM TextCol AS SINGLE     ' bitmap text color
     TextCol =  &H0000FF   ' Solid Red
     DIM FormCol AS SINGLE     ' Form Color
     FormCol =  &HC0C0C0   ' Haze  Gray
     DIM CanvCol AS SINGLE     ' Canvas color
     CanvCol = &H4D764B    ' Dark  Green


'_______________________declare Subs____________________________________
     DECLARE SUB paint
     DECLARE SUB ButtonClick (Sender AS QBUTTON)

'_____________________declare Objects___________________
     DIM font AS QFONT
     DIM bump AS QBITMAP
     DIM form AS QFORM
     DIM canvas AS QCANVAS

     DIM label1 AS QLABEL
     DIM label2 AS QLABEL
     DIM label3 AS QLABEL
     DIM label4 AS QLABEL
     DIM label5 AS QLABEL
     DIM label6 AS QLABEL
     DIM label7 AS QLABEL
     DIM label8 AS QLABEL
     DIM label9 AS QLABEL
     DIM labelA AS QLABEL

     DIM StartB AS QBUTTON
     DIM StopB AS QBUTTON
     DIM EndB AS QBUTTON

     DIM Input1 AS QEDIT
     DIM Input2 AS QEDIT
     DIM Input3 AS QEDIT
     DIM Input4 AS QEDIT
     DIM Input5 AS QEDIT
     DIM Input6 AS QEDIT
     DIM Input7 AS QEDIT

'_____________________Qualfy Objects_______________
'_______________________________Qbitmap____________
     bump.width  = 400
     bump.height = 400
     bump.fillrect(0,0,400,400,BmpCol)

'_______________________________Qform______________
     form.CAPTION = "Ellipse"
     form.clientheight = 500
     form.clientwidth = 600
     form.COLOR = FormCol
     form.center

'_______________________________Qcanvas____________
     canvas.PARENT = form
     canvas.width  = 400
     canvas.height = 400
     canvas.top = 50
     canvas.left = 50
     canvas.COLOR = CanvCol
     canvas.onpaint = paint   'Call paint sub when ever form.show


'_______________________________Qlabel_____________
     label1.PARENT = form
     label1.CAPTION = "          Computer Generated Graphics"
     label1.Top = 5
     label1.Left = 50
     label1.Width = 400
     label1.Height = 15
     label1.Transparent = 0
     label1.hint = "label 1 hint"

     label2.PARENT = form
     label2.CAPTION = "Provide the ellipses width, height, skew and resolution"
     label2.Top = 20
     label2.Left = 50
     label2.Width = 400
     label2.Height = 15
     label2.Transparent = 0

     label3.PARENT = form
     label3.CAPTION = "   ellipse one and two"
     label3.Top = 25
     label3.Left = 450
     label3.Width = 130
     label3.Height = 15
     label3.Transparent = 0

     label4.PARENT = form
     label4.CAPTION = "  __width____height__"
     label4.Top = 43
     label4.Left = 450
     label4.Width = 130
     label4.Height = 15
     label4.Transparent = 0

     label5.PARENT = form
     label5.CAPTION = "   _Skew__"
     label5.Top = 135
     label5.Left = 450
     label5.Width = 130
     label5.Height = 15
     label5.Transparent = 0

     label6.PARENT = form
     label6.CAPTION = "   Resolution"
     label6.Top = 165
     label6.Left = 450
     label6.Width = 130
     label6.Height = 15
     label6.Transparent = 0

     label7.PARENT = form
     label7.CAPTION = "   _Tilt____"
     label7.Top = 195
     label7.Left = 450
     label7.Width = 130
     label7.Height = 15
     label7.Transparent = 0

     label8.PARENT = form
     label8.CAPTION = "  draw new selections"
     label8.Top = 285
     label8.Left = 450
     label8.Width = 130
     label8.Height = 15
     label8.Transparent = 0

     label9.PARENT = form
     label9.CAPTION = "          save picture"
     label9.Top = 345
     label9.Left = 450
     label9.Width = 130
     label9.Height = 15
     label9.Transparent = 0

     labelA.PARENT = form
     labelA.CAPTION = "         exits program"
     labelA.Top = 405
     labelA.Left = 450
     labelA.Width = 130
     labelA.Height = 15
     labelA.Transparent = 0



'_______________________________Qedit_____________________
     input1.PARENT = form
     input1.Hint = "#1 width  -200 to +200 pixels"
     input1.Top = 60
     input1.Left = 460
     input1.Width = 50
     input1.ShowHint = 1
     input1.text = STR$(w1)   'ellipse1 width

     input2.PARENT = form
     input2.Hint = "#1 height  -200 to +200 pixels"
     input2.Top = 60
     input2.Left = 520
     input2.Width = 50
     input2.ShowHint = 1
     input2.text = STR$(h1)    'ellipse1 height

     input3.PARENT = form
     input3.Hint = "#2 width  -200 to +200 pixels"
     input3.Top = 90
     input3.Left = 460
     input3.Width = 50
     input3.ShowHint = 1
     input3.text = STR$(w2)   'ellipse2 width

     input4.PARENT = form
     input4.Hint = "#2 height  -200 to +200 pixels"
     input4.Top = 90
     input4.Left = 520
     input4.Width = 50
     input4.ShowHint = 1
     input4.text = STR$(h2)   'ellipse2 height

     input5.PARENT = form
     input5.Hint = "skew angle -180 to +180 degrees"
     input5.Top = 125
     input5.Left = 520
     input5.Width = 50
     input5.ShowHint = 1
     input5.text = STR$(skew)

     input6.PARENT = form
     input6.Hint = "1 or greater degrees"
     input6.Top = 155
     input6.Left = 520
     input6.Width = 50
     input6.ShowHint = 1
     input6.text = STR$(s1)  'resolution

     input7.PARENT = form
     input7.Hint = "within 0 to 360 degrees"
     input7.Top = 185
     input7.Left = 520
     input7.Width = 50
     input7.ShowHint = 1
     input7.text = STR$(tilt)  'tilt

'_______________________________Qbutton_____________________
     startB.PARENT = form
     startB.CAPTION = "Draw"
     startB.OnClick = ButtonClick      'sub buttonclick
     startB.Hint = "re-draws new settings"
     startB.ShowHint = 1
     startB.Left = 480
     startB.Top = 305

     stopb.PARENT = form
     stopB.CAPTION = "Save"
     stopB.OnClick = ButtonClick      'sub buttonclick
     stopB.Hint = "send bmp file to desktop"
     stopB.ShowHint = 1
     stopB.Left = 480
     stopB.Top = 365
     stopB.TabOrder = 1

     EndB.PARENT = form
     EndB.CAPTION = "Exit"
     EndB.OnClick = ButtonClick      'sub buttonclick
     EndB.Hint = "gracefully exits the program"
     EndB.ShowHint = 1
     EndB.Left = 480
     EndB.Top = 425



'___________Write text to Canvas via the bitmap____________
     N = 10

     N$= "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
     bump.textout (10,N,N$,TextCol,0): n=n+15

     N$= "The right margin contains Edit boxes and Event Buttons "
     bump.textout (10,N,N$,TextCol,0): n=n+15

     N$= " "
     bump.textout (10,N,N$,TextCol,0): n=n+15

     N$= "Edit Boxes  <or status boxes>"
     bump.textout (10,N,N$,TextCol,0): n=n+15

     N$= "The Edit boxes contain the current values for the Draw event "
     bump.textout (10,N,N$,TextCol,0): n=n+15

     N$= "..Change a value by placing the mouse over the value "
     bump.textout (10,N,N$,TextCol,0): n=n+15

     N$= "....A hint will show the value expected. Click it to select it "
     bump.textout (10,N,N$,TextCol,0): n=n+15

     N$= "....Use the keyboard number keys to select new value "
     bump.textout (10,N,N$,TextCol,0): n=n+15

     N$= " "
     bump.textout (10,N,N$,TextCol,0): n=n+15

     N$= "Event Buttons "
     bump.textout (10,N,N$,TextCol,0): n=n+15

     N$= "..A mouse click will execute the event "
     bump.textout (10,N,N$,TextCol,0): n=n+15

     N$= "....DRAW displays a picture for the selected values "
     bump.textout (10,N,N$,TextCol,0): n=n+15

     N$= "....SAVE creates a Bump.bmp file on the desktop "
     bump.textout (10,N,N$,TextCol,0): n=n+15

     N$= "....EXIT closes this program gracefully with elegant couth "
     bump.textout (10,N,N$,TextCol,0): n=n+15

     N$= " "
     bump.textout (10,N,N$,TextCol,0): n=n+15

     N$= "Points for two elipses are plotted  on a 400x400 pixel field "
     bump.textout (10,N,N$,TextCol,0): n=n+15

     N$= "From 0 to 360 degrees, the point for each ellipse is drawn in "
     bump.textout (10,N,N$,TextCol,0): n=n+15

     N$= "turn for each angle and a line drawn between each set of points "
     bump.textout (10,N,N$,TextCol,0): n=n+15

     N$= " "
     bump.textout (10,N,N$,TextCol,0): n=n+15

     N$= "To see this clearly, make the width and height the same for both "
     bump.textout (10,N,N$,TextCol,0): n=n+15

     N$= "ellipses. The line between them will be of zero length... "
     bump.textout (10,N,N$,TextCol,0): n=n+15

     N$= "..Skew: degrees shifted between each set of plots "
     bump.textout (10,N,N$,TextCol,0): n=n+15

     N$= "..Resolution: degrees between successive sets of plots "
     bump.textout (10,N,N$,TextCol,0): n=n+15

     N$= "..Tilt: degrees the second elipse is rotated "
     bump.textout (10,N,N$,TextCol,0): n=n+15



     N$= "______________________________________________________"
     bump.textout (10,N,N$,TextCol,0)



'__Show the Form and wait for a click on Draw, Save or Exit__

     form.SHOWMODAL   ' Display Window & wait for OnClick
                        ' Else fall thru & quit less gracefully
     SHOWMESSAGE("The program will close;however, less couthfully than with EXIT")
     END



'___________________Sub Routines__________________

     SUB paint
      canvas.draw(0,0,bump.bmp)
     END SUB


     SUB ButtonClick (Sender AS QBUTTON)

'__________Service the Qbuttons Draw, Save and Exit________
      SELECT CASE Sender.CAPTION
      CASE "Save"
       FN = FN + 1
       fname$ = "Bump" + STR$(FN) + ".bmp"
       bump.SaveToFile ("c:\windows\desktop\" + fname$)
      CASE "Exit"
       END
      END SELECT

'_____________Gather the QEdit buttons (users inputs)____________
      n$ = input1.text:  n = VAL(n$)
      IF n>-201 AND n<201 THEN w1=n:input1.text=STR$(w1) ELSE input1.text="error"

      n$ = input2.text:  n = VAL(n$)
      IF n>-201 AND n<201 THEN h1=n:input2.text=STR$(h1) ELSE input2.text="error"

      n$ = input3.text:  n = VAL(n$)
      IF n>-201 AND n<201 THEN w2=n:input3.text=STR$(w2) ELSE input3.text="error"

      n$ = input4.text:  n = VAL(n$)
      IF n>-201 AND n<201 THEN h2=n:input4.text=STR$(h2) ELSE input4.text="error"

      n$ = input5.text:  n = VAL(n$)
      IF ABS(n)> 180 THEN input5.text="error" ELSE skew= n: input5.text= STR$(skew)

      n$ = input6.text:  n = VAL(n$)
      IF n< 1 THEN input6.text= "error" ELSE s1=n: input6.text= STR$(s1)

      n$ = input7.text:  n = VAL(n$):   tilt=n: input7.text= STR$(tilt)


'_____________________Generate the pattern_______________________

      bump.fillrect(0,0,400,400,BmpCol) ' erase old picture
      FOR angle = 0 TO 360 STEP s1
       Theta = angle + skew

'            Calculate 1st point and move there

       x1 = COS(angle * rad) * w1
       y1 = SIN(angle * rad) * h1
       bump.pset(200 + x1, 200 - y1, hue)

'            Calculate 2nd point

       x2 = COS(theta * rad) * w2
       y2 = SIN(theta * rad) * h2

'            Rotate it through the tilt angle

       x3 = x2 * COS(tilt * rad) + y2 * SIN(tilt * rad)
       y3 = y2 * COS(tilt * rad) - x2 * SIN(tilt * rad)

'           Then draw to it
       bump.line(200 + x1, 200 + y1, 200 + x3, 200 + y3, hue)
      NEXT angle
      canvas.repaint

     END SUB

'_______________thaa thaa thats all folks______________________
'_________________________Kalos________________________________
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Sun 2019-7-21  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2005-04-16 12:24:29