Author Topic: One liner graphic  (Read 3856 times)

B+

  • Guest
One liner graphic
« on: July 31, 2016, 07:01:03 PM »
Code: [Select]
'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)

jj2007

  • Guest
Re: One liner graphic
« Reply #1 on: August 01, 2016, 07:05:59 AM »
Thumbs up!

ZXDunny

  • Guest
Re: One liner graphic
« Reply #2 on: August 01, 2016, 09:03:29 AM »
One liner, you say?

I wonder what I can come up with.... :D

B+

  • Guest
Re: One liner graphic
« Reply #3 on: August 01, 2016, 12:59:24 PM »
hmm... maybe I should have said one statement?

It has been pointed out to me there is a much shorter version (Thanks jsalai!)
Code: [Select]
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.

Galileo

  • Guest
Re: One liner graphic
« Reply #4 on: August 01, 2016, 04:03:22 PM »
Yabasic version:

Code: [Select]
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

B+

  • Guest
Re: One liner graphic
« Reply #5 on: August 01, 2016, 07:22:56 PM »
Hey without the color we almost have this:
Code: [Select]
'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
« Last Edit: August 01, 2016, 07:26:50 PM by B+ »

B+

  • Guest
Re: One liner graphic
« Reply #6 on: August 03, 2016, 02:29:38 PM »
Another version with BAND (that could be made into one line but...)
Code: [Select]
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

Peter

  • Guest
Re: One liner graphic
« Reply #7 on: September 13, 2016, 05:42:29 PM »
My version in BaCon.

Code: [Select]
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


Mike Lobanovsky

  • Guest
Re: One liner graphic
« Reply #8 on: September 14, 2016, 12:17:29 AM »
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. :)

Code: [Select]
#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

ScriptBasic

  • Guest
Re: One liner graphic
« Reply #9 on: September 14, 2016, 05:57:19 AM »
Mike's example converted to SB SDL_gfx.

Quote
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.



Code: [Select]
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.

« Last Edit: September 16, 2016, 04:55:07 AM by John »

Mike Lobanovsky

  • Guest
Re: One liner graphic
« Reply #10 on: September 14, 2016, 12:04:57 PM »
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.