CustomGradient() - Spiral gradient - Fractal gradient

Share your advanced PureBasic knowledge/code with the community.
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

CustomGradient() - Spiral gradient - Fractal gradient

Post by eddy »

updated 4.40b3

Image

Code: Select all

#Image=0
#Window=0
#Gadget=0

Procedure.f ATan2(x.f, y.f)
   Protected angle.f=ATan(y/x)
   If x<0
      angle+3.141592653589793238;#PI
   ElseIf y<0
      angle+6.283185307179586477;2*#PI
   EndIf
   ProcedureReturn angle
EndProcedure
Structure SpiralGradient
   px.f
   py.f
   radius.f
   loop.i
EndStructure
Procedure.f SpiralGradientCallback(x, y)
   Shared SpiralGradient.SpiralGradient
   
   Protected.f px, py, d, dx, dy, c1, c2, c3, a, value
   dx=(x-SpiralGradient\px)
   dy=(y-SpiralGradient\py)
   d=Sqr(dx*dx+dy*dy)
   a=ATan2(dx, dy)
   value=(Cos(2*#PI*d/(SpiralGradient\radius/SpiralGradient\loop)+a)+1)/2

   ProcedureReturn value
EndProcedure
Procedure SpiralGradient(x, y, radius, loop)
   Shared SpiralGradient.SpiralGradient
   SpiralGradient\px=x
   SpiralGradient\py=y
   SpiralGradient\radius=radius
   SpiralGradient\loop=loop
   CustomGradient(@SpiralGradientCallback())
EndProcedure

If OpenWindow(#Window, 0, 0, 300, 300, "Spiral Gradient", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
   
   If CreateImage(#Image, 300, 300)
      If StartDrawing(ImageOutput(#Image))
            DrawingMode(#PB_2DDrawing_Gradient)
            GradientColor(0.00, $FFFF0000)
            GradientColor(0.20, $FFFFFF00)
            GradientColor(0.50, $FF00FF00)
            GradientColor(0.80, $FF00FFFF)
            GradientColor(1.00, $FF0000FF)
            SpiralGradient(150, 150, 150, 3)
            Circle(150, 150, 150)
            ;Box(0, 0, 300, 300)
         StopDrawing()
      EndIf
      
      ImageGadget(#Gadget, 0, 0, 300, 300, ImageID(#Image))
   EndIf
   
   Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf
Last edited by eddy on Wed Sep 16, 2009 2:42 pm, edited 8 times in total.
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
oreopa
Enthusiast
Enthusiast
Posts: 283
Joined: Sat Jun 24, 2006 3:29 am
Location: Edinburgh, Scotland.

Post by oreopa »

Interesting... I get a linker error...

"POLINK: Error: Unresolved external symbol '_PB_Custom_Gradient'

What did I break? :D

XP/4.40b2
Proud supporter of PB! * Musician * C64/6502 Freak
User avatar
Andre
PureBasic Team
PureBasic Team
Posts: 2139
Joined: Fri Apr 25, 2003 6:14 pm
Location: Germany (Saxony, Deutscheinsiedel)
Contact:

Post by Andre »

On my MacOS x86 10.5.8 using PureBasic v4.40 beta2 this code example produces only a black window background with a red-filled circle on it.

Anything missing in the Mac version of PB?
Bye,
...André
(PureBasicTeam::Docs & Support - PureArea.net | Order:: PureBasic | PureVisionXP)
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Post by Trond »

I get the linker error, too.
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

Lollipop ahoy. Runs fine on 4.40b1 here.
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
SFSxOI
Addict
Addict
Posts: 2970
Joined: Sat Dec 31, 2005 5:24 pm
Location: Where ya would never look.....

Post by SFSxOI »

This is for the 4.4 beta right? It would really help if people would say that in their post or code.
srod
PureBasic Expert
PureBasic Expert
Posts: 10589
Joined: Wed Oct 29, 2003 4:35 pm
Location: Beyond the pale...

Post by srod »

Linker error here as well with PB 4.4 beta 2 x86.
I may look like a mule, but I'm not a complete ass.
freak
PureBasic Team
PureBasic Team
Posts: 5944
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post by freak »

There is a bug with this in beta2.
quidquid Latine dictum sit altum videtur
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Re: CustomGradient() - spiral gradient

Post by eddy »

Image

updated for PB4.40b3 :mrgreen:

I tried to code a fractal gradient but ... too complex !
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
STARGÅTE
Addict
Addict
Posts: 2235
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: CustomGradient() - spiral gradient

Post by STARGÅTE »

I tried to code a fractal gradient but ... too complex !
This one ?

Code: Select all

Structure FractalGradient
 x.l
 y.l
 Size.l
 MaxIteration.l
EndStructure
Procedure.d Iteration(cx.d, cy.d)
 Shared FractalGradient.FractalGradient
 Protected Iter.l, x.d, y.d, xt.d, yt.d
 While x*x + y*y <= 6 And Iter < FractalGradient\MaxIteration
  xt = x*x - y*y + cx 
  yt = 2*x*y + cy 
  x = xt 
  y = yt
  Iter + 1 
 Wend 
 ProcedureReturn Iter/FractalGradient\MaxIteration
EndProcedure
Procedure.f FractalGradientCallback(x, y)
 Shared FractalGradient.FractalGradient
 With FractalGradient
  ProcedureReturn Iteration((x-\x)/\Size, (y-\y)/\Size)
 EndWith
EndProcedure
Procedure FractalGradient(x, y, Size, MaxIteration)
 Shared FractalGradient.FractalGradient
 With FractalGradient
  \x = x
  \y = y
  \Size = Size
  \MaxIteration = MaxIteration
 EndWith
 CustomGradient(@FractalGradientCallback())
EndProcedure

Enumeration
 #Image
 #Window
 #Gadget
EndEnumeration


CreateImage(#Image, 384, 256)
StartDrawing(ImageOutput(0))
 DrawingMode(#PB_2DDrawing_Gradient)
 FractalGradient(256, 128, 128,63)
 GradientColor(0.00, $0000FF)
 GradientColor(0.25, $00FFFF)
 GradientColor(0.50, $00FF00)
 GradientColor(0.75, $FFFF00)
 GradientColor(1.00, $FF0000)
 Box(0,0,384,256)
StopDrawing()

OpenWindow(#Window, 0, 0, ImageWidth(#Image), ImageHeight(#Image), "Fractal", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
 ImageGadget(#Gadget,0,0,ImageWidth(#Image), ImageHeight(#Image), ImageID(#Image))

Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Re: CustomGradient() - Spiral gradient - Fractal gradient

Post by eddy »

:o ... Cool! Thx for your code.
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
Post Reply