Author Topic: Graphics Test #2 - are you certifiable?  (Read 7120 times)

0 Members and 1 Guest are viewing this topic.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Graphics Test #2 - are you certifiable?
« Reply #15 on: November 30, 2021, 07:41:37 pm »
Warning! Do not run this if you are prone to Epileptic Seizures.

Code: QB64: [Select]
  1. _Title "Rotating Spokes" 'b+ 2021-11-30
  2. DefDbl A-Z
  3. Const ss = 700: ssd2 = ss / 2: pi = _Pi
  4. Screen _NewImage(ss, ss, 32)
  5. _ScreenMove 280, 40
  6.     Cls
  7.     For r = 1 To 9
  8.         n = 2 ^ r
  9.         stepper = pi * (2 / n)
  10.         oa = oa * -1
  11.         For a = 0 To _Pi(2) - .0000001 Step stepper
  12.             x1 = ssd2 + (r - 1) * 35 * Cos(a + oa): y1 = ssd2 + (r - 1) * 35 * Sin(a + oa)
  13.             x2 = ssd2 + r * 35 * Cos(a + oa): y2 = ssd2 + r * 35 * Sin(a + oa)
  14.             If r Mod 2 Then Line (x1, y1)-(x2, y2), _RGB32(0, 128 + 128 * a / (2 * pi), 0) Else Line (x1, y1)-(x2, y2), _RGB32(0, 0, 128 + 128 * a / (2 * pi))
  15.         Next
  16.     Next
  17.     oa = Abs(oa) + pi / 360
  18.     _Display
  19.     _Limit 20
  20.  


No really, there is no message to send money, send money, send money...

Actually this is pretty close to what I did in OP and also I think I can make it recursive now, stay tuned...

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Graphics Test #2 - are you certifiable?
« Reply #16 on: December 01, 2021, 11:33:48 am »
Couldn't get the recursive version working last night but this morning with fresh eyes found a bunch of typos and got slightly different results in middle with 2/3 the code, but looks better I think!

 
recurs 2 branching.PNG


Code: QB64: [Select]
  1. _Title "Globe - recurs 2 branching" 'b+ 2021-12-01 got it working
  2. DefDbl A-Z
  3. Const ss = 700, SSD2 = ss / 2, PI = _Pi
  4. Screen _NewImage(ss, ss, 32)
  5. _ScreenMove 280, 40
  6. r2branch 1
  7.  
  8. Sub r2branch (r)
  9.     If r = 9 Then Exit Sub
  10.     n = 2 ^ r
  11.     stepper = PI * (2 / n)
  12.     ao = .5 * stepper
  13.     ao2 = .25 * stepper
  14.     For a = 0 To 2 * PI - .0000001 Step stepper
  15.         x1 = SSD2 + (r - 1) * 40 * Cos(a + ao): y1 = SSD2 + (r - 1) * 40 * Sin(a + ao)
  16.         x2 = SSD2 + r * 40 * Cos(a + ao - ao2): y2 = SSD2 + r * 40 * Sin(a + ao - ao2)
  17.         Line (x1, y1)-(x2, y2)
  18.         x2 = SSD2 + r * 40 * Cos(a + ao + ao2): y2 = SSD2 + r * 40 * Sin(a + ao + ao2)
  19.         Line (x1, y1)-(x2, y2)
  20.     Next
  21.     r2branch r + 1
  22.  

Before recursive effort, I saved the points in an array and used a simple formula for points in array to draw lines from point on one circle to 2 or more points on the next. Then the main problem was getting things to line up pretty.

