Author Topic: Accidental Fractal  (Read 5110 times)

0 Members and 1 Guest are viewing this topic.

Offline romichess

  • Forum Regular
  • Posts: 145
    • View Profile
Accidental Fractal
« on: January 01, 2020, 04:57:13 am »
I'm not going to say what I was really trying to do, LOL. But what I accidentally ended up with is a fractal! :)

Code: QB64: [Select]
  1.  
  2. screenw = _DESKTOPWIDTH
  3. screenh = _DESKTOPHEIGHT
  4. SCREEN _NEWIMAGE(screenw, screenh, 256)
  5.  
  6.  
  7. repeat = -1
  8.  
  9. WHILE repeat
  10.  
  11.     FOR i = 0 TO 32767
  12.         FOR j = 0 TO 32767
  13.             FOR k = 0 TO 32767
  14.                 x = (i OR j OR k) / 32768 * screenw
  15.                 y = (i OR k) / 32768 * screenh
  16.                 PSET (x, y), 15
  17.                 x = screenw - x
  18.                 y = screenh - y
  19.                 PSET (x, y), 15
  20.                 ch = INKEY$
  21.                 IF ch = CHR$(27) THEN SYSTEM
  22.             NEXT
  23.         NEXT
  24.     NEXT
  25.  
  26.  
My name is Michael, but you can call me Mike :)

Offline romichess

  • Forum Regular
  • Posts: 145
    • View Profile
Re: Accidental Fractal
« Reply #1 on: January 01, 2020, 05:35:01 am »
This one with colors is more interesting.

Code: QB64: [Select]
  1.  
  2. screenw = _DESKTOPWIDTH
  3. screenh = _DESKTOPHEIGHT
  4. SCREEN _NEWIMAGE(screenw, screenh, 256)
  5.  
  6.  
  7. repeat = -1
  8.  
  9. WHILE repeat
  10.  
  11.     FOR i = 0 TO 32767
  12.         FOR j = 0 TO 32767
  13.             FOR k = 0 TO 32767
  14.                 x = (i OR j OR k) / 32768 * screenw
  15.                 y = (i OR k) / 32768 * screenh
  16.                 c = ((i OR j OR k) / 32768 * 6) + 1
  17.                 PSET (x, y), c
  18.                 x = screenw - x
  19.                 y = screenh - y
  20.                 c = ((i XOR j XOR k) / 32768 * 6) + 1
  21.                 PSET (x, y), c
  22.                 ch = INKEY$
  23.                 IF ch = CHR$(27) THEN SYSTEM
  24.             NEXT
  25.         NEXT
  26.     NEXT
  27.  
  28.  
  29.  
My name is Michael, but you can call me Mike :)

Offline romichess

  • Forum Regular
  • Posts: 145
    • View Profile
Re: Accidental Fractal
« Reply #2 on: January 01, 2020, 05:57:29 am »
This is more like what I was trying to do. But, not really exactly like this either.
Code: QB64: [Select]
  1.  
  2. screenw = _DESKTOPWIDTH
  3. screenh = _DESKTOPHEIGHT
  4. SCREEN _NEWIMAGE(screenw, screenh, 256)
  5.  
  6.  
  7. repeat = -1
  8.  
  9. WHILE repeat
  10.  
  11.     FOR i = 0 TO 32767
  12.         FOR j = 0 TO 32767
  13.             c = ((i XOR j) / 32768 * 7) + 1
  14.             FOR k = 0 TO 32767
  15.                 x = (i XOR j XOR k) / 32768 * screenw
  16.                 y = (i XOR k) / 32768 * screenh
  17.                 PSET (x, y), c
  18.                 x = screenw - x
  19.                 y = screenh - y
  20.                 PSET (x, y), c
  21.                 ch = INKEY$
  22.                 IF ch = CHR$(27) THEN SYSTEM
  23.             NEXT
  24.         NEXT
  25.     NEXT
  26.  
  27.  
  28.  
My name is Michael, but you can call me Mike :)

Offline OldMoses

  • Seasoned Forum Regular
  • Posts: 469
    • View Profile
