Author Topic: How could thicken the compass needle line ?  (Read 1943 times)

0 Members and 1 Guest are viewing this topic.

Offline acjacques

  • Newbie
  • Posts: 33
How could thicken the compass needle line ?
« on: October 31, 2019, 11:30:34 am »
Hi;  How I could thicken the compass needle line ?

Code: QB64: [Select]
  1.  
  2. CX = 320: CY = 240 'Centre of circle
  3. Rad = 100 'Radius
  4.  
  5.    '_LIMIT 100
  6.     mX = _MOUSEX: mY = _MOUSEY
  7.     ang = mX
  8.   ' rad = mY
  9.  
  10.     IF ang = 360 THEN ang = 0
  11.     IF ang > 360 THEN ang = ang - 360
  12.  
  13.  
  14.     X = CX + COS(_D2R(ang - 90)) * Rad
  15.     Y = CY + SIN(_D2R(ang - 90)) * Rad
  16.  
  17.     pX = CX + COS(_D2R(ang - 90)) * (Rad + 1)
  18.     pY = CY + SIN(_D2R(ang - 90)) * (Rad + 1)
  19.     LINE (CX, CY)-(oldX, oldY), 0 'clear the old line
  20.     LINE (CX, CY)-(X, Y), 14 'yellow needle line
  21.     PSET (pX, pY)
  22.     oldX = X: oldY = Y
  23.     LOCATE 1, 10: PRINT USING "Angle: ###.##"; ang;
  24.    'PRINT " mX= "; mX
  25.     CIRCLE (CX, CY), 5, 14
  26.  
  27.  
  28.  
« Last Edit: October 31, 2019, 11:36:26 am by acjacques »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: How could thicken the compass needle line ?
« Reply #1 on: October 31, 2019, 12:01:38 pm »
This code: https://www.qb64.org/forum/index.php?topic=1810.msg110567#msg110567

Demo's the thic (thick line drawing) SUB that requires the ftri SUB for filling triangles (but you don't have to know how to use that).

hmm... looks like need to switch to 32 bit graphics colors to use that.
« Last Edit: October 31, 2019, 12:18:37 pm by bplus »

Marked as best answer by acjacques on October 31, 2019, 10:53:54 am

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: How could thicken the compass needle line ?
« Reply #2 on: October 31, 2019, 12:21:26 pm »
Code: QB64: [Select]
  1. _TITLE "Compass fix and mod B+ 2019-10-31"
  2.  
  3. SCREEN _NEWIMAGE(700, 700, 32)
  4. _SCREENMOVE 400, 20
  5. CX = 350: CY = 350 'Centre of circle
  6. Radius = 100 'Radius
  7.  
  8.     CLS
  9.     mX = _MOUSEX: mY = _MOUSEY
  10.     ang = _ATAN2(mY - CY, mX - CX)
  11.     IF ang < 0 THEN ang = ang + _PI(2)
  12.     X = CX + Radius * COS(ang)
  13.     Y = CY + Radius * SIN(ang)
  14.     thic CX, CY, X, Y, 5, &HFFFFFF00
  15.     da = _R2D(ang) + 90
  16.     IF da > 360 THEN da = da - 360
  17.     LOCATE 1, 10: PRINT USING "Angle: ###.##"; da
  18.     CIRCLE (CX, CY), 5, &HFFFFFF00
  19.     CIRCLE (CX, CY), Radius, &HFFFFFFFF
  20.     _DISPLAY
  21.     _LIMIT 60
  22.  
  23. SUB thic (x1, y1, x2, y2, thick, K AS _UNSIGNED LONG)
  24.     PD2 = _PI / 2
  25.     DIM t2 AS SINGLE, a AS SINGLE, x3 AS SINGLE, y3 AS SINGLE, x4 AS SINGLE, y4 AS SINGLE
  26.     DIM x5 AS SINGLE, y5 AS SINGLE, x6 AS SINGLE, y6 AS SINGLE
  27.     t2 = thick / 2
  28.     IF t2 < 1 THEN t2 = 1
  29.     a = _ATAN2(y2 - y1, x2 - x1)
  30.     x3 = x1 + t2 * COS(a + PD2)
  31.     y3 = y1 + t2 * SIN(a + PD2)
  32.     x4 = x1 + t2 * COS(a - PD2)
  33.     y4 = y1 + t2 * SIN(a - PD2)
  34.     x5 = x2 + t2 * COS(a + PD2)
  35.     y5 = y2 + t2 * SIN(a + PD2)
  36.     x6 = x2 + t2 * COS(a - PD2)
  37.     y6 = y2 + t2 * SIN(a - PD2)
  38.     ftri x6, y6, x4, y4, x3, y3, K
  39.     ftri x3, y3, x5, y5, x6, y6, K
  40.  
  41. SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  42.     DIM a&
  43.     a& = _NEWIMAGE(1, 1, 32)
  44.     _DEST a&
  45.     PSET (0, 0), K
  46.     _DEST 0
  47.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  48.     _FREEIMAGE a& '<<< this is important!
  49.  

