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