Author Topic: Curves  (Read 951 times)

0 Members and 1 Guest are viewing this topic.

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
Curves
« on: February 01, 2022, 04:35:33 pm »
Code: [Select]
deflng a-z
dim shared sw, sh
sw = 1024
sh = 600
dim shared pi as double
pi = 4*atn(1)

screen _newimage(sw, sh, 32)

dim as long n, r, mx, my, mb, omx, omy
n = 0
redim x(n) as long, y(n) as long

r = 5
do
getmouse mx, my, mb

if mb = 1 then
n = 1
redim _preserve x(n)
redim _preserve y(n)

x(0) = mx - sw/2
y(0) = sh/2 - my

pset (mx, my)
do while mb = 1
getmouse mx, my, mb

line -(mx, my), _rgb(30,30,30)

if (mx - omx)^2 + (my - omy)^2 > r^2 then
circlef mx, my, 3, _rgb(30,30,30)
omx = mx
omy = my

x(n) = mx - sw/2
y(n) = sh/2 - my
n = n + 1
redim _preserve x(n)
redim _preserve y(n)
end if

_display
_limit 50
loop

'close the contour
'x(n) = x(0)
'y(n) = y(0)
'n = n + 1
'redim _preserve x(n)
'redim _preserve y(n)


'redraw spline
'pset (sw/2 + x(0), sh/2 - y(0))
'for i=0 to n
'line -(sw/2 + x(i), sh/2 - y(i)), _rgb(255,0,0)
'circlef sw/2 + x(i), sh/2 - y(i), 3, _rgb(255,0,0)
'next

dim as double bx, by, t, bin
pset (sw/2 + x(0), sh/2 - y(0))
for t=0 to 1 step 0.0001
bx = 0
by = 0

for i=0 to n
bin = 1
for j=1 to i
bin = bin*(n - j)/j
next

bx = bx + bin*((1 - t)^(n - 1 - i))*(t^i)*x(i)
by = by + bin*((1 - t)^(n - 1 - i))*(t^i)*y(i)
next

line -(sw/2 + bx, sh/2 - by), _rgb(255,0,0)
next
end if

_display
_limit 50
loop until _keyhit = 27
system

sub getmouse (mx as long, my as long, mb as long)
do
mx = _mousex
my = _mousey
mb = -_mousebutton(1)
loop while _mouseinput
end sub
 
sub circlef(x as long, y as long, r as long, c as long)
dim as long x0, y0, e
        x0 = r
        y0 = 0
        e = -r
 
        do while y0 < x0
                if e <=0 then
                        y0 = y0 + 1
                        line (x - x0, y + y0)-(x + x0, y + y0), c, bf
                        line (x - x0, y - y0)-(x + x0, y - y0), c, bf
                        e = e + 2*y0
                else
                        line (x - y0, y - x0)-(x + y0, y - x0), c, bf
                        line (x - y0, y + x0)-(x + y0, y + x0), c, bf
                        x0 = x0 - 1
                        e = e - 2*x0
                end if
        loop
        line (x - r, y)-(x + r, y), c, bf
end sub


 
caligpro3.PNG
« Last Edit: February 01, 2022, 04:59:41 pm by _vince »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
Re: Curves
« Reply #1 on: February 01, 2022, 05:32:11 pm »
That's awesome for designing! Just remember, one letter at a time though or the whole word turns into a squiggle. lol

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
Re: Curves
« Reply #2 on: February 01, 2022, 06:49:08 pm »
 
B+ mod vince code.PNG


