Author Topic: Simple Challenge Pattern Derivatives  (Read 4011 times)

0 Members and 1 Guest are viewing this topic.

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Simple Challenge Pattern Derivatives
« on: June 29, 2019, 01:01:19 pm »
Playing around with the code which I wrote for bplus's challenge here (https://www.qb64.org/forum/index.php?topic=1467.0 ), I decided to play around with my numbers and see what other simple patterns I could generate, which led me to the little brain seizure inducing code below:

Code: QB64: [Select]
  1. DEFLNG A-Z
  2. SCREEN _NEWIMAGE(640, 480, 32)
  3. DIM C(-1 TO 0): C(-1) = &HFFFF0000: C(0) = &HFF0000FF
  4.  
  5.     variance = variance + 1
  6.     IF variance > 640 THEN variance = 0
  7.     CLS
  8.  
  9.     FOR i = 0 TO 8
  10.         k = NOT k
  11.         x = 25 * SIN(_D2R(30 * i)) + variance
  12.         y = 25 * COS(_D2R(30 * i)) + 50
  13.         CIRCLE (x, y), 25, C(k)
  14.         PAINT (x, y), C(k)
  15.     NEXT
  16.  
  17.     h = _NEWIMAGE(50, 100, 32)
  18.     _PUTIMAGE , 0, h, (variance, 0)-(100, 100)
  19.     f = _NEWIMAGE(100, 100, 32)
  20.     _DEST f
  21.     D h, 50, 0, 0, 1: D h, 0, 0, 180, 4
  22.     _DEST 0
  23.  
  24.     CLS
  25.     a = 0
  26.     DO
  27.         a = a + 3
  28.         FOR y = -50 TO 530 STEP 82
  29.             Z = NOT Z
  30.             dir = 1: IF Z THEN dir = -1
  31.             FOR x = -50 TO 690 STEP 100
  32.                 D f, x + Z * 50, y, dir * a, 0
  33.         NEXT x, y
  34.     LOOP UNTIL a >= 180
  35.  
  36.  
  37. SUB D (Im, x, y, a, m)
  38.     DIM px(3), py(3)
  39.     w = _WIDTH(Im) - 1: h = 99
  40.     SELECT CASE m
  41.         CASE 0: px(0) = -w \ 2: py(0) = -h \ 2: px(3) = w \ 2: py(3) = -h \ 2: px(1) = -w \ 2: py(1) = h \ 2: px(2) = w \ 2: py(2) = h \ 2
  42.         CASE 1: px(0) = 0: py(0) = 0: px(3) = w: py(3) = 0: px(1) = 0: py(1) = h: px(2) = w: py(2) = h
  43.         CASE 4: px(0) = -w: py(0) = -h: px(3) = 0: py(3) = -h: px(1) = -w: py(1) = 0: px(2) = 0: py(2) = 0
  44.     END SELECT
  45.     s! = SIN(_D2R(a)): c! = COS(_D2R(a))
  46.     FOR i = 0 TO 3
  47.         x2 = (px(i) * c! + s! * py(i)) + x: y2 = (py(i) * c! - px(i) * s!) + y
  48.         px(i) = x2: py(i) = y2
  49.     NEXT
  50.     _MAPTRIANGLE (0, 0)-(0, h)-(w, h), Im TO(px(0), py(0))-(px(1), py(1))-(px(2), py(2))
  51.     _MAPTRIANGLE (0, 0)-(w, 0)-(w, h), Im TO(px(0), py(0))-(px(3), py(3))-(px(2), py(2))
  52.  
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline TempodiBasic

  • Forum Resident
  • Posts: 1792
    • View Profile
Re: Simple Challenge Pattern Derivatives
« Reply #1 on: June 29, 2019, 02:12:42 pm »
Wow
this challenge is sure out of my ability!

I'm at window waiting what will be post.
In the while I can say thanks you have remembered me the Degree/Radiant functions for SIN and COS that eat only radiant!

Good Coding
Programming isn't difficult, only it's  consuming time and coffee

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Simple Challenge Pattern Derivatives
« Reply #2 on: June 30, 2019, 01:18:23 am »
Cool! Looks like optical illusion.
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Simple Challenge Pattern Derivatives
« Reply #3 on: June 30, 2019, 02:41:07 am »
Hi. I created a new Pattern. :)
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(600, 600, 32)
  2.     _LIMIT 30
  3. SUB drawPattern (a, s, c AS _BYTE, N)
  4.     IF s < 0.001 THEN EXIT SUB
  5.     IF c = 1 THEN _glColor3f 1, 1, 1 ELSE _glColor3f 0, 0, 0
  6.     _glBegin _GL_POLYGON
  7.     FOR i = a TO _PI(2) + a STEP _PI(2 / N)
  8.         _glVertex2f s * COS(i), s * SIN(i)
  9.     NEXT
  10.     _glEnd
  11.     IF c = 1 THEN drawPattern a + 0.1, s - 0.01, 0, N ELSE drawPattern a + 0.1, s - 0.01, 1, N
  12. SUB _GL ()
  13.     STATIC c
  14.     drawPattern c, 1.5, 1, 8
  15.     c = c + 0.01
  16.  
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Simple Challenge Pattern Derivatives
« Reply #4 on: June 30, 2019, 02:45:24 am »
Okay. So, here is a dancing color MOD.
Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(600, 600, 32)
  2.     _LIMIT 30
  3. SUB drawPattern (a, s, c AS _BYTE, N)
  4.     IF s < 0.001 THEN EXIT SUB
  5.     IF c = 1 THEN _glColor3f 1, 1, 1 ELSE _glColor3f RND, RND, RND
  6.     _glBegin _GL_POLYGON
  7.     FOR i = a TO _PI(2) + a STEP _PI(2 / N)
  8.         _glVertex2f s * COS(i), s * SIN(i)
  9.     NEXT
  10.     _glEnd
  11.     IF c = 1 THEN drawPattern a + 0.1, s - 0.01, 0, N ELSE drawPattern a + 0.1, s - 0.01, 1, N
  12. SUB _GL ()
  13.     STATIC c
  14.     drawPattern c, 2, 1, 8
  15.     c = c + 0.01
  16.  
  17.  
  18.  
if (Me.success) {Me.improve()} else {Me.tryAgain()}


My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

Offline johnno56

  • Forum Resident
  • Posts: 1270
  • Live long and prosper.
    • View Profile
Re: Simple Challenge Pattern Derivatives
« Reply #5 on: June 30, 2019, 11:29:49 pm »
Wow! I think ALL Optometrists should have THIS demo as part of the list of eye tests... lol
Very cool... a bit trippy... but cool none the less...
Logic is the beginning of wisdom.