Author Topic: I've asked this before... but...  (Read 2117 times)

johnno56

  • Guest
Re: I've asked this before... but...
« Reply #15 on: April 20, 2015 »
Peter,

Cool. also VERY fast. Am I correct in assuming that _drawcircle is another way of writing proc drawcircle ?

Many thanks.

J

Peter

  • Guest
Re: I've asked this before... but...
« Reply #16 on: April 20, 2015 »
Quote
_drawcircle is another way of writing proc drawcircle ?
accurate!

here*s another learn-object.
Code: [Select]
set window 16,16,640,480
set redraw off
radians

x1#=200.0; y1#=200.0; a#

while keydown(27)=0
set color 0,0,0
cls

for j=2 to 100
    i# = float(j)
    x2# = x1 + cos(i+a)*i*10.0
    y2# = y1 + sin(i+a)*i*10.0
    set color 200, 255, 200
    draw rect 80+int(x2),int(y2),j,j
next

a = a+1.0
rem another fine thing is: a = a+0.01
if a >=360.0 then a = -a

redraw
wait 10
wend
 

B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: I've asked this before... but...
« Reply #17 on: April 20, 2015 »
Hi Peter,

Yep! My circle procedure very slow! Decided to have a cup of coffee while computer was drawing my red circles (which I now have under my eyes for staying up so late). Out of coffee, so I planted some bean trees, grew them, manufactured the coffee, ground it, brewed it, ...ah coffee! and the red circle program was still drawing!

B+

« Last Edit: April 20, 2015 by B+ »
B+

B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: I've asked this before... but...
« Reply #18 on: April 20, 2015 »
WOW!

set redraw off
....draw the stuff then
redraw

what a difference in time!

For the Red Circles program, I didn't have time to take a single sip of coffee before the thing pops up whole on the screen!

I am looking over the circle drawing algorithm's and see the whole program draws the circle not just the circle procedure.

I also notice this:
Code: [Select]
procedure drawcircle(xc#,yc#,x#,y#)
draw pixel int(xc + x), int(yc + y)
draw pixel int(xc - x), int(yc + y)
draw pixel int(xc + x), int(yc - y)
draw pixel int(xc - x), int(yc - y)
draw pixel int(xc + y), int(yc + x)
draw pixel int(xc - y), int(yc + x)
draw pixel int(xc + y), int(yc - x)
draw pixel int(xc - y), int(yc - x)
endproc
How come you don't need to write  xc#,yc#, x#,y# in the procedure?
Ah, also in Peter's "another learn-object" the a# defined at top and then used with just a ???

***   "Foolish consistency is the hobgoblin of little minds?"  ***

J, is this what you were getting at, about knowing when to use integer and when a float?

I will guess and then test this idea, once you "define" a float, you don't have to use the # to remind the compiler, so therefore a$ and a# and a can't coexist in same program?

B+
B+

aurel

  • Jr. Member
  • **
  • Posts: 61
    • View Profile
Re: I've asked this before... but...
« Reply #19 on: April 20, 2015 »
Quote
so therefore a$ and a# and a can't coexist in same program
heh..it looks that you have serious problem with def var
and who and where use same name for different variable type ?
 ::)

B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: I've asked this before... but...
« Reply #20 on: April 20, 2015 »
Quote
so therefore a$ and a# and a can't coexist in same program
heh..it looks that you have serious problem with def var
and who and where use same name for different variable type ?
 ::)

x and y all the time, to make integer or to make float?

that is the question.

B+
B+

johnno56

  • Guest
Re: I've asked this before... but...
« Reply #21 on: April 20, 2015 »
B+,

Quote
J, is this what you were getting at, about knowing when to use integer and when a float?

Yep. I get soooo confused at times, my brain turns to mush... *sigh*

Interesting point about defining a# and a$. I had not considered that before.

J

Peter

  • Guest
Re: I've asked this before... but...
« Reply #22 on: April 21, 2015 »
float exercise no. 2:
Code: [Select]
set window 32,32,640,480
set redraw off
radians

a#

while keydown(27)=0
set color 0,0,0
cls

set color 255,255,255
_DrawCube 300.0, 100.0, 80.0, a
_DrawCube 300.0, 300.0, 90.0,-a

set color 255,200,0
_DrawCube  20.0,  20.0, 20.0, a
_DrawCube 600.0, 460.0, 20.0,-a

a = a+0.1
if a>=360.0 then a=-a
redraw
wait 80
wend

