RetroBASIC
Basicprogramming(.org) => Code and examples => Topic started by: B+ on July 31, 2016, 07:01:03 PM
-
'one liner graphic.bas for SmallBASIC 0.12.6 [B+=MGA] 2016-07-31
for x in seq(0,512^2,512^2) do pset x mod 512,x\512,rgb((x mod 512)mod 256,((x mod 512) xor (x\512))mod 256,(x\512)mod 128)
-
Thumbs up!
-
One liner, you say?
I wonder what I can come up with.... :D
-
hmm... maybe I should have said one statement?
It has been pointed out to me there is a much shorter version (Thanks jsalai!)
for x=0 to 262144 do pset x%512,x\512,rgb(x%256,(x%512 xor x\512)%256,x\512%256)
add PAUSE for a 2nd line if don't want to toggle back to output screen.
SEQ was not needed and I forgot % is short form for MOD.
-
Yabasic version:
open window 512,512
for x=0 to 262144
color mod(x,256),mod(eor(mod(x,512), int(x/512)),256),mod(int(x/512),256)
dot mod(x,512),int(x/512)
next x
-
Hey without the color we almost have this:
'rotozoomer Galileo vB+.bas (SmallBasic) bpf 2015-05-16
' some big screen adjustements B+
rect 0,0,804,704,15 filled
for i=1 to 24
'orig .08, now increment in radian fractions
ANG=ANG+2*3.14159265/32
CS=COS(ANG)*ABS(SIN(ANG))*128
SS=SIN(ANG)*ABS(SIN(ANG))*128
FOR Y=-350 TO 350
FOR X=-400 TO 400
tono = abs(((X*CS-Y*SS) band (Y*CS+X*SS))/256)
if tono>255 then tono=255
pset X+402,Y+352,rgb(tono,tono,tono)
NEXT X
NEXT Y
next
-
Another version with BAND (that could be made into one line but...)
SmallBASIC 0.12.6 [B+=MGA] 2016-08-03
for x = 0 to 512 * 512
pset x mod 512, int(x / 512), rgb( (x mod 512) mod 256, x mod 512 band (x / 512) mod 256, (x / 512) mod 128 )
next
pause
-
My version in BaCon.
INCLUDE canvas.bac:WINDOW("One line",512,512):FOR x=0 TO 262144:INK(x %256,(x %512)^(x/512)%256,(x/512)%256,255):PIXEL(x %512,x/512):NEXT:WAITKEY
-
Heh guys, your submissions are really urging me to develop my own no-nonsense Canvas include. :)
I can't formulate the code as a one liner because FBSL's # preproc directives require separate lines but anyway here's my version of B+=MGA's original SmallBASIC xor-ing code that uses some VB-stylish OOP, for a change. It also accounts for operator precedence and associativity rules to get rid of redundant parentheses.
My include is yet rudimentary but I'll be enriching it based on your further examples. :)
#Include "Canvas.inc"
Dim Canvas As New CCanvas("Going VB Style", 512, 512)
With Canvas
For Dim x = 0 To 262144
.PSet(x Mod 512, x / 512, RGB(x Mod 512 Mod 256, x Mod 512 BXor x / 512 Mod 256, x / 512 Mod 128))
Next
.Refresh()
End With
-
Mike's example converted to SB SDL_gfx.
It also accounts for operator precedence and associativity rules to get rid of redundant parentheses.
No parentheses used in the Script BASIC version of the one line graphic definition. Integer division and a smart XOR (bitwise/logical) function also contribute to simplifying the definition.
(http://files.allbasic.info/ScriptBasic/gfx/mike_oneline.png)
IMPORT gfx.inc
sv = gfx::Window(512, 512, "Going SB Style")
ts = gfx::Time()
FOR x = 0 to 262144
gfx::pixelRGBA sv, x % 512, x \ 512, x % 512 % 256, x % 512 XOR x \ 512 % 256, x \ 512 % 128, 255
NEXT
te = gfx::Time()
gfx::stringColor sv, 20, 15, "Time: " & FORMAT("%.4f",(te-ts)/1000) & " Seconds." & CHR(0), 0xffffffff
gfx::Update
WHILE gfx::KeyName(1) <> "+escape"
WEND
gfx::Close
The attached is randomizing the alpha channel.
-
Mike's example converted to SB SDL_gfx.
My Canvas is persistent and the picture is resizable on completion. :)
But your code did coerce me to enrich my CCanvas class with .Time() and .Print() methods.