Code: QB64: [Select]
  1. _Title "b+ mods vince fine Curves code" ' b+ 2022-02-01
  2. DefLng A-Z
  3. Const sw = 1024, sh = 600 ' const shared everywhere
  4. Screen _NewImage(sw, sh, 32)
  5. _ScreenMove 150, 60 'center stage
  6.  
  7. 'put 'em all here
  8. Dim As Long n, r, mx, my, mb, omx, omy, i, j, vs
  9. Dim As Double bx, by, t, bin
  10. Dim k$
  11. ReDim x(n) As Long, y(n) As Long
  12.  
  13. vs = _NewImage(sw, sh, 32) ' vs for virtual screen
  14. r = 5 'gap checker?
  15.     Cls
  16.     k$ = InKey$
  17.     If k$ = "c" Then
  18.         _Dest vs
  19.         Line (0, 0)-(sw, sh), &HFF000000, BF
  20.         _Dest 0
  21.         Cls
  22.     End If
  23.     _PutImage , vs, 0
  24.     While _MouseInput: Wend ' poll mouse update mouse variables
  25.     mx = _MouseX: my = _MouseY: mb = _MouseButton(1)
  26.  
  27.  
  28.     If mb Then
  29.         n = 1
  30.         ReDim _Preserve x(n)
  31.         ReDim _Preserve y(n)
  32.  
  33.         x(0) = mx - sw / 2
  34.         y(0) = sh / 2 - my
  35.  
  36.         PSet (mx, my)
  37.         Do While mb
  38.             While _MouseInput: Wend ' poll mouse update mouse variables
  39.             mx = _MouseX: my = _MouseY: mb = _MouseButton(1)
  40.             Line -(mx, my), _RGB(30, 30, 30)
  41.  
  42.             If (mx - omx) ^ 2 + (my - omy) ^ 2 > r ^ 2 Then
  43.                 circlef mx, my, 3, _RGB(30, 30, 30)
  44.                 omx = mx
  45.                 omy = my
  46.  
  47.                 x(n) = mx - sw / 2
  48.                 y(n) = sh / 2 - my
  49.                 n = n + 1
  50.                 ReDim _Preserve x(n)
  51.                 ReDim _Preserve y(n)
  52.             End If
  53.  
  54.             _Display
  55.             '_Limit 30
  56.         Loop
  57.  
  58.         'close the contour
  59.         'x(n) = x(0)
  60.         'y(n) = y(0)
  61.         'n = n + 1
  62.         'redim _preserve x(n)
  63.         'redim _preserve y(n)
  64.  
  65.  
  66.         'redraw spline
  67.         'pset (sw/2 + x(0), sh/2 - y(0))
  68.         'for i=0 to n
  69.         'line -(sw/2 + x(i), sh/2 - y(i)), _rgb(255,0,0)
  70.         'circlef sw/2 + x(i), sh/2 - y(i), 3, _rgb(255,0,0)
  71.         'next
  72.         _Dest vs
  73.         PSet (sw / 2 + x(0), sh / 2 - y(0))
  74.         For t = 0 To 1 Step 0.0001
  75.             bx = 0
  76.             by = 0
  77.  
  78.             For i = 0 To n
  79.                 bin = 1
  80.                 For j = 1 To i
  81.                     bin = bin * (n - j) / j
  82.                 Next
  83.  
  84.                 bx = bx + bin * ((1 - t) ^ (n - 1 - i)) * (t ^ i) * x(i)
  85.                 by = by + bin * ((1 - t) ^ (n - 1 - i)) * (t ^ i) * y(i)
  86.             Next
  87.  
  88.             Line -(sw / 2 + bx, sh / 2 - by), _RGB(255, 0, 0)
  89.         Next
  90.         _Dest 0
  91.     End If
  92.  
  93.     _Display
  94.     _Limit 30
  95.  
  96. Sub circlef (x As Long, y As Long, r As Long, c As Long)
  97.     Dim As Long x0, y0, e
  98.     x0 = r
  99.     y0 = 0
  100.     e = -r
  101.  
  102.     Do While y0 < x0
  103.         If e <= 0 Then
  104.             y0 = y0 + 1
  105.             Line (x - x0, y + y0)-(x + x0, y + y0), c, BF
  106.             Line (x - x0, y - y0)-(x + x0, y - y0), c, BF
  107.             e = e + 2 * y0
  108.         Else
  109.             Line (x - y0, y - x0)-(x + y0, y - x0), c, BF
  110.             Line (x - y0, y + x0)-(x + y0, y + x0), c, BF
  111.             x0 = x0 - 1
  112.             e = e - 2 * x0
  113.         End If
  114.     Loop
  115.     Line (x - r, y)-(x + r, y), c, BF
  116.  
  117.  

Works best with slowly printed letters.

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
Re: Curves
« Reply #3 on: February 01, 2022, 10:35:07 pm »
nice mod,
 
bplus2.PNG

Offline Phlashlite

  • Newbie
  • Posts: 50
Re: Curves
« Reply #4 on: February 01, 2022, 10:41:07 pm »
Very cool!