procedure DrawCube(x#, y#, s#, a#)
x1# = x
y1# = y
x2# = x1+cos(a)*s
y2# = y1+sin(a)*s
x3# = x2+cos(a+90.0)*s
y3# = y2+sin(a+90.0)*s
x4# = x1+cos(a+90.0)*s
y4# = y1+sin(a+90.0)*s

draw line int(x1), int(y1), int(x2), int(y2)
draw line int(x2), int(y2), int(x3), int(y3)
draw line int(x3), int(y3), int(x4), int(y4)
draw line int(x4), int(y4), int(x1), int(y1)

draw line int(x1+s), int(y1), int(x2+s), int(y2)
draw line int(x2+s), int(y2), int(x3+s), int(y3)
draw line int(x3+s), int(y3), int(x4+s), int(y4)
draw line int(x4+s), int(y4), int(x1+s), int(y1)

draw line int(x1), int(y1), int(x1+s), int(y1)
draw line int(x2), int(y2), int(x2+s), int(y2)
draw line int(x3), int(y3), int(x3+s), int(y3)
draw line int(x4), int(y4), int(x4+s), int(y4)
endproc

B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: I've asked this before... but...
« Reply #23 on: April 21, 2015 »
WOW!

set redraw off
....draw the stuff then
redraw

what a difference in time!

For the Red Circles program, I didn't have time to take a single sip of coffee before the thing pops up whole on the screen!

I am looking over the circle drawing algorithm's and see the whole program draws the circle not just the circle procedure.

I also notice this:
Code: [Select]
procedure drawcircle(xc#,yc#,x#,y#)
draw pixel int(xc + x), int(yc + y)
draw pixel int(xc - x), int(yc + y)
draw pixel int(xc + x), int(yc - y)
draw pixel int(xc - x), int(yc - y)
draw pixel int(xc + y), int(yc + x)
draw pixel int(xc - y), int(yc + x)
draw pixel int(xc + y), int(yc - x)
draw pixel int(xc - y), int(yc - x)
endproc
How come you don't need to write  xc#,yc#, x#,y# in the procedure?
Ah, also in Peter's "another learn-object" the a# defined at top and then used with just a ???

***   "Foolish consistency is the hobgoblin of little minds?"  ***

J, is this what you were getting at, about knowing when to use integer and when a float?

I will guess and then test this idea, once you "define" a float, you don't have to use the # to remind the compiler, so therefore a$ and a# and a can't coexist in same program?

B+

OK I did some tests here is a cool result!
Code: [Select]
rem Circle test v1 revised 2015-04-21 B+
rem here we test idea that you only have to tell the compiler once your variable is a float
rem modified circle procedure so color can be set by caller program of circle procedure
rem so more color this time around testing a general circle proc also .1 better! refinement
sq=520
set window 0,0,sq,sq
set redraw off
rem origin
x0 = int(sq/2)
y0 = int(sq/2)
for i=0 to 255
set color 255-i,255-i,255-i
_circle x0,y0,i
next
redraw
wait keydown
end
procedure circle(x,y,r)
i#=0.0
do
xpos = int(sin(i) * float(r))
ypos = int(cos(i) * float(r))
draw pixel xpos+x,ypos+y
i = i + 0.1
until i >= 360.0
endproc
B+

Peter

  • Guest
Re: I've asked this before... but...
« Reply #24 on: April 21, 2015 »
great   B+,
you jumped over your shaddow.
Code: [Select]
rem Peter was here.
set window 0,0,520,520
set redraw off

sq = 520
x0 = sq/2
y0 = sq/2

for i=0 to 255
     set color (255-i)*int(0.5),255-i,255-i
   _circle x0,y0,i
   _circle x0-i,y0+i,i
   _circle x0-i,y0-i,i
   _circle x0+i,y0+i,i
   _circle x0+i,y0-i,i
next

redraw
wait keydown
end

procedure circle(x,y,r)
i#
do
xpos = int(sin(i) * float(r))
ypos = int(cos(i) * float(r))
draw pixel xpos+x,ypos+y
i = i + 0.1
until i >= 360.0
endproc


johnno56

  • Guest
Re: I've asked this before... but...
« Reply #25 on: April 21, 2015 »
Very nice examples, indeed. Well done. :)

J

B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Re: I've asked this before... but...
« Reply #26 on: April 22, 2015 »
Yes Johnno, they look # but are you any clearer on float?

My theory is once you tell the compiler: i#
all future references to i are assumed float by it.

i# (first time), therefore i am float,

B+
B+

johnno56

  • Guest
Re: I've asked this before... but...
« Reply #27 on: April 22, 2015 »
B+,

Yes. Much clearer, thanks.

J

B+

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Floats!
« Reply #28 on: May 12, 2015 »
That was only half the story with floats and integers!

The other half is that your literal numbers also have to be 0.xxxx or xxx.0 for floats!
Code: [Select]
x#=1.11
rem a#=x#+1
rem = error? yep

b#=x#+1.0
rem = OK? yep

rem c#=x#+.01
rem = error? yep

d#=x#+0.01
rem = OK? yep

Good golly Miss Molly, no wonder one's brain turns to mush!

that and coffee (which floats my bloat),

B+
« Last Edit: May 12, 2015 by B+ »
B+

johnno56

  • Guest
Re: I've asked this before... but...
« Reply #29 on: May 12, 2015 »
Thanks for the info B+.  I am slowly figuring out the float thingy.  I have particular difficulty when both float and integer are combined in a calculation.  I apologise for not being as quick as others, when it comes to floating point, I have not had to deal with them in the past.  *sigh*

J