Jump to content
IGNORED

pye chart problem


Recommended Posts

 

Can someone please help me to sort out this problem. I'm trying to draw a pye-chart and putting a letter ('A' onwards) representing each % segment. I haven't finished it because I'm getting a problem that I just can't solve. The pye-chart segments are depicted by the values in the DATA; 25 is 25% of 360 degrees, 50 is 50% etc. but when I move 12.5% (just as an effort to iron out the problem) the program is supposed to put the letter 'A' on the edge of the circle on the right in between 0 degrees and 90 degrees, but its appearing further over on the left side (which is weird and I just don't understand).

 

Please, any help would be most appreciated.

 

100 GRAPHICS 8+16:POKE 710,0:COLOR 1
102 SM=PEEK(88)+256*PEEK(89)
104 DEG 
108 X=160:Y=96:S=80
110 V=0:Q=360/100:CH=33
114 FOR D=0 TO 359
120 RX=(COS(D)*(S+20))+X
130 RY=(SIN(D)*S)+Y
140 PLOT RX,RY
150 IF V=0 THEN READ B:V=1
160 Z=INT(Q*B):Z2=INT(Q*12.5)
164 IF D=Z THEN DRAWTO X,Y:PLOT RX,RY:V=0:GOTO 190
170 IF D=Z2 THEN GOSUB 500
190 NEXT D
200 DATA 0,25,50,52,81,90,100
300 GOTO 300
500 FOR I=0 TO 7
520 POKE SM+INT(RX/8)+RY*40+I*40,PEEK(224*256+CH*8+I)
560 NEXT I
564 CH=CH+1
570 RETURN

 

Link to comment
Share on other sites

4 minutes ago, ivop said:

Rounding is wrong:

 

520 POKE SM+INT(RX)/8+INT(RY)*40+I*40,PEEK(224*256+CH*8+I)

 

Thankyou for that, that certainly does the trick, but I still dont understand it, since:

If I ? INT(RX/8) when RX = 228.199836 the result is exactly 28, but:

? INT(RX)/8 = 28.5 and when POKEing on line 520 there shouldn't be any difference. 28 or 28.5 you would think the round number would work and the other not, but whether the result be 28 or 28.5, they both should work? I don't understand.

Link to comment
Share on other sites

6 minutes ago, ivop said:

The RX value was not the biggest problem. It's RY*40 versus INT(RY)*40. If RY is not an integer, you are displacing your poke position by fractions of 40 bytes.

Oh ofcourse, I didn't realise that, I think I was thrown because the letter 'A' was still put on screen after 45 degrees which was throwing me, it made me think that RY was correct but RX wrong. Anyway, thanks for that.

 

The problem I got now is getting all the other letters in the correct place, can you work out how to that? coz I'm having difficulty doing it.

Link to comment
Share on other sites

18 minutes ago, ivop said:

Remove line 170.

On line 164, change GOTO 190, into, GOSUB 500 (keep it on the same line, within the scope of the IF statement (!)).

 

blerk.png.d5d83df300cf9b4ea7cfa412f5f1d0a3.png

 

Thanks for that, but I was trying to put the letters in-between the segments rather than on the lines, but if I can't or no-one else can do this I will be doing it the way you have. I would prefer it with, as I said, the letters in-between.

Link to comment
Share on other sites

I see. You can, if you let Z2 (in your original code) depend on B and the previous B. Z2=INT(Q*((B+PREVB)/2))

And then GOSUB on D=Z2 as you did before.

 

In the 500 routine, you can also mitigate for being in one of the four quarters, and either subtract 8 from RX or not, or subtract 8 from RY or not, before printing the character. Use TEMPX,TEMPY for that to not disturb the main loop.

 

I could program all of this for you, but where's the fun in that for you? :)

 

Link to comment
Share on other sites

This was really winding me up trying to do this, I tried absolutely everything, as a last resort I done what you said ivop, I took a previous B and executed:

 

Z2=INT(Q*((B+PREVB)/2))

 

That finally done the trick, so for your curiosity:

add B2=B on line 164 and add the above equation after Z= on line 160 (B2 is PREVB).

 

As it goes, it looks better with the letters adjacent the lines rather than in-between, anyhow, thanks for your help ivop.

 

 

  • Thanks 1
Link to comment
Share on other sites

Basically, it uses the average of each consecutive pair of B values. That's why you end up in the middle of the piece of the pie :)

 

Now you might notice that each letter is on the right side and below of its plot point. You can fix that if you determine in which quadrant you are and use temporary variables to calculate where to start poking your character. So you get the characters left and right, and up and below your pie chart, with minimal interference with the drawing itself. Good luck, and have fun! :)

Edited by ivop
typo
Link to comment
Share on other sites

On 8/28/2021 at 9:08 PM, ivop said:

Basically, it uses the average of each consecutive pair of B values. That's why you end up in the middle of the piece of the pie :)

 

Now you might notice that each letter is on the right side and below of its plot point. You can fix that if you determine in which quadrant you are and use temporary variables to calculate where to start poking your character. So you get the characters left and right, and up and below your pie chart, with minimal interference with the drawing itself. Good luck, and have fun! :)

It's ok, I just changed (RX)/8 to (RX/8) and it sorts that problem quite well. Cheers ivop.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...