EDIT: fix the display angle for more compass like readings
« Last Edit: October 31, 2019, 12:44:29 pm by bplus »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: How could thicken the compass needle line ?
« Reply #3 on: October 31, 2019, 01:06:11 pm »
Might look better with filled triangles:
Code: QB64: [Select]
  1. _TITLE "Compass 2 fix and mod B+ 2019-10-31"
  2.  
  3. SCREEN _NEWIMAGE(500, 500, 32)
  4. _SCREENMOVE 400, 20
  5. CX = 250: CY = 250 'Centre of circle
  6. Radius = 200 'Radius
  7.  
  8.     CLS
  9.     mX = _MOUSEX: mY = _MOUSEY
  10.     ang = _ATAN2(mY - CY, mX - CX)
  11.     IF ang < 0 THEN ang = ang + 2 * _PI
  12.     X = CX + Radius * COS(ang)
  13.     Y = CY + Radius * SIN(ang)
  14.     x1 = CX + 20 * COS(ang + _PI / 2)
  15.     y1 = CY + 20 * SIN(ang + _PI / 2)
  16.     x2 = CX + 20 * COS(ang - _PI / 2)
  17.     y2 = CY + 20 * SIN(ang - _PI / 2)
  18.     x3 = CX + Radius * COS(ang - _PI)
  19.     y3 = CY + Radius * SIN(ang - _PI)
  20.     ftri x1, y1, x2, y2, X, Y, &HFFFFFFFF
  21.     ftri x1, y1, x2, y2, x3, y3, &HFF444444
  22.     da = _R2D(ang) + 90
  23.     IF da >= 360 THEN da = da - 360
  24.     LOCATE 1, 10: PRINT USING "Angle: ###.##"; da ' usually want o degrees pointing North
  25.     CIRCLE (CX, CY), 5, &HFF000000
  26.     i = 0
  27.     FOR a = 0 TO _PI(2) STEP _PI(1 / 18)
  28.         X = CX + Radius * COS(a)
  29.         Y = CY + Radius * SIN(a)
  30.         i = i + 1
  31.         IF (i - 10) MOD 9 = 0 THEN
  32.             CIRCLE (X, Y), 4, &HFFFFFFFF
  33.         ELSE
  34.             CIRCLE (X, Y), 1, &HFFFFFFFF
  35.         END IF
  36.     NEXT
  37.     _DISPLAY
  38.     _LIMIT 60
  39.  
  40.  
  41. SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  42.     DIM a&
  43.     a& = _NEWIMAGE(1, 1, 32)
  44.     _DEST a&
  45.     PSET (0, 0), K
  46.     _DEST 0
  47.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  48.     _FREEIMAGE a& '<<< this is important!
  49.  
  50.  
  51.  

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
Re: How could thicken the compass needle line ?
« Reply #4 on: October 31, 2019, 01:46:14 pm »
Cool Bplus!
  [ You are not allowed to view this attachment ]  

a fine evolution of compass of acJacques.
Fine idea to share acjacques!

Programming isn't difficult, only it's  consuming time and coffee

Offline acjacques

  • Newbie
  • Posts: 33
Re: How could thicken the compass needle line ?
« Reply #5 on: November 01, 2019, 07:33:15 pm »
I made some mods :  Resizeable screen
Visual changes
Text fixed at center


