Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PSET "hat" graphic from old ad in BYTE
#21
So this post will give the almost-original "PSET hat" drawing from an ad by Micro Technology Unlimited in Compute magazines of 1981.  The ad was for a Commodore PET upgrade to hi-res (320x200!).  The code has been modified to run under QB64, slowed down, and made able to be paused.  @CharlieJV got the key link to the thread ( https://atariage.com/forums/topic/218503.../#comments ) where Atari fans are running it -- on Ataris and many other old computers!  A lot of talk there how to speed it up.  We have to slow it down.  It's a BIG thread, but no mention of an author.

It was and is still stunning how such a few lines of code can create a complex drawing and even take care of hidden lines.  Here is a little info on the workings of the program (the programmer was working with a BASIC with 2-character name restrictions!).  I can understand only some of the code.  The hidden points in back are hidden by erasing them as the nearer points are drawn.  I did plot the math function they used:  Plug this function into my "FunctionPlot" program ( https://qb64phoenix.com/forum/showthread.php?tid=260 ).

Code: (Select All)
Function func1 (x)
  Dim r: r = Abs(x)
  func1 = (Sin(r) + 0.4 * Sin(3 * r)) * 4
  Line (zux(-4.71), 400)-(zux(-4.71), 700), 1 ' limits
  Line (zux(4.71), 400)-(zux(4.71), 700), 1 ' limits
End Function

Imagine the curve between the blue lines, rotated around the center -- it would look like a hat!  You can replace this one line in the original code and a get a different hat -- a dunce hat.

Code: (Select All)
'Replace this:
120 YY = (Sin(XT) + 0.4 * Sin(3 * XT)) * YF
'with this:
120 YY = 80 - Abs(XT) * 80
'Wait a few seconds for the hat to appear from below.

The almost-original code: ( @bplus - obviously I've spent too much time on this )

Code: (Select All)
' From Compute Magazine, 11/1/1981
' Ad by Micro Technology Unlimited, pg42
' The following has minimal changes to the original:
' o) to make it work in QB64
' o) to slow it down
' o) to be able to pause (ENTER), exit (ESC)
Dim Shared time0: time0 = Timer

' 10 VISMEM: CLEAR
10 Screen 7
20 P = 160: Q = 104
30 XP = 144: XR = 1.5 * 3.1415927
40 YP = 56: YR = 1: ZP = 64
50 XF = XR / XP: YF = YP / YR: ZF = XR / ZP
60 For ZI = -Q To Q - 1
  70 If ZI < -ZP Or ZI > ZP GoTo 150
  80 ZT = ZI * XP / ZP: ZZ = ZI
  90 XL = Int(.5 + (Sqr(XP * XP - ZT * ZT)))
  100 For XI = -XL To XL
    110 XT = Sqr(XI * XI + ZT * ZT) * XF: XX = XI
    120 YY = (Sin(XT) + 0.4 * Sin(3 * XT)) * YF
    130 GoSub 170
    sub1 (0) ' ck keyboard
  140 Next XI
150 Next ZI
' 160 Stop
160 sub1 (1) ' exit
170 X1 = XX + ZZ + P
180 Y1 = YY - ZZ + Q
' 190 GMODE 1: MOVE X1,Y1: WRPIX
190 PSet (X1, 199 - Y1), 15
200 If Y1 = 0 GoTo 220
' 210 GMODE 2: LINE X1,Y1-1,X1,0
210 Line (X1, 199 - Y1 + 1)-(X1, 199), 0
220 Return

Sub sub1 (swexit) ' ck keyboard, etc.
  _Limit 1000 ' slows it down (30 secs)
  If swexit Then s$ = Chr$(13): Locate 25, 1: _
   Print Timer - time0;: Else s$ = InKey$
  If s$ = Chr$(27) Then System ' exit
  If s$ = Chr$(13) Then
    While InKey$ = "": Wend
  End If
  If swexit Then System
End Sub

That Atari thread had another version, that drew front-to-back instead of back-to-front.  To do that and take care of hidden points, an
array(320) holds the y values drawn so far, and any point lower is not drawn.  Here is that code, from the same thread.

Code: (Select All)
' The "hat" - Front-to-back processing
' https://atariage.com/forums/topic/218503-graphics-8-fedora-hat/#comments
' Micro Tech Unlimited ad in Compute Magazine 11/1/81
Screen 7
100 Dim RR(320)
120 For I = 0 To 320: RR(I) = 193: Next I
150 XP = 144: XR = 4.71238905: XF = XR / XP
160 For ZI = 64 To -64 Step -1
  170 ZT = ZI * 2.25: ZS = ZT * ZT
  180 XL = Int(Sqr(20736 - ZS) + 0.5)
  190 For XI = 0 - XL To XL
    200 XT = Sqr(XI * XI + ZS) * XF
    210 YY = (Sin(XT) + Sin(XT * 3) * 0.4) * 56
    220 X1 = XI + ZI + 160: Y1 = 96 - YY + ZI
    223 If RR(X1) <= Y1 Then 250
    226 RR(X1) = Y1
    230 PSet (X1, Y1), 15
250 _Limit 2000: Next XI: Next ZI
260 While InKey$ = "": Wend: System

I could spend time on using that technique on a large screen, but I would rather study OpenGL.  With OpenGL, you (you) can create the surface in 3D and then move it and rotate it.  A great start into QB64 OpenGL is https://ashishkingdom.github.io/OpenGL-Tutorials/intro/ .  It covers basics, points, lines, triangles (key to all surfaces), circles, colors, textures, 2D translations, [oops, stop].  Very well done, but doesn't make it to 3D translations and 2D and 3D rotations, lights, cameras, etc. I will be asking how to get further into this.
Reply
#22
Hi @dcromley

Here is another mod by b+
Code: (Select All)
_Title "Hat - b+ mod of dcromley's port from atari" '  2022-04-30
' The "hat" - Front-to-back processing
' https://atariage.com/forums/topic/218503-graphics-8-fedora-hat/#comments
' Micro Tech Unlimited ad in Compute Magazine 11/1/81

'Screen 7
'Print _Width, _Height   ' get screen 7 measurements
'End
Const sw = 320, sh = 320 '     rcromley might enjoy a modern look?
Screen _NewImage(sw, sh, 32) ' converting to graphics for millions more color choices
_ScreenMove 500, 250
Color , &HFFBBBB99: Cls
Dim RR(320)
For I = 0 To 320: RR(I) = 193: Next I
XP = 144: XR = 4.71238905: XF = XR / XP
For ZI = 64 To -64 Step -.1
    ZT = ZI * 2.25: ZS = ZT * ZT
    XL = Int(Sqr(20736 - ZS) + 0.5)
    For XI = 0 - XL To XL Step 1.5
        XT = Sqr(XI * XI + ZS) * XF
        YY = (Sin(XT) + Sin(XT * 3) * 0.4) * 56
        X1 = XI + ZI + 160: Y1 = 96 - YY + ZI
        If RR(X1) > Y1 Then
            RR(X1) = Y1
            PSet (X1, Y1 + 80), _RGB32(70 + 2 * x / sw, 45 + 2 * x / sw, 3 * (16 + Y1 / sh)) ' attempt some colorization
        End If
Next XI: Next ZI
Beep: Sleep


[Image: Hat.png]

I messed up color, need to get z involved and bigger multiplier than 1 for fraction of screen x, y is at. I leave that to another needing to kill time ;-))

I had fun with this thanks, thumbs up to you!
b = b + ...
Reply
#23
Quote:@bplus : .. messed up color .. 
An entirely different texture!  Interesting.  Got to look again/more.  Tnx.
Reply
#24
https://en.wikipedia.org/wiki/Yabasic#Yabasic_example

Actually edited it for QB64 and used _PUTIMAGE to make the screen twice as large.
Reply
#25
A little extra related reading material from 1982:  https://archive.org/details/analog-compu...1/mode/2up
Reply
#26
@CharlieJV Neat find from 1982! Thanks. Will process it.
___________________________________________________________________________________
I am mostly grateful for the people who came before me.  Will the people after me be grateful for me?
Reply
#27
I revisited my program and created a version that plays with colours a bit, redrawing with random colours in a loop:

* Run the program
* View the source code

   
Reply




Users browsing this thread: 8 Guest(s)