Re: Accidental Fractal
« Reply #3 on: January 02, 2020, 05:36:52 am »
I'm always amazed at the things that lie hidden in math and logical operators.

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Accidental Fractal
« Reply #4 on: January 02, 2020, 06:03:56 am »
I am curious as to which version of  QB64 was used to make the fractal? Reason: Version 1.3, on 'my' Linux machine, produces a single multi-coloured diagonal line that begins in the top left of the screen and ends in the bottom right. All I did was 'copy and paste' and F5. If it's just me, then by all means, ignore the ravings of this user and pretend that I didn't post... lol

J
Logic is the beginning of wisdom.

Offline romichess

  • Forum Regular
  • Posts: 145
    • View Profile
Re: Accidental Fractal
« Reply #5 on: January 02, 2020, 12:22:34 pm »
I am curious as to which version of  QB64 was used to make the fractal? Reason: Version 1.3, on 'my' Linux machine, produces a single multi-coloured diagonal line that begins in the top left of the screen and ends in the bottom right. All I did was 'copy and paste' and F5. If it's just me, then by all means, ignore the ravings of this user and pretend that I didn't post... lol

J

I'm using ver 1.3. I checked all three examples, just now. It starts off as a diagonal line, but it builds out from there to fill the screen. It is not very fast. It takes a few minutes to complete. My cpu is an i7-3930k overclocked to 4.2 GHz.
My name is Michael, but you can call me Mike :)

Offline Richard Frost

  • Seasoned Forum Regular
  • Posts: 316
  • Needle nardle noo. - Peter Sellers
    • View Profile
Re: Accidental Fractal
« Reply #6 on: January 02, 2020, 04:16:08 pm »
Code: QB64: [Select]
  1. _TITLE "More accidental fracals"
  2. DEFINT A-Z
  3. x1 = 126: y1 = 80: x2 = 302: y2 = 160: z = 220
  4. DIM gbuff(12000)
  5.     a = (a + 3) MOD 360: c = -(a > 180)
  6.     y = 120 - 40 * COS(a * ATN(1) / 45)
  7.     FOR i = 0 TO 2
  8.         j = i * 120: k = i * 4 + c * 2 + 1
  9.         c1 = VAL(MID$(" 7 1 8111012", k, 2))
  10.         c2 = VAL(MID$(" 612 5 214 9", k, 2))
  11.         PSET (x2, y + j), c1
  12.         PSET (x2 + z, y + j), c2
  13.         GET (x1 + VAL(MID$("122", i + 1, 1)), y1 + j)-(x2, y2 + j), gbuff()
  14.         PUT (x1, y1 + j), gbuff()
  15.         GET (z + x1 + VAL(MID$("122", i + 1, 1)), y1 + j)-(z + x2 + 1, y2 + j), gbuff()
  16.         PUT (z + x1, y1 + j), gbuff()
  17.     NEXT i