Really now you can change out the recursive sub for a Main For Loop:
Code: QB64: [Select]
  1. _Title "Globe - elim recurs 2 branching" 'b+ 2021-12-01 got it working
  2. DefDbl A-Z
  3. Const ss = 700, SSD2 = ss / 2, PI = _Pi
  4. Screen _NewImage(ss, ss, 32)
  5. _ScreenMove 280, 40
  6. For r = 1 To 8
  7.     n = 2 ^ r
  8.     stepper = PI * (2 / n)
  9.     ao = .5 * stepper
  10.     ao2 = .25 * stepper
  11.     For a = 0 To 2 * PI - .0000001 Step stepper
  12.         x1 = SSD2 + (r - 1) * 40 * Cos(a + ao): y1 = SSD2 + (r - 1) * 40 * Sin(a + ao)
  13.         x2 = SSD2 + r * 40 * Cos(a + ao - ao2): y2 = SSD2 + r * 40 * Sin(a + ao - ao2)
  14.         Line (x1, y1)-(x2, y2)
  15.         x2 = SSD2 + r * 40 * Cos(a + ao + ao2): y2 = SSD2 + r * 40 * Sin(a + ao + ao2)
  16.         Line (x1, y1)-(x2, y2)
  17.     Next
  18.  

Offline Dimster

  • Forum Resident
  • Posts: 500
    • View Profile
Re: Graphics Test #2 - are you certifiable?
« Reply #17 on: December 01, 2021, 12:22:53 pm »
Ran "Rotating Spokes", lucky for me there was no money in my pocket. Pretty cool how it rotates in opposite directions at the same time.
Steve's reminds me of the aftermath of an earthquake. Needs a go fund me site to generate $$$$ from the effort.
Wonder if you guys could live off the proceeds? Maybe consider NFT's??????

Offline johannhowitzer

  • Forum Regular
  • Posts: 118
    • View Profile
Re: Graphics Test #2 - are you certifiable?
« Reply #18 on: December 01, 2021, 06:48:09 pm »
Code: QB64: [Select]
  1.  
  2. type node_structure
  3.    angle  as single
  4.    ring   as byte    ' Which ring to draw on
  5.    parent as integer ' Parent node
  6. dim shared node(65535) as node_structure
  7. dim shared node_count as integer
  8.  
  9. input "Number of rings:    ", rings
  10. input "Number of branches: ", branches
  11.  
  12. for ring = 1 to rings
  13.    new_branches = branches ^ ring
  14.  
  15.    for n = 1 to new_branches
  16.       node_count = node_count + 1
  17.       node(node_count).angle  = (8 * atn(1)) * (n / new_branches)
  18.       node(node_count).ring   = ring
  19.       node(node_count).parent = first_parent + int((n - 1) / branches)
  20.    next n
  21.  
  22.    first_parent = first_parent + int(new_branches / branches)
  23. next ring
  24.  
  25. for n = 1 to node_count
  26.    p = node(n).parent
  27.    v1 = 240 * (node(n).ring / rings)
  28.    v2 = 240 * (node(p).ring / rings)
  29.    line(320 + (v1 * cos(node(n).angle)), 240 + (v1 * sin(node(n).angle)))-_
  30.        (320 + (v2 * cos(node(p).angle)), 240 + (v2 * sin(node(p).angle))), 15
  31.  

Without looking at others' code, while I was in some downtime at work I glanced at the OP, and threw this together in about ten minutes.  I see I took a different approach; while others seem to be going straight to the drawing step, I started by building a network of references, and letting the user input the number of rings, as well as the number of branches from each node.

My result is a little different, because the new ring of nodes are grouping up to the previous ring via an int() modifier on the stack index.  But I think this looks even cooler, and since all the nodes are saved, I can do more things to them if I want.  Fun challenge!

 
stargen.png
« Last Edit: December 01, 2021, 08:37:09 pm by johannhowitzer »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Graphics Test #2 - are you certifiable?
« Reply #19 on: December 01, 2021, 10:20:04 pm »
Oh very nice challenge @johannhowitzer

Here I calculate the number of rings that will have enough space to keep each spoke separate from the others around the edge. Here is 2 to 9 branching, press any when the screen is sleeping ie "ZZZ..."

Code: QB64: [Select]
  1. _Title "Globe - N(2 to 9) Branching" 'b+ 2021-12-01
  2. DefDbl A-Z
  3. Const ss = 730, pi32 = _Pi(3 / 2)
  4. Screen _NewImage(ss, ss, 32)
  5. _ScreenMove 250, 10
  6. Dim As Integer power, radius, n, i, branch, rings
  7.  
  8. For branch = 2 To 9
  9.     Cls
  10.  
  11.     rings = 1 ' according to number branches decide number of rings that will fit
  12.     While ss / 2 * _Pi(2) / branch ^ rings > 3
  13.         rings = rings + 1
  14.     Wend
  15.     rings = Int(rings) - 1
  16.     deltaRadius = Int((ss / 2) / rings) ' divide max radius by rings
  17.  
  18.     'save points of ring in these 2D arrays d1 = ring d2 = point number on ring
  19.     ReDim xp(0 To rings, 0 To branch ^ (rings + 1)), yp(0 To rings, 0 To branch ^ (rings + 1))
  20.  
  21.     For power = 0 To rings ' load points from rings
  22.         radius = power * deltaRadius
  23.         n = branch ^ power
  24.         stepper = _Pi(2 / n)
  25.         ao = .5 * stepper
  26.         i = 0
  27.         For a = 0 To _Pi(2) - .000001 Step stepper
  28.             xp(power, i) = ss / 2 + radius * Cos(a + ao + pi32)
  29.             yp(power, i) = ss / 2 + radius * Sin(a + ao + pi32)
  30.             i = i + 1
  31.         Next
  32.     Next
  33.  
  34.     power = 0 ' OK draw the lines
  35.     For power = 0 To rings - 1
  36.         accum = 0
  37.         For i = 0 To branch ^ power - 1
  38.             For k = 0 To branch - 1
  39.                 Line (xp(power, i), yp(power, i))-(xp(power + 1, accum + k), yp(power + 1, accum + k))
  40.             Next
  41.             accum = accum + branch
  42.         Next
  43.     Next
  44.     Print "Branches:"; branch; "  ZZZ... "
  45.     Sleep
  46.  
  47.  

Alas, it took me more than 10 minutes to whip up ;-))

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Graphics Test #2 - are you certifiable?
« Reply #20 on: December 03, 2021, 07:28:28 am »
Recursive 3 branching from tsh73 at JB, translated and adopted to my style of display:
Code: QB64: [Select]
  1. _Title "3 branching recurs by tsh73" 'b+ trans from JB 2021-12-02
  2. Const ss = 600, cx = ss / 2, cy = cx, pi = _Pi
  3. Screen _NewImage(ss, ss, 32)
  4. _ScreenMove 300, 60
  5. drawBranches cx, cy, 0, 0, 45, 0
  6. Sub drawBranches (x, y, a, totLen, legth, level)
  7.     If level > 6 Then Exit Sub
  8.     x1 = cx + Cos(a) * totLen
  9.     y1 = cy + Sin(a) * totLen
  10.     Line (x, y)-(x1, y1)
  11.     N = 3 ^ (level + 1)
  12.     da = 2 * pi / N
  13.     drawBranches x1, y1, (a - da), (totLen + legth), legth, level + 1
  14.     drawBranches x1, y1, a, (totLen + legth), legth, level + 1
  15.     drawBranches x1, y1, (a + da), (totLen + legth), legth, level + 1
  16.  
  17.  




Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Graphics Test #2 - are you certifiable?
« Reply #21 on: December 03, 2021, 07:49:29 am »
Actually this looks more like his original, pretty cool too!:
Code: QB64: [Select]
  1. _Title "3 branching recurs by tsh73 more like original" 'b+ trans from JB 2021-12-03
  2. Const ss = 600, cx = ss / 2, cy = cx, pi = _Pi
  3. Screen _NewImage(ss, ss, 32)
  4. _ScreenMove 300, 60
  5. Color &HFF000011, &HFFBBBBFF
  6. drawBranches cx, cy, 0, 0, 256, 0
  7.  
  8. Sub drawBranches (x, y, a, totLen, leg, level)
  9.     '                   This had me stuck for awhile!!!
  10.     legth = leg ' <<<< change name of variable for recursive sub in QB64 before passing changed value in next call
  11.     If legth < 1 Then Exit Sub
  12.     x1 = cx + Cos(a) * totLen
  13.     y1 = cy + Sin(a) * totLen
  14.     Circle (cx, cy), totLen
  15.     Line (x, y)-(x1, y1)
  16.     N = 3 ^ (level + 1)
  17.     da = 2 * pi / N
  18.     legth = legth / 2  ' >> changed value requires the name change in QB64 (not in JB that passes by value not reference)
  19.     drawBranches x1, y1, (a - da), (totLen + legth), legth, level + 1
  20.     drawBranches x1, y1, a, (totLen + legth), legth, level + 1
  21.     drawBranches x1, y1, (a + da), (totLen + legth), legth, level + 1
  22.  

 
3 branching more like tsh73 original.PNG
« Last Edit: December 03, 2021, 08:01:34 am by bplus »

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Graphics Test #2 - are you certifiable?
« Reply #22 on: December 14, 2021, 06:32:32 pm »
have a pretty flower, bplus

Code: QB64: [Select]
  1. defdbl a-z
  2. pi = 4*atn(1)
  3. screen _newimage(640, 640, 32)
  4. _title "Plumeria"
  5. for t=0 to 2*_pi step 0.001
  6.         x = 190*cos(t) + 200*cos(t*6)
  7.         y = 190*sin(t) + 200*sin(t*6)
  8.         d = sqr(x*x + y*y)
  9.         if d < 250 then
  10.                 c = 255 - d
  11.                 if d > od or d > 110 then
  12.                         pset (320 + x, 320 + y),_rgb(255,200 - 0.8*c,225 - 0.8*c)
  13.                 end if
  14.         end if
  15.         od = d
  16.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Graphics Test #2 - are you certifiable?
« Reply #23 on: December 14, 2021, 07:54:32 pm »
Back to you @_vince :)

Code: QB64: [Select]
  1. _Title "Plumeria - colorized and motorized by b+"
  2. Screen _NewImage(700, 700, 32)
  3. _ScreenMove 300, 40
  4.     For t = 0 To 2 * _Pi Step 0.001
  5.         x = 190 * Cos(t + ao) + 200 * Cos(t * 6 + ao)
  6.         y = 190 * Sin(t + ao) + 200 * Sin(t * 6 + ao)
  7.         PSet (350 + x, 350 + y), _RGB(255 * y / 390, 255 * t / 5, ao * 255)
  8.     Next
  9.     ao = ao + .001
  10.     If ao > 2 * _Pi(1 / 5) Then ao = 0
  11.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Graphics Test #2 - are you certifiable?
« Reply #24 on: December 18, 2021, 11:27:08 pm »
More generalized variation with interesting pattern at mult > 6

Code: QB64: [Select]
  1. _Title "Press spacebar for new mult"
  2. Screen _NewImage(700, 700, 32)
  3. _ScreenMove 300, 40
  4. For mult = 2 To 16
  5.     Cls
  6.     Print mult
  7.     Do
  8.         For t = 0 To 2 * _Pi Step 0.001
  9.             x = 200 * Cos(t + ao) + 200 * Cos(t * mult + ao)
  10.             y = 200 * Sin(t + ao) + 200 * Sin(t * mult + ao)
  11.             PSet (350 + x, 350 + y), _RGB(255 * y / 390, 0, 255 * t / _Pi(2))
  12.         Next
  13.         ao = ao + .001
  14.         If ao > _Pi(2 / (mult - 1)) Then ao = 0
  15.         If InKey$ = " " Then Exit Do
  16.     Loop
  17.  
  18.  

Offline _vince

  • Seasoned Forum Regular
  • Posts: 422
    • View Profile
Re: Graphics Test #2 - are you certifiable?
« Reply #25 on: December 19, 2021, 04:53:07 am »
nice, bplus

How did you generate the cubes or steve's shelves?

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Graphics Test #2 - are you certifiable?
« Reply #26 on: December 19, 2021, 08:31:26 am »
nice, bplus

How did you generate the cubes or steve's shelves?

Hi _vince

I was doing experiments in "Real" 3d rendering here:
https://www.qb64.org/forum/index.php?topic=1904.15