Code: QB64: [Select]
  1. 'RESIZE:STRETCH
  2. size = 300 'enter size of window
  3. iwidth = size
  4. iheight = size
  5.  
  6. _TITLE "Compass fix and mod B+ 2019-10-31"
  7. 'MODIFIED by ACJACQUES 2019-11-02
  8.  
  9. SCREEN _NEWIMAGE(iwidth, iheight, 32)
  10. _SCREENMOVE 400, 20
  11. CX = iwidth / 2: CY = iheight / 2 'Centre of circle
  12. Radius = size / 3 'Radius
  13.  
  14.  
  15.     CLS
  16.     _MOUSESHOW "CROSSHAIR" ' will display a crosshair cursor
  17.     DO WHILE _MOUSEINPUT: LOOP 'wait for mouse
  18.     mX = _MOUSEX: mY = _MOUSEY 'get mouse xy
  19.  
  20.     ang = _ATAN2(mY - CY, mX - CX)
  21.     IF ang < 0 THEN ang = ang + _PI(2)
  22.  
  23.     X = CX + Radius * COS(ang)
  24.     Y = CY + Radius * SIN(ang)
  25.     thic CX, CY, X, Y, 3, &HFFFFFF00
  26.     da = _R2D(ang) + 90
  27.     'IF ang = 360 THEN ang = 0
  28.     IF da > 359.99 THEN da = da - 360
  29.  
  30.  
  31.     CIRCLE (CX, CY), 38, &HFFFFFFFF 'white center circle
  32.     PAINT (CX, CY), &HFFFFFFFF, &HFFFFFFFF 'filling
  33.  
  34.     CIRCLE (CX, CY), 37, &HFF000000 'black center circle
  35.     PAINT (CX, CY), &HFF000000, &HFF000000 'filling
  36.  
  37.     CIRCLE (CX, CY), Radius + 3, &HFFFFFFFF 'external white circle
  38.  
  39.     'LOCATE 10, 10:
  40.     'PRINT USING "Angle: ###.##"; da
  41.  
  42.     da = INT(da) 'make only integer
  43.     chrstr$ = STR$(da) 'convert to string
  44.  
  45.     chrstr$ = RIGHT$("00" + LTRIM$(chrstr$), 3) 'to include leading zeros
  46.     COLOR _RGB(255, 255, 0) 'color for text
  47.     _PRINTSTRING (CX - 12, CY - 6), chrstr$ ' set position relativve graphic screen with  offsets to be centered
  48.     _DISPLAY
  49.     _LIMIT 60
  50.  
  51. SUB thic (x1, y1, x2, y2, thick, K AS _UNSIGNED LONG)
  52.     PD2 = _PI / 3
  53.     DIM t2 AS SINGLE, a AS SINGLE, x3 AS SINGLE, y3 AS SINGLE, x4 AS SINGLE, y4 AS SINGLE
  54.     DIM x5 AS SINGLE, y5 AS SINGLE, x6 AS SINGLE, y6 AS SINGLE
  55.     t2 = thick / 2
  56.     IF t2 < 1 THEN t2 = 1
  57.     a = _ATAN2(y2 - y1, x2 - x1)
  58.     x3 = x1 + t2 * COS(a + PD2)
  59.     y3 = y1 + t2 * SIN(a + PD2)
  60.     x4 = x1 + t2 * COS(a - PD2)
  61.     y4 = y1 + t2 * SIN(a - PD2)
  62.     x5 = x2 + t2 * COS(a + PD2)
  63.     y5 = y2 + t2 * SIN(a + PD2)
  64.     x6 = x2 + t2 * COS(a - PD2)
  65.     y6 = y2 + t2 * SIN(a - PD2)
  66.     ftri x6, y6, x4, y4, x3, y3, K
  67.     ftri x3, y3, x5, y5, x6, y6, K
  68.  
  69. SUB ftri (x1, y1, x2, y2, x3, y3, K AS _UNSIGNED LONG)
  70.     DIM a&
  71.     a& = _NEWIMAGE(1, 1, 32)
  72.     _DEST a&
  73.     PSET (0, 0), K
  74.     _DEST 0
  75.     _MAPTRIANGLE _SEAMLESS(0, 0)-(0, 0)-(0, 0), a& TO(x1, y1)-(x2, y2)-(x3, y3)
  76.     _FREEIMAGE a& '<<< this is important!

 [ You are not allowed to view this attachment ]  
« Last Edit: November 01, 2019, 07:39:06 pm by acjacques »