' 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 " 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________________________________