zak
25-07-2011, 08:06
in this thread (http://www.thinbasic.com/community/showthread.php?10349-MathArt-Port-of-code-by-Stan-Blank&highlight=MathArt) "MathArt: Port of code by Stan Blank" the program uses TBGL module to plot the points, below is the same code but using the Canvas, the part of the code :
x1 = x*25 + 300
y1 = y*25 + 280
means to amplify and shift the draw, in the original TBGL code this is done by using a virtual window to set the resolution and the coordinate system using:
TBGL_RenderMatrix2D (-axrng, axrng, axrng, -axrng)
in the original code the refresh process are done by continuosly calling the list in which the plot stored:
TBGL_CallList %listPoints
but in this canvas program the refresh are done using the instruction "Canvas_Redraw", i have inserted it in line 33 to give the impression of animation, any modifications are welcome.
7354
' originally MathArt by Stan Blank
' Ported to TBGL by Petr Schreiber
' ported to Canvas by zak, from thinbasic street, apartment 31415, nowhere planet
Uses "UI"
' Global variables
'-----------------------------------------------------------
Dim ScreenWidth As Long = 800
Dim ScreenHeight As Long = 600
Dim hWin As DWord '---Handle of the canvas window
Dim x,y,x1,y1,r As Double
Dim axrng As Double = 10
'-----------------------------------------------------------
' Main program
'-----------------------------------------------------------
hWin = Canvas_Window("mathArt _ press any key to exit", 1, 1, ScreenWidth, ScreenHeight )
Canvas_Attach(hWin, 0, %TRUE) ' <- double buffer
'---Init canvas
Canvas_Clear(%BLACK)
Canvas_Width(1)
For x = -axrng To axrng Step 0.04
For y = -axrng To axrng Step 0.04
r = Cos(x) + Sin(y)
x1 = x*25 + 300
y1 = y*25 + 280
Canvas_Color(Rgb(Cos(y*r)*255, Cos(x*y*r)*255, Sin(r*x)*255))
Canvas_SetPixel(x1, y1)
Next
Canvas_Redraw
Next
Canvas_Redraw
Canvas_WaitKey
Canvas_Window End
x1 = x*25 + 300
y1 = y*25 + 280
means to amplify and shift the draw, in the original TBGL code this is done by using a virtual window to set the resolution and the coordinate system using:
TBGL_RenderMatrix2D (-axrng, axrng, axrng, -axrng)
in the original code the refresh process are done by continuosly calling the list in which the plot stored:
TBGL_CallList %listPoints
but in this canvas program the refresh are done using the instruction "Canvas_Redraw", i have inserted it in line 33 to give the impression of animation, any modifications are welcome.
7354
' originally MathArt by Stan Blank
' Ported to TBGL by Petr Schreiber
' ported to Canvas by zak, from thinbasic street, apartment 31415, nowhere planet
Uses "UI"
' Global variables
'-----------------------------------------------------------
Dim ScreenWidth As Long = 800
Dim ScreenHeight As Long = 600
Dim hWin As DWord '---Handle of the canvas window
Dim x,y,x1,y1,r As Double
Dim axrng As Double = 10
'-----------------------------------------------------------
' Main program
'-----------------------------------------------------------
hWin = Canvas_Window("mathArt _ press any key to exit", 1, 1, ScreenWidth, ScreenHeight )
Canvas_Attach(hWin, 0, %TRUE) ' <- double buffer
'---Init canvas
Canvas_Clear(%BLACK)
Canvas_Width(1)
For x = -axrng To axrng Step 0.04
For y = -axrng To axrng Step 0.04
r = Cos(x) + Sin(y)
x1 = x*25 + 300
y1 = y*25 + 280
Canvas_Color(Rgb(Cos(y*r)*255, Cos(x*y*r)*255, Sin(r*x)*255))
Canvas_SetPixel(x1, y1)
Next
Canvas_Redraw
Next
Canvas_Redraw
Canvas_WaitKey
Canvas_Window End