DASH String Art

Post Reply
User avatar
rbytes
Posts: 1798
Joined: Sun May 31, 2015 12:11 am
My devices: iPhone X
iPad 4
Dell Inspiron laptop
CHUWI Plus 10 convertible Windows/Android tablet
Location: Calgary, Canada
Flag: Canada
Contact:

DASH String Art

Post by rbytes » Mon Oct 29, 2018 3:24 pm

I wasn't sure that dashed colored lines could be drawn fast enough to make interesting string art. It turns out that they can.
The effect is a lot like plaid at certain segment sizes.

Code: Select all

/*
DASH String Art by rbytes
October, 2018
String art drawn with rainbow-colored
lines made with the DRAW DASH command.
The field shows the length in
points of each colored line segment. 
This length starts at 1 and grows by 1 with
each loop iteration until it reaches 700 points.
By then the segments are so large that the drawing is
reduced to a single color. Next, the segment length
shrinks by one point in each loop iteration until
the segment length is again 1. 

The lower field shows the elapsed time in
seconds. An entire grow and shrink cycle
takes 248 seconds (4 minutes and 8 seconds). 
Then this cycle repeats forever until the program
is ended. Press and hold anywhere on screen to end.

Notice the drawing speed of Smart Basic, even when each line updated on screen is actually 8 dashed lines. It takes only a fraction of a second to redraw the screen! I had to add a 1-second delay at the end of each loop to better illustrate how the lines are changing.
*/
set toolbar off
get screen size sw,sh
graphics
graphics clear 0,0,0
draw alpha 1
ds=.5   ' single pixel width (although anti-aliasing will increase that a bit)
inc=1
draw size ds
cshift=0
mult=1
mult2=mult*7
timer=TIME()
tmmy=0
draw color 0,1,1
draw font size 22
draw font name "Arial"
FIELD "1" TEXT " "&mult AT sw*.47,sh*.42 SIZE 50,40 RO
FIELD "2" TEXT " "&tmmy AT sw*.466,sh*.62 SIZE 60,40 RO
draw text "SEGMENT LENGTH" at sw*.41,sh*.36
draw text "ELAPSED TIME" at sw*.425,sh*.56

loop:
for phs=0 to 7
  DRAW DASH mult,mult2 PHASE mult*phs
  pal(cshift+phs/8,1,1,1,.5)
  draw color pal.r,pal.g,pal.b
  gosub liner
next phs

' touch (hold) to end

GET TOUCH 0 AS tx,ty
IF tx<>-1 THEN
  IF laun$="desktop" THEN
    IF FILE_EXISTS("/launch") THEN
      RUN "/-Launch.sb"
    ELSE
      EXIT
    ENDIF
  ENDIF
  END
ENDIF

mult+=inc
mult2=mult*7
if mult>700 then inc=-1
if mult<2 then inc=1
tmmy = INT(TIME()-timer)
FIELD "1" TEXT " "&mult
FIELD "2" TEXT " "&tmmy
pause 1
goto loop
end

liner:
for t=0 to sh step 10
  draw line 0,sh-t to t,0
  draw line 0,t to t,sh
  draw line sw,t to sw-t,sh
  draw line sw,sh-t to sw-t,0
next t
return


'r' ===== Combined Palette function based on Henko and Dutchman converters, by rbytes
DEF Pal(Tint,SATURATION,Brighten,Intensity,Gamma)
' ---- adjust parameter-values between zero and 1.
h=tint*360
tint%=1
Sat=ABS(SATURATION)
IF Sat>1 THEN Sat%=1
Intensity=ABS(Intensity) 
IF Intensity>1 THEN Intensity%=1
Brighten=ABS(Brighten)
IF Brighten>1 THEN Brighten%=1
r=0 ! g=0 ! b=0 ! h%=360
IF h<120 OR h>240 THEN r=palsub(ABS(h-360*FLOOR(h/240)),Gamma)
IF h<240 THEN g=palsub(ABS(h-120),Gamma)
IF h>120 THEN b=palsub(ABS(h-240),Gamma)
Sat: ' with constant luminance
' ---- apply Saturation and Brighten
IF Sat<1 THEN
  Y=0.3*R+0.59*G+0.11*B
  U=B-Y ! U*=sat
  V=R-Y ! v*=sat
  W=G-Y ! w*=sat
  R=Y+V ! G=Y+W ! B=Y+U
  IF Brighten<>0 THEN
    Ysup=1-MAX(MAX(R,G),B)' max white to add
    Ysup*=Brighten
    R+=Ysup ! G+=Ysup ! B+=Ysup
  ENDIF
ENDIF
' ---- apply Intensity
IF Intensity<1 THEN
  R*=Intensity
  G*=Intensity
  B*=Intensity
ENDIF
Y=0.3*R+0.59*G+0.11*B
END DEF ' Pal
DEF palsub(e,Gamma)
f=Gamma   ' 0<=f<=1 better balance between primary and secondary colors
IF e<60 THEN c=1 ELSE ! x=(120-e)/60 ! c=x*(1+f-f*x) ! END IF
RETURN c
END DEF
Attachments
370D7DB2-AEBD-4866-8701-06C4F0E17F60.png
370D7DB2-AEBD-4866-8701-06C4F0E17F60.png (1.92 MiB) Viewed 1314 times
####### Living the colorful life #######

Post Reply