String Art

Post Reply
User avatar
rbytes
Posts: 1808
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:

String Art

Post by rbytes » Thu Oct 25, 2018 6:34 pm

Remember when string art was popular? I created a couple of large pieces to decorate a bachelor pad many years ago. All you needed was a sheet of plywood, some felt or burlap to stretch over it, a big bag of nails and lots of colored string.

The computer can do a pretty good simulation of string art. This is a start. I may develop it into a program with multiple options, but for now it is just an amusement. For observant programmers - yes, I know I could use ON .. GOTO, but that doesn't save any code, since each draw line then needs extra code to skip over the lines that follow.

The biggest cheat is my rainbow-colored string. String like this probably doesn't exist, but I like the effect. (I have seen rainbow-colored fishing line). ;)

You can experiment with draw size, step size and by commenting out styles. If you come up with any new drawing patterns, please add them and share with us.

After the 7 styles have finished drawing, tap to end the program.

Code: Select all

/*
String Art by rbytes
October, 2018
Simple math draws
realistic string art
*/
set toolbar off
get screen size sw,sh
graphics
graphics clear 0,0,0
draw size 1
style=10
draw color 0,0,0
draw line 0,0 to 0,sh
draw line 0,sh to sw,sh
loop:
for t=-100 to sw step 10
  pal(cshift+t/sh,1,1,1,.5)
  draw color pal.r,pal.g,pal.b
  if style=10 then draw line sw-t,0 to 0, t
  if style=20 then draw line sw,sh to sw-t,0
  if style=30 then draw line t,sh to t,0
  if style=40 then draw line 0,t to t,sh-t
  if style=50 then draw line sw,sh-t to t,t
  if style=60 then draw line sw-t,0 to sh,t
  if style=70 then draw line sw-t,0 to sh, t
  pause .01
next t
style+=10
if style<=60 then loop

' 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

wait:SLOWDOWN!GET TOUCH 0 AS tx,ty!IF tx=-1 THEN wait

'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
53FBBEBD-55A6-4F33-BC18-383511EDB1F8.png
53FBBEBD-55A6-4F33-BC18-383511EDB1F8.png (4.28 MiB) Viewed 896 times
Last edited by rbytes on Fri Oct 26, 2018 2:40 pm, edited 2 times in total.
####### Living the colorful life #######

User avatar
rbytes
Posts: 1808
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:

String Art Frame

Post by rbytes » Fri Oct 26, 2018 2:46 pm

Here is another string art concept. It creates a frame around an image of your choice. I have supplied an image to use if you don't have a suitable one.

The frame updates every few seconds with a slight shift of the color scheme. To end the program, press and hold. It will end after the next frame update is complete.

The parabolic curves are an illusion generated by the patterns of lines.

Code: Select all

/*
String Art Frame by rbytes
October, 2018
String art frame for an image
*/
set toolbar off
get screen size sw,sh
graphics
draw image "tamaracks.jpg" at 0,0 scale .5
draw size 1
draw alpha .5

loop:
for t=0 to sh step 10
  pal(cshift+t/sh,1,1,1,.5)
  draw color pal.r,pal.g,pal.b
  draw line 0,t to t,sh
  draw line sw,t to sw-t,sh
  draw line t,0 to 0,sh-t
  draw line sw,sh-t to sw-t,0
  pause .01
next t

' 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

cshift+=.05
pause 1
goto loop
pause 5


'r' ===== Palette function combining 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
06CE1368-1951-4E37-A281-28F8C173103D.png
06CE1368-1951-4E37-A281-28F8C173103D.png (7.19 MiB) Viewed 876 times
tamaracks.jpg
tamaracks.jpg (4.09 MiB) Viewed 876 times
####### Living the colorful life #######

User avatar
Mr. Kibernetik
Site Admin
Posts: 4415
Joined: Mon Nov 19, 2012 10:16 pm
My devices: iPad, iPhone, MacBook
Location: Russia
Flag: Russia

Re: String Art

Post by Mr. Kibernetik » Fri Oct 26, 2018 7:31 pm

Very nice colors!

User avatar
rbytes
Posts: 1808
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:

Re: String Art

Post by rbytes » Sat Oct 27, 2018 4:40 am

Thanks. :)
####### Living the colorful life #######

Post Reply