It works better if you plug it in.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Accidental Fractal
« Reply #7 on: January 02, 2020, 04:56:02 pm »
and another accidental find:
Code: QB64: [Select]
  1. _TITLE "Sierpinski flies a kite by bplus 2017-10-16"
  2. ' after playing with Ashish Kite Fractal
  3.  
  4. SCREEN _NEWIMAGE(1200, 700, 32)
  5. _SCREENMOVE 100, 20
  6.     CLS
  7.     drawKite 600, 540, 200, a
  8.     _DISPLAY
  9.     _LIMIT 20
  10.     a = a + _PI(2 / 360)
  11. SUB drawKite (xx, yy, s, a)
  12.     x = xx: y = yy
  13.     x2 = x + 3 * s * COS(_PI(1 / 2) - a / 2): y2 = y + 3 * s * SIN(_PI(1 / 2) - a / 2)
  14.     x3 = x + 3 * s * COS(_PI(1 / 2) + a / 2): y3 = y + 3 * s * SIN(_PI(1 / 2) + a / 2)
  15.     SierLineTri x, y, x2, y2, x3, y3, 0
  16.     'LINE (x, y)-(x + s * COS(_PI(2) - a / 2), (y - s) + s * SIN(_PI(2) - a / 2))
  17.     'LINE (x, y)-(x + s * COS(_PI + a / 2), (y - s) + s * SIN(_PI + a / 2))
  18.  
  19.     IF s > 10 THEN
  20.         drawKite x + 1 * s * COS(_PI(2) - a), (y - s) + 1 * s * SIN(_PI(2) - a), s / 2, a
  21.         drawKite x + 1 * s * COS(_PI + a), (y - s) + 1 * s * SIN(_PI + a), s / 2, a
  22.     END IF
  23. SUB SierLineTri (x1, y1, x2, y2, x3, y3, depth)
  24.     IF depth = 0 THEN 'draw out triangle if level 0
  25.         LINE (x1, y1)-(x2, y2)
  26.         LINE (x2, y2)-(x3, y3)
  27.         LINE (x1, y1)-(x3, y3)
  28.     END IF
  29.     'find midpoints
  30.     IF x2 < x1 THEN mx1 = (x1 - x2) / 2 + x2 ELSE mx1 = (x2 - x1) / 2 + x1
  31.     IF y2 < y1 THEN my1 = (y1 - y2) / 2 + y2 ELSE my1 = (y2 - y1) / 2 + y1
  32.     IF x3 < x2 THEN mx2 = (x2 - x3) / 2 + x3 ELSE mx2 = (x3 - x2) / 2 + x2
  33.     IF y3 < y2 THEN my2 = (y2 - y3) / 2 + y3 ELSE my2 = (y3 - y2) / 2 + y2
  34.     IF x3 < x1 THEN mx3 = (x1 - x3) / 2 + x3 ELSE mx3 = (x3 - x1) / 2 + x1
  35.     IF y3 < y1 THEN my3 = (y1 - y3) / 2 + y3 ELSE my3 = (y3 - y1) / 2 + y1
  36.  
  37.     LINE (mx1, my1)-(mx2, my2) '  'draw all inner triangles
  38.     LINE (mx2, my2)-(mx3, my3)
  39.     LINE (mx1, my1)-(mx3, my3)
  40.  
  41.     IF depth < 4 THEN 'not done so call me again
  42.         SierLineTri x1, y1, mx1, my1, mx3, my3, depth + 1
  43.         SierLineTri x2, y2, mx1, my1, mx2, my2, depth + 1
  44.         SierLineTri x3, y3, mx3, my3, mx2, my2, depth + 1
  45.     END IF
  46.  
  47.  

Offline romichess

  • Forum Regular
  • Posts: 145
    • View Profile
Re: Accidental Fractal
« Reply #8 on: January 02, 2020, 05:17:30 pm »
Guy's were they really accidental? What were you trying to have revolve or fly? I was just trying to cover every pixel of the screen in an unusual pattern as the third example does.
My name is Michael, but you can call me Mike :)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Accidental Fractal
« Reply #9 on: January 02, 2020, 07:19:25 pm »
Guy's were they really accidental? What were you trying to have revolve or fly? I was just trying to cover every pixel of the screen in an unusual pattern as the third example does.

