programming a spiral in basic

The place for codemasters or beginners to talk about programming any language for the Spectrum.
Post Reply
User avatar
777
Manic Miner
Posts: 512
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

programming a spiral in basic

Post by 777 »

ive had a look on google, this forum and wos forum, etc and cant find anything on how to do this. i can do the basic part, i just need pointing in the right direction as to what equation, i should use. maths is not my strongest point. i would prefer if it was to be done purely with the plot command, so i can manipulate it later. any ideas would be appreciated.
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1
AndyC
Dynamite Dan
Posts: 1406
Joined: Mon Nov 13, 2017 5:12 am

Re: programming a spiral in basic

Post by AndyC »

I'd probably start by writing routing to plot a circle using SIN / COS, them modify it to increase (or decrease) the radius by a small fraction after each plot. That should create a spiralling effect.
User avatar
777
Manic Miner
Posts: 512
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

Re: programming a spiral in basic

Post by 777 »

AndyC wrote: Sun Sep 27, 2020 2:45 pm I'd probably start by writing routing to plot a circle using SIN / COS, them modify it to increase (or decrease) the radius by a small fraction after each plot. That should create a spiralling effect.
drawing circles the part i dont get

do you mean like this?

https://pasteboard.co/Jt1LGJn.png

https://gofile.io/d/lmu0gb

this is the best i can do

it works but it doesnt seem very manipulable
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1
+3code

Re: programming a spiral in basic

Post by +3code »

User avatar
p13z
Manic Miner
Posts: 611
Joined: Sun Feb 17, 2019 10:41 pm
Location: UK
Contact:

Re: programming a spiral in basic

Post by p13z »

Simplest way to start with something like this in Speccy BASIC, IMO would be:

Code: Select all

10 PLOT 125,85
20 FOR a=1 TO 90
30 DRAW a*COS a,a*SIN a
40 NEXT a
Then adjust to suit.
You're welcome :)

(I appreciate it isn't PLOTed - but PLOTed solutions could get quite a bit slower and more involved)
Last edited by p13z on Mon Sep 28, 2020 12:25 pm, edited 1 time in total.
User avatar
uglifruit
Manic Miner
Posts: 703
Joined: Thu Jan 17, 2019 12:41 pm
Location: Leicester
Contact:

Re: programming a spiral in basic

Post by uglifruit »

Using plots

Code: Select all

10 LET R=80					; INITIAL RADIUS
20 FOR A=0 TO 8*PI STEP 0.1			; 8*PI = 4 LOOPS, STEP 0.1 = HOW FREQUENT THE PIXELS ARE
30 PLOT 80-R*SIN A,80-R*COS A			; 80,80 = CENTRE OF SPIRAL
40 LET R=R-0.3					; DECREASE IN R EACH STEP
50 NEXT A	
Image
CLEAR 23855
User avatar
ZXDunny
Manic Miner
Posts: 498
Joined: Tue Nov 14, 2017 3:45 pm

Re: programming a spiral in basic

Post by ZXDunny »

p13z wrote: Mon Sep 28, 2020 12:02 pm Simplest way to start with something like this in Speccy BASIC, IMO would be:

Code: Select all

10 PLOT 125,85
20 FOR a=1 TO 90
30 DRAW a*COS a,a*SIN a
40 NEXT a
Then adjust to suit.
You're welcome :)

(I appreciate it isn't PLOTed - but PLOTed solutions could get quite a bit slower and more involved)
Dude.

Code: Select all

10 FOR d=.1 TO 3 STEP .001
20 PLOT 400,240
30 FOR a=1 TO 180 step 1/d
40 DRAW a/d*COS a,a/d*SIN a
50 NEXT a
60 WAIT SCREEN
70 CLS
80 NEXT d
SpecBAS, natch. Apologies for derailing.
User avatar
Joefish
Rick Dangerous
Posts: 2058
Joined: Tue Nov 14, 2017 10:26 am

Re: programming a spiral in basic

Post by Joefish »

Maths note - if you use SQR(A) for the angle where A is the subject of the FOR..NEXT loop and the growing radius is a multiple of A, then that compensates for the increasing radius/circumference and your dots end up evenly spaced, however large the spiral grows.

A shame then that SQR slows everything right down...
User avatar
777
Manic Miner
Posts: 512
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

Re: programming a spiral in basic

Post by 777 »

+3code wrote: Sun Sep 27, 2020 11:24 pm See
https://microhobby.speccy.cz/mhf/111/MH111_11.jpg
theres some really good magazine programs on that site... ty
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1
User avatar
p13z
Manic Miner
Posts: 611
Joined: Sun Feb 17, 2019 10:41 pm
Location: UK
Contact:

Re: programming a spiral in basic

Post by p13z »

This is a tiny addition to my earlier attempt, easy to tweak, just added the third parameter to DRAW.
Rough, slow, but as simple as you can get - bit like me.

Code: Select all

10 PLOT 127,83
20 FOR a=1 TO 87
30 DRAW a*COS a,a*SIN a,1.08
40 NEXT a
Image
User avatar
777
Manic Miner
Posts: 512
Joined: Fri Jun 26, 2020 11:23 am
Location: sw uk

Re: programming a spiral in basic

Post by 777 »

p13z wrote: Tue Sep 29, 2020 5:49 pm This is a tiny addition to my earlier attempt, easy to tweak, just added the third parameter to DRAW.
Rough, slow, but as simple as you can get - bit like me.

Code: Select all

10 PLOT 127,83
20 FOR a=1 TO 87
30 DRAW a*COS a,a*SIN a,1.08
40 NEXT a
Image
this was more the effect i was after, like a galaxy...

https://imgur.com/a/6SIX3w1

Code: Select all

1 BORDER 0: BRIGHT 1: PAPER 0: INK 7: CLS 
50 LET s=0
100 FOR a=1 TO 4000
120 LET x=SIN a*PI*s
125 LET y=COS a*PI*s/1.45
126 LET s=s+.01
130 PLOT x+128,y+87
200 NEXT a
i started programming the spectrum when i was 8 :-

1 plot rnd*255,rnd*175
2 goto 1
Post Reply