Circle Timer

New to FreeBASIC? Post your questions here.
TurtleProgrammer
Posts: 37
Joined: Jan 26, 2017 7:54

Circle Timer

Postby TurtleProgrammer » Apr 16, 2017 22:39

When I run the attached code I get black artifacts and such and what is supposed to be a circle doesn't look like one. I only uploaded part of the code to reduce the size of the message. I used a long, probably not the best code, for this because at different stages I want the circle code to stop and execute other code.

Code: Select all

screenres 1500, 1500
line (750, 750)-(750, 725), 15
sleep 1000
line (750, 751)-(751, 727), 15
sleep 1000
line (750, 752)-(752, 729), 15
sleep 1000
line (750, 753)-(753, 731), 15
sleep 1000
line (750, 754)-(754, 733), 15
sleep 1000
line (750, 755)-(755, 735), 15
sleep 1000
line (750, 756)-(756, 737), 15
sleep 1000
line (750, 757)-(757, 739), 15
sleep 1000
line (750, 758)-(758, 741), 15
sleep 1000
line (750, 759)-(759, 743), 15
sleep 1000
line (750, 760)-(760, 745), 15
sleep 1000
line (750, 761)-(761, 747), 15
sleep 1000
fxm
Posts: 9477
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Circle Timer

Postby fxm » Apr 17, 2017 4:57

Please explain why, in your mind, this should plot a circle.
leopardpm
Posts: 1795
Joined: Feb 28, 2009 20:58

Re: Circle Timer

Postby leopardpm » Apr 17, 2017 7:31

fxm wrote:Please explain why, in your mind, this should plot a circle.

LMAO - are you sure you want that explanation?!

reviewing code now...

Turtle - it is doing exactly what you are telling it to do... and that is not making anything 'circular'... try hand plotting your coordinates... they ain't correct for any known type if circularish shaped object...
fxm
Posts: 9477
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Circle Timer

Postby fxm » Apr 17, 2017 8:03

By using the instruction CIRCLE:
Circle [target,] [STEP] (x,y), radius[, [color][, [start][, [end][, [aspect][, F]]]]]
You can even plot a circle by small angular sectors (using 'start' and 'end' with successive values) and execute other code between each plotted angular sector.
dodicat
Posts: 6163
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Circle Timer

Postby dodicat » Apr 17, 2017 8:08

If you draw lines with a slope then not all pixels will get filled.

Code: Select all



screen 19

dim as long k=40 'slope


for n as long=100 to 600
    line(100,n)-(n,n-k)
    sleep 10
next
sleep
fxm
Posts: 9477
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Circle Timer

Postby fxm » Apr 17, 2017 9:22

Plotting by angular sector:

- For a circle (simplest):

Code: Select all

Const As Single Pi = 4 * Atn(1)

Dim As Double x=400, y=300, r=100, c = 15

Screen 19

Circle (x, y), r, c, 0, Pi/4
Sleep 1000
Circle (x, y), r, c, Pi/4, Pi/2
Sleep 1000
Circle (x, y), r, c, Pi/2, 3*Pi/4
Sleep 1000
Circle (x, y), r, c, 3*Pi/4, Pi
Sleep 1000
Circle (x, y), r, c, Pi, 5*Pi/4
Sleep 1000
Circle (x, y), r, c, 5*Pi/4, 3*Pi/2
Sleep 1000
Circle (x, y), r, c, 3*Pi/2, 7*Pi/4
Sleep 1000
Circle (x, y), r, c, 7*Pi/4, 2*Pi
Sleep 1000

Sleep

- For a disk (more complex):

Code: Select all

Const As Single Pi = 4 * Atn(1)

#Macro angularSector(x, y, r, c, start, end)
  Line (x, y)-(x+r*Cos(start), y-r*Sin(start)), c
  Circle (x, y), r, c, start, end
  Line (x, y)-(x+r*Cos(end), y-r*Sin(end)), c
  Paint (x+r/2*Cos((start+end)/2), y-r/2*Sin((start+end)/2)), c
#Endmacro

Dim As Double x=400, y=300, r=100, c = 15

Screen 19

angularSector(x, y, r, c, 0, Pi/4)
Sleep 1000
angularSector(x, y, r, c, Pi/4, Pi/2)
Sleep 1000
angularSector(x, y, r, c, Pi/2, 3*Pi/4)
Sleep 1000
angularSector(x, y, r, c, 3*Pi/4, Pi)
Sleep 1000
angularSector(x, y, r, c, Pi, 5*Pi/4)
Sleep 1000
angularSector(x, y, r, c, 5*Pi/4, 3*Pi/2)
Sleep 1000
angularSector(x, y, r, c, 3*PI/2, 7*Pi/4)
Sleep 1000
angularSector(x, y, r, c, 7*Pi/4, 2*Pi)
Sleep 1000

Sleep
thesanman112
Posts: 538
Joined: Jul 15, 2005 4:13

Re: Circle Timer

Postby thesanman112 » Apr 17, 2017 22:37

Do you mean video artifacts like dots or chips elsewhere??? That is because of pr9gram initilisation methods....like call screen 1....or when initilising a screen or display value.....

Is that what you mean????
dodicat
Posts: 6163
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: Circle Timer

Postby dodicat » Apr 17, 2017 23:18

Lines are drawn using the available screen pixels.
These, of course, are like grid points, so a stepping pattern is used.
The patterns just don't match well enough at different slopes, so holes appear.

Put the mouse cursor at a point and rotate the wheel to magnify an area.
Press down on the mouse wheel to reset,

Code: Select all


screen 19
Sub Magnify()
    #define resetwheel(w,fl) fl=w
    #define wheel(w,f) w-f
    Dim As Integer mx,my,mw,button:Getmouse mx,my,mw,button
    Static As Integer flag,pmw
    mw=(mw/2)
   If button=4 Then  resetwheel(mw,flag)
    Dim As Uinteger array(1 To 6561),count
    pmw=wheel(mw,flag)
    if pmw<=1 then exit sub
    For z As Integer=1 To 2
        For x As Integer=mx-40 To mx+40
            For y As Integer=my-40 To my+40
                count+=1
                If z=1 Then array(count)=Point(x,y)
                If z=2 Then
                    var NewX=pmw*(x-mx)+mx:var NewY=pmw*(y-my)+my
                    line(newx-pmw/2,newy-pmw/2)-(newx+pmw/2,newy+pmw/2),array(count),bf
                End If
            Next y
        Next x
        count=0
    Next z
    Line(mx-pmw*40,my-pmw*40)-(mx+pmw*40,my+pmw*40),5,B
End Sub


dim as long k=40 'slope

do
    screenlock
    cls
for n as long=100 to 600
    line(100,n)-(n,n-k)
next
line(600,100)-(700,400)
line(600,100)-(710,400)

magnify
screenunlock
sleep 1,1
loop until len(inkey)
sleep

Return to “Beginners”

Who is online

Users browsing this forum: No registered users and 1 guest