In my case, I just was experimenting replacing a triangle with a Sierpinski in Ashish Kite Fractal. I had no idea it would dance around like it did. Of course I beefed up the numbers to see it dance better once I saw that there was a show to be seen. :)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Accidental Fractal
« Reply #10 on: January 02, 2020, 10:11:30 pm »
Code: QB64: [Select]
  1. _TITLE "Birth of Sierpinski Flies a Kite" 'b+ 2020-01-02
  2. SCREEN _NEWIMAGE(800, 600, 32)
  3. _SCREENMOVE 300, 50
  4. drawKite 400, 500, 140, .5 'here was Ashish fractal, now put a 2 after drawKite
  5. PRINT "Original Kite Fractal from Ashish, press any..."
  6. drawKite2 400, 500, 140, .5
  7. PRINT "Sub in Sierpinski, press any..."
  8. drawKite2 400, 500, 140, -.5
  9. PRINT "Mess with the a variable, press any..."
  10. FOR i = -1 TO 1 STEP .1
  11.     CLS
  12.     drawKite2 400, 500, 140, i
  13.     PRINT "Run a continuous change on variable a, press any..."
  14.     _LIMIT 15
  15. FOR i = _PI(-2) TO _PI(2) STEP .1
  16.     CLS
  17.     drawKite2 400, 500, 140, i
  18.     PRINT "Oh more continuous change on variable a, press any..."
  19.     _LIMIT 15
  20. PRINT "WOW! what was that!?"
  21. PRINT "The Birth of Sierpinski Flies a Kite."
  22. PRINT "Actually any symmetric object might dance around like that!"
  23. PRINT "Maybe you have one to try?"
  24.  
  25. SUB drawKite (x, y, s, a)
  26.     LINE (x, y)-(x + s * COS(_PI(2) - a), (y - s) + s * SIN(_PI(2) - a))
  27.     LINE (x, y)-(x + s * COS(_PI + a), (y - s) + s * SIN(_PI + a))
  28.     IF s > 1 THEN
  29.         drawKite x + s * COS(_PI(2) - a), (y - s) + s * SIN(_PI(2) - a), s / 2, a
  30.         drawKite x + s * COS(_PI + a), (y - s) + s * SIN(_PI + a), s / 2, a
  31.     END IF
  32.  
  33. SUB drawKite2 (xx, yy, s, a)
  34.     x = xx: y = yy
  35.     x2 = x + 3 * s * COS(_PI(1 / 2) - a / 2): y2 = y + 3 * s * SIN(_PI(1 / 2) - a / 2)
  36.     x3 = x + 3 * s * COS(_PI(1 / 2) + a / 2): y3 = y + 3 * s * SIN(_PI(1 / 2) + a / 2)
  37.     SierLineTri x, y, x2, y2, x3, y3, 0
  38.     IF s > 10 THEN
  39.         drawKite2 x + 1 * s * COS(_PI(2) - a), (y - s) + 1 * s * SIN(_PI(2) - a), s / 2, a
  40.         drawKite2 x + 1 * s * COS(_PI + a), (y - s) + 1 * s * SIN(_PI + a), s / 2, a
  41.     END IF
  42.  
  43.  
  44. SUB SierLineTri (x1, y1, x2, y2, x3, y3, depth)
  45.     IF depth = 0 THEN 'draw out triangle if level 0
  46.         LINE (x1, y1)-(x2, y2)
  47.         LINE (x2, y2)-(x3, y3)
  48.         LINE (x1, y1)-(x3, y3)
  49.     END IF
  50.     'find midpoints
  51.     IF x2 < x1 THEN mx1 = (x1 - x2) / 2 + x2 ELSE mx1 = (x2 - x1) / 2 + x1
  52.     IF y2 < y1 THEN my1 = (y1 - y2) / 2 + y2 ELSE my1 = (y2 - y1) / 2 + y1
  53.     IF x3 < x2 THEN mx2 = (x2 - x3) / 2 + x3 ELSE mx2 = (x3 - x2) / 2 + x2
  54.     IF y3 < y2 THEN my2 = (y2 - y3) / 2 + y3 ELSE my2 = (y3 - y2) / 2 + y2
  55.     IF x3 < x1 THEN mx3 = (x1 - x3) / 2 + x3 ELSE mx3 = (x3 - x1) / 2 + x1
  56.     IF y3 < y1 THEN my3 = (y1 - y3) / 2 + y3 ELSE my3 = (y3 - y1) / 2 + y1
  57.     LINE (mx1, my1)-(mx2, my2) '  'draw all inner triangles
  58.     LINE (mx2, my2)-(mx3, my3)
  59.     LINE (mx1, my1)-(mx3, my3)
  60.     IF depth < 4 THEN 'not done so call me again
  61.         SierLineTri x1, y1, mx1, my1, mx3, my3, depth + 1
  62.         SierLineTri x2, y2, mx1, my1, mx2, my2, depth + 1
  63.         SierLineTri x3, y3, mx3, my3, mx2, my2, depth + 1
  64.     END IF
  65.  
  66.