Sorceress

Elliptic Curves Mesh

Jan 7th, 2021 (edited)
100
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. 'Elliptic Curves Mesh (c)2021 @_sorceress
  2.  
  3. DEFDBL A-Z
  4. DIM col AS LONG, i AS LONG
  5.  
  6. SCREEN _NEWIMAGE(800, 600, 32)
  7. cx = 400: cy = 300
  8.  
  9. WHILE INKEY$ <> CHR$(27)
  10. a = 10 * SIN(TIMER * .43): b = 10 * SIN(TIMER * .23)
  11. 'a = -7: b = 10
  12. t = TIMER / 4: sint = SIN(t): cost = COS(t)
  13.  
  14. CLS
  15. 'mesh plot
  16. FOR xi = -5 TO 5.1 STEP .2
  17. FOR xr = -5 TO 5 STEP .01
  18. GOSUB ECfunc
  19. col = _RGB(128 + xr * 16, 128 - xi * 16, 128 + yi * 16)
  20. GOSUB plot
  21. yr = -yr: yi = -yi 'negative root
  22. col = _RGB(128 + xr * 16, 128 - xi * 16, 128 + yi * 16)
  23. GOSUB plot
  24. NEXT
  25. NEXT
  26. FOR xr = -5 TO 5.1 STEP .2
  27. FOR xi = -5 TO 5 STEP .01
  28. GOSUB ECfunc
  29. col = _RGB(128 + xr * 16, 128 - xi * 16, 128 + yi * 16)
  30. GOSUB plot
  31. yr = -yr: yi = -yi 'negative root
  32. col = _RGB(128 + xr * 16, 128 - xi * 16, 128 + yi * 16)
  33. GOSUB plot
  34. NEXT
  35. NEXT
  36.  
  37. 'real subspace
  38. col = _RGB(255, 255, 0): xi = 0
  39. FOR xr = -10 TO 10 STEP .001
  40. GOSUB ECfunc
  41. IF ABS(yi) < ABS(yr) THEN GOSUB plot: yr = -yr: yi = -yi: GOSUB plot
  42. NEXT
  43.  
  44. 'axes
  45. xr = 10: xi = 0: yr = 0: yi = 0
  46. GOSUB plot: LINE (cx, cy)-(px, py), _RGB(255, 0, 0): LOCATE py \ 16 + 1, px \ 8 + 1: PRINT "Re(z)"
  47. xr = 0: xi = 10: yr = 0: yi = 0
  48. GOSUB plot: LINE (cx, cy)-(px, py), _RGB(0, 255, 0): LOCATE py \ 16 + 1, px \ 8 + 1: PRINT "Im(z)"
  49. xr = 0: xi = 0: yr = 10: yi = 0
  50. GOSUB plot: LINE (cx, cy)-(px, py), _RGB(0, 0, 255): LOCATE py \ 16 + 1, px \ 8 + 1: PRINT "Re(w)"
  51. xr = 0: xi = 0: yr = 0: yi = 10
  52. GOSUB plot: LINE (cx, cy)-(px, py), _RGB(127, 127, 127): LOCATE py \ 16 + 1, px \ 8 + 1: PRINT "Im(w)"
  53.  
  54. _DISPLAY
  55. _LIMIT 10
  56. WEND
  57. SYSTEM
  58.  
  59. ECfunc: 'inputs (xr,xi) outputs (yr,yi)
  60. 'y^2 = q = x^3 +a*x + b 'elliptic curve over complex x
  61. qr = xr * (xr * xr - 3 * xi * xi + a) + b
  62. qi = xi * (3 * xr * xr - xi * xi + a)
  63. modq = SQR(qr * qr + qi * qi)
  64. yr = 0.707107 * SQR(modq + qr)
  65. IF yr <> 0 THEN yi = qi / (2 * yr) ELSE yi = SQR(-qr)
  66. RETURN
  67.  
  68. plot: 'projects point to R2 and plots it
  69. gx = xi * cost - yi * sint
  70. gy = xi * sint + yi * cost
  71. px = 400 + 25 * (xr + gx * .5)
  72. py = 300 - 25 * (yr + gy * .5)
  73. PSET (px, py), col
  74. RETURN
  75.  
  76.  
RAW Paste Data