Post by bplus on Nov 18, 2021 11:39:05 GMT -5
johnno56 recently posted a translation of old 2016-09-07 code from SdlBasic to RCBasic. I had to see what it was, I didn't remember it?
So here is the SdlBasic translated into QB64, the animation looks much better than the still:
And a screen shot to jog memories:
So here is the SdlBasic translated into QB64, the animation looks much better than the still:
_Title "3D Surface Plot" ' b+ trans SdlBasic to QB64 2021-11-18 to see WTH? it is :)
' Johnno posted a translation of this at RCBasic ref: https://rcbasic.freeforums.net/thread/603/3d-surface-plot
' My code animation of AndyA ref: http://sdlbasic.epizy.com/showthread.php?tid=299
' from sdlBasic version notes
'===========================================================================
'3D Surface Plot
'From "Microcomputer Graphics Techniques and Applications" by Donald Hearn
'Ported To PB by Dave Navarro (dave@powerbasic.com)
'===========================================================================
'Converted to sdlBAS, and colorized by Andres Amaya Jr
' 2016-09-07 (B+=MGA) mod per Andy's instructions to animate drawing and check speed of transitions
'===========================================================================
'SetDisplay(960, 720,32,1)
Screen _NewImage(960, 700, 32)
_ScreenMove 150, 40
'SetCaption("3D Surface Plot")
'autoback(-10) '<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
sw = 960: sh = 720
cx = Int(sw / 2): cy = Int(sh / 2)
fx = cx - 30: fy = cy - 114
Dim pal(47)
pal(0) = &HFF0000FF: pal(1) = &HFF2000FF: pal(2) = &HFF4000FF: pal(3) = &HFF6000FF
pal(4) = &HFF8000FF: pal(5) = &HFFA000FF: pal(6) = &HFFC000FF: pal(7) = &HFFE000FF
pal(8) = &HFFFF00FF: pal(9) = &HFFFF00E0: pal(10) = &HFFFF00C0: pal(11) = &HFFFF00A0
pal(12) = &HFFFF0080: pal(13) = &HFFFF0060: pal(14) = &HFFFF0040: pal(15) = &HFFFF0020
pal(16) = &HFFFF0000: pal(17) = &HFFFF2000: pal(18) = &HFFFF4000: pal(19) = &HFFFF6000
pal(20) = &HFFFF8000: pal(21) = &HFFFFA000: pal(22) = &HFFFFC000: pal(23) = &HFFFFE000
pal(24) = &HFFFFFF00: pal(25) = &HFFE0FF00: pal(26) = &HFFC0FF00: pal(27) = &HFFA0FF00
pal(28) = &HFF80FF00: pal(29) = &HFF60FF00: pal(30) = &HFF40FF00: pal(31) = &HFF20FF00
pal(32) = &HFF00FF00: pal(33) = &HFF00FF20: pal(34) = &HFF00FF40: pal(35) = &HFF00FF60
pal(36) = &HFF00FF80: pal(37) = &HFF00FFA0: pal(38) = &HFF00FFC0: pal(39) = &HFF00FFE0
pal(40) = &HFF00FFFF: pal(41) = &HFF00E0FF: pal(42) = &HFF00C0FF: pal(43) = &HFF00A0FF
pal(44) = &HFF0080FF: pal(45) = &HFF0060FF: pal(46) = &HFF0040FF: pal(47) = &HFF0020FF
Rho = 45 'Viewing Elevation
Scale = 1020 'Scaling Factor
Theta = 1.0
snt = Sin(Theta): cst = Cos(Theta)
Phi = 1.0
snp = Sin(Phi): csp = Cos(Phi)
tx = 450: ty = 485 'x & y translates
incremented = 3.1
dr = -1
increment = .2
While 1
Cls
For x = -15 To 15 Step 0.125
flag = 0
x2 = x * x
For y = -15 To 15 Step 0.125
xy2 = (x2 + y * y) / 20.0
z = incremented * Cos(xy2)
xe = -x * snt + y * cst
ye = -x * cst * csp - y * snt * csp + z * snp
ze = -x * snp * cst - y * snt * snp - z * csp + Rho
sx = Scale * xe / ze
sy = Scale * ye / ze
ix = Int(sx + tx)
iy = sh - Int(sy + ty)
colr = (Int(Sqr((fx - ix) * (fx - ix) + 4.3 * (fy - iy) * (fy - iy)) / 15) + 7) Mod 48
If flag = 0 Then
'PSet (ix, iy), pal(colr)
flag = 1: oldx = ix: oldy = iy
Else
'Ink( pal(colr) )
Line (oldx, oldy)-(ix, iy), pal(colr)
oldx = ix: oldy = iy
End If
Next
Next
'screenswap
_Display
incremented = incremented + increment * dr
If incremented > 5 Then
incremented = 5
dr = dr * -1
End If
If incremented < -5 Then
incremented = -5
dr = dr * -1
End If
Wend
And a screen shot to jog memories: