twisting pillar effect

Share your advanced PureBasic knowledge/code with the community.
Mr.L
Enthusiast
Enthusiast
Posts: 146
Joined: Sun Oct 09, 2011 7:39 am

twisting pillar effect

Post by Mr.L »

...just some eyecandy - make sure to disable debug mode

Code: Select all

InitSprite() : #WID = 400 : #HIG = 800
OpenWindow(0, 0, 0, #WID, #HIG, "!") : OpenWindowedScreen(WindowID(0), 0, 0, #WID, #HIG)
Procedure.f Min(a.f,b.f) : If a < b : ProcedureReturn a: EndIf: ProcedureReturn b : EndProcedure
Procedure.f Max(a.f,b.f) : If a > b : ProcedureReturn a: EndIf: ProcedureReturn b : EndProcedure
Macro renderLine(x1, x2, y, color, angle)
    xMid.f = (x1 + x2) * 0.5 : r = Red(color): g = Green(color): b = Blue(color)
    rng.f = 1.0 / (x2 - xMid) : x1 = Min(Max(0,x1),#WID-1) : x2 = Min(Max(0,x2),#WID-1)
    For x = x1 To x2
        pos.f = (x - xMid) * rng
        ang.f = (angle + ASin(pos) + (Cos((angle + pos * 2 * #PI) * 1.78) * 0.3)) + #PI * 0.5
        sf.f = 0.2 + 0.8 * Max(0, Min(1, Cos(ang))) : sp.f = Pow(Max(0, Cos(2 * ang)), 20) * 255
        Plot(x, y, RGB(Min(255, r * sf + sp), Min(255, g * sf + sp), Min(255, b * sf + sp)))
    Next
EndMacro
Repeat
    ClearScreen(RGB(64,64,64))
    If StartDrawing(ScreenOutput())
        t.f = ElapsedMilliseconds() / 1000.0
        ta.f = Sin(t * Cos(t) * 0.02) + t : tb.f = (1.0 + Sin(t) * 1.0) * 0.02 + 0.01
        xa.f = #WID * 0.5
        For y = 0 To #HIG - 1
            ya.f = y * 0.01
            rad.f = 60 + Sin(ta + ya) * 30: rot.f = t + Sin(ya * 2) * 0.5 + Cos(ta * 0.3) * 0.3
            x1 = xa + Sin(rot) * rad : x2 = xa + Sin(rot + #PI * 0.5) * rad
            x3 = xa + Sin(rot + #PI) * rad : x4 = xa + Sin(rot + #PI * 1.5) * rad
            If x1 < x2 : renderLine(x1, x2, y, #Red, rot) : EndIf
            If x2 < x3 : renderLine(x2, x3, y, #Green, rot + #PI * 0.5) : EndIf
            If x3 < x4 : renderLine(x3, x4, y, #Blue, rot + #PI) : EndIf
            If x4 < x1 : renderLine(x4, x1, y, #Yellow, rot + #PI * 1.5) : EndIf
            t + Sin(ta + ya) * tb : xa + Sin(t + ta) * 0.1
        Next
        StopDrawing()
    EndIf
    FlipBuffers()
    While WindowEvent():If Event() = #PB_Event_CloseWindow:End:EndIf:Wend
ForEver
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: twisting pillar effect

Post by Fangbeast »

That is totally unreal. Reminds me of many types of candy being twisted on a roller before they harden.

Thanks for that!
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4951
Joined: Sun Apr 12, 2009 6:27 am

Re: twisting pillar effect

Post by RASHAD »

Another contender to pf shadoko :mrgreen:
Nice effect
Thanks
Egypt my love
User avatar
idle
Always Here
Always Here
Posts: 5864
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: twisting pillar effect

Post by idle »

wow, i didn't expect that! :shock:
User avatar
moulder61
Enthusiast
Enthusiast
Posts: 192
Joined: Sun Sep 19, 2021 6:16 pm
Location: U.K.

Re: twisting pillar effect

Post by moulder61 »

Dayum! That's pretty spectacular!
How do you even come up with that stuff?

Moulder.
"If it ain't broke, fix it until it is!

This message is brought to you thanks to SenselessComments.com

My PB stuff for Linux: "https://u.pcloud.link/publink/show?code ... z3MR0T3jyV
BarryG
Addict
Addict
Posts: 4160
Joined: Thu Apr 18, 2019 8:17 am

Re: twisting pillar effect

Post by BarryG »

Fangbeast wrote: Thu Jul 18, 2024 8:21 amReminds me of many types of candy being twisted on a roller before they harden.
Was literally about to post this comment as well! Like the candy shop near the Big Banana.
User avatar
pf shadoko
Enthusiast
Enthusiast
Posts: 386
Joined: Thu Jul 09, 2015 9:07 am

Re: twisting pillar effect

Post by pf shadoko »

36 lines of code !
great job !
Mr.L
Enthusiast
Enthusiast
Posts: 146
Joined: Sun Oct 09, 2011 7:39 am

Re: twisting pillar effect

Post by Mr.L »

moulder61 wrote: Thu Jul 18, 2024 10:03 am How do you even come up with that stuff?
Actually, the idea came to me after reading the previous topic 'Snake simulation'.
In ancient times there was a very active computer demo scene, that came up with the craziest stuff (look for 64k demos or even 4k demos on pouet.net).
One of these effects was the 'twisting 4-Sided column'. And so I started coding, added some Sin here and a little bit of Cos there, and here you go! :lol:
User avatar
jacdelad
Addict
Addict
Posts: 2000
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: twisting pillar effect

Post by jacdelad »

What the...! :shock:
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
moulder61
Enthusiast
Enthusiast
Posts: 192
Joined: Sun Sep 19, 2021 6:16 pm
Location: U.K.

Re: twisting pillar effect

Post by moulder61 »

@Mr.L

In ancient times you would have been burned at the stake for this wizardry. ;)

Moulder.
"If it ain't broke, fix it until it is!

This message is brought to you thanks to SenselessComments.com

My PB stuff for Linux: "https://u.pcloud.link/publink/show?code ... z3MR0T3jyV
User avatar
Fangbeast
PureBasic Protozoa
PureBasic Protozoa
Posts: 4789
Joined: Fri Apr 25, 2003 3:08 pm
Location: Not Sydney!!! (Bad water, no goats)

Re: twisting pillar effect

Post by Fangbeast »

BarryG wrote: Thu Jul 18, 2024 10:22 am
Fangbeast wrote: Thu Jul 18, 2024 8:21 amReminds me of many types of candy being twisted on a roller before they harden.
Was literally about to post this comment as well! Like the candy shop near the Big Banana.
I was channeling your mind in your sleep:):)
Amateur Radio/VK3HAF, (D-STAR/DMR and more), Arduino, ESP32, Coding, Crochet
Nituvious
Addict
Addict
Posts: 1029
Joined: Sat Jul 11, 2009 4:57 am
Location: United States

Re: twisting pillar effect

Post by Nituvious »

I would like to create a petition; all eye candy code must be accompanied by eye candy screenshots! :mrgreen:
▓▓▓▓▓▒▒▒▒▒░░░░░
firace
Addict
Addict
Posts: 946
Joined: Wed Nov 09, 2011 8:58 am

Re: twisting pillar effect

Post by firace »

Really nice! Also, fiddling with parts of the code produces other interesting effects - for instance:

1.

Code: Select all

InitSprite() : #WID = 400 : #HIG = 800
OpenWindow(0, 0, 0, #WID, #HIG, "!") : OpenWindowedScreen(WindowID(0), 0, 0, #WID, #HIG)
Procedure.f Min(a.f,b.f) : If a < b : ProcedureReturn a: EndIf: ProcedureReturn b : EndProcedure
Procedure.f Max(a.f,b.f) : If a > b : ProcedureReturn a: EndIf: ProcedureReturn b : EndProcedure

Macro renderLine(x1, x2, y, color, angle)
  xMid.f = (x1 + x2) * 0.5 : r = Red(color): g = Green(color): b = Blue(color)
  rng.f = 1.0 / (x2 - xMid) : x1 = Min(Max(0,x1),#WID-1) : x2 = Min(Max(0,x2),#WID-1)
  For x = x1 To x2
    pos.f = (x - xMid) * rng
    ang.f = (angle + ASin(pos) + (Cos((angle + pos * 2 * #PI) * 1.78) * 0.3)) + #PI * 0.5
    sf.f = 0.2 + 0.8 * Max(0, Min(1, Cos(ang))) : sp.f = Pow(Max(0, Cos(2 * ang)), 20) * 255
    Plot(x, y, $ce9A9A)
  Next
EndMacro

Repeat
  ClearScreen(RGB(64,64,64))
  If StartDrawing(ScreenOutput())
    t.f = ElapsedMilliseconds() / 1000.0
    ta.f = Sin(t * Cos(t) * 0.02) + t : tb.f = (1.0 + Sin(t) * 1.0) * 0.02 + 0.01
    xa.f = #WID * 0.5
    For y = 0 To #HIG - 1
      ya.f = y * 0.01
      rad.f = 60 + Sin(ta + ya) * 30: rot.f = t + Sin(ya * 2) * 0.5 + Cos(ta * 0.3) * 0.3
      x1 = xa + Sin(rot) * rad : x2 = xa + Sin(rot + #PI * 0.5) * rad
      x3 = xa + Sin(rot + #PI) * rad : x4 = xa + Sin(rot + #PI * 1.5) * rad
      If x1 < x2 : renderLine(x1, x1, y, #Red, rot) : EndIf
      If x2 < x3 : renderLine(x2, x4, y, #Green, rot + #PI * 0.5) : EndIf
      If x3 < x4 : renderLine(x3, x4, y, #Blue, rot + #PI) : EndIf
      If x4 < x1 : renderLine(x4, x1, y, #Yellow, rot + #PI * 1.5) : EndIf
      t + Sin(ta + ya) * tb : xa + Sin(t + ta) * 0.1
    Next
    StopDrawing()
  EndIf
  FlipBuffers()
  While WindowEvent():If Event() = #PB_Event_CloseWindow:End:EndIf:Wend
ForEver

2.

Code: Select all

InitSprite() : #WID = 400 : #HIG = 800
OpenWindow(0, 0, 0, #WID, #HIG, "!") : OpenWindowedScreen(WindowID(0), 0, 0, #WID, #HIG)
Procedure.f Min(a.f,b.f) : If a < b : ProcedureReturn a: EndIf: ProcedureReturn b : EndProcedure
Procedure.f Max(a.f,b.f) : If a > b : ProcedureReturn a: EndIf: ProcedureReturn b : EndProcedure

Macro renderLine(x1, x2, y, color, angle)
  xMid.f = (x1 + x2) * 0.5 : r = Red(color): g = Green(color): b = Blue(color)
  rng.f = 1.0 / (x2 - xMid) : x1 = Min(Max(0,x1),#WID-1) : x2 = Min(Max(0,x2),#WID-1)
  For x = x1 To x2
    pos.f = (x - xMid) * rng
    ang.f = (angle + ASin(pos) + (Cos((angle + pos * 2 * #PI) * 1.78) * 0.3)) + #PI * 0.5
    sf.f = 0.2 + 0.8 * Max(0, Min(1, Cos(ang))) : sp.f = Pow(Max(0, Cos(2 * ang)), 20) * 255
    Plot(x, y, RGB(Min(255, r * sf + sp), Min(255, g * sf + sp), $99))

  Next
EndMacro

Repeat
  ClearScreen(RGB(64,64,64))
  If StartDrawing(ScreenOutput())
    t.f = ElapsedMilliseconds() / 1000.0
    ta.f = Sin(t * Cos(t) * 0.02) + t : tb.f = (1.0 + Sin(t) * 1.0) * 0.02 + 0.01
    xa.f = #WID * 0.5
    For y = 0 To #HIG - 1
      ya.f = y * 0.01
      rad.f = 60 + Sin(ta + ya) * 30: rot.f = t + Sin(ya * 2) * 0.5 + Cos(ta * 0.3) * 0.3
      x1 = xa + Sin(rot) * rad : x2 = xa + Sin(rot + #PI * 0.5) * rad
      x3 = xa + Sin(rot + #PI) * rad : x4 = xa + Sin(rot + #PI * 1.5) * rad
      If x1 < x2 : renderLine(x1, x1, y, #Red, rot) : EndIf
      If x2 < x3 : renderLine(x2, x4, y, #Green, rot + #PI * 0.5) : EndIf
      If x3 < x4 : renderLine(x3, x4, y, #Blue, rot + #PI) : EndIf
      If x4 < x1 : renderLine(x4, x1, y, #Yellow, rot + #PI * 1.5) : EndIf
      t + Sin(ta + ya) * tb : xa + Sin(t + ta) * 0.1
    Next
    StopDrawing()
  EndIf
  FlipBuffers()
  While WindowEvent():If Event() = #PB_Event_CloseWindow:End:EndIf:Wend
ForEver

3.

Code: Select all

InitSprite() : #WID = 400 : #HIG = 800
OpenWindow(0, 0, 0, #WID, #HIG, "!") : OpenWindowedScreen(WindowID(0), 0, 0, #WID, #HIG)
Procedure.f Min(a.f,b.f) : If a < b : ProcedureReturn a: EndIf: ProcedureReturn b : EndProcedure
Procedure.f Max(a.f,b.f) : If a > b : ProcedureReturn a: EndIf: ProcedureReturn b : EndProcedure

Macro renderLine(x1, x2, y, color, angle)
  xMid.f = (x1 + x2) * 0.5 : r = Red(color): g = Green(color): b = Blue(color)
  rng.f = 1.0 / (x2 - xMid) : x1 = Min(Max(0,x1),#WID-1) : x2 = Min(Max(0,x2),#WID-1)
  For x = x1 To x2
    pos.f = (x - xMid) * rng
    ang.f = (angle + ASin(pos) + (Cos((angle + pos * 2 * #PI) * 1.78) * 0.3)) + #PI * 0.5
    sf.f = 0.2 + 0.8 * Max(0, Min(1, Cos(ang))) : sp.f = Pow(Max(0, Cos(2 * ang)), 20) * 255
;     Plot(x, y, RGB(Min(255, g * sf + sp), Min(255, g * sf + sp), $29))
    Plot(x, y, RGB(Min(255, g * sf + sp), Min(255, g * sf + sp), $29))

  Next
EndMacro

Repeat
  ClearScreen(RGB(64,64,64))
  If StartDrawing(ScreenOutput())
    t.f = ElapsedMilliseconds() / 1000.0
    ta.f = Sin(t * Cos(t) * 0.02) + t : tb.f = (1.0 + Sin(t) * 1.0) * 0.02 + 0.01
    xa.f = #WID * 0.5
    For y = 0 To #HIG - 1
      ya.f = y * 0.05
      rad.f = 60 + Sin(ta + ya) * 30: rot.f = t + Sin(ya * 2) * 0.5 + Cos(ta * 0.3) * 0.3
      x1 = xa + Cos(rot) * rad : x2 = xa + Sin(rot + #PI * 0.5) * rad
      x3 = xa + Sin(rot + #PI) * rad : x4 = xa + Cos(rot + #PI * 1.5) * rad
      If x1 < x2 : renderLine(x1, x1, y, #Red, rot) : EndIf
      If x2 < x3 : renderLine(x2, x4, y, #Green, rot + #PI * 0.5) : EndIf
      If x3 < x4 : renderLine(x3, x4, y, #Blue, rot + #PI) : EndIf
      If x4 < x1 : renderLine(x4, x1, y, #Yellow, rot + #PI * 1.5) : EndIf
      t + Sin(ta + ya) * tb : xa + Sin(t + ta) * 0.1
    Next
    StopDrawing()
  EndIf
  FlipBuffers()
  While WindowEvent():If Event() = #PB_Event_CloseWindow:End:EndIf:Wend
ForEver
User avatar
SPH
Enthusiast
Enthusiast
Posts: 565
Joined: Tue Jan 04, 2011 6:21 pm

Re: twisting pillar effect

Post by SPH »

TOP XTRA ! Waouwwww !! Small code ! GG 👍

!i!i!i!i!i!i!i!i!i!
!i!i!i!i!i!i!
!i!i!i!
//// Informations ////
Portable LENOVO ideapad 110-17ACL 64 bits
Version de PB : 6.12LTS - 64 bits
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: twisting pillar effect

Post by Kwai chang caine »

What words can be used for define this splendid effect more true than nature ??? :shock:
Thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
Post Reply