Author Topic: Happy Face  (Read 1283 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Happy Face
« on: May 12, 2020, 11:22:16 pm »
I made another goofy app that might cheer some people up. It shows the, "Have A Nice Day" happy face and you can use the left mouse button to relocate it and also the mouse wheel to change its size. The changing of the size isn't perfect but it's as good as I can get it. Enjoy!

Code: QB64: [Select]
  1. _TITLE "Have A Nice Day! - Use mouse left button to relocate and wheel to change size."
  2. SCREEN _NEWIMAGE(800, 600, 32)
  3. x = 400
  4. y = 300
  5. s = 100
  6. e = 20
  7. m = 65
  8. _LIMIT 1000
  9. GOSUB face:
  10.     mouseWheel = 0
  11.         mouseX = _MOUSEX
  12.         mouseY = _MOUSEY
  13.         mouseLeftButton = _MOUSEBUTTON(1)
  14.         mouseRightButton = _MOUSEBUTTON(2)
  15.         mouseMiddleButton = _MOUSEBUTTON(3)
  16.         mouseWheel = mouseWheel + _MOUSEWHEEL
  17.         IF mouseWheel > 0 THEN
  18.             s = s + 5
  19.             e = e + 1
  20.             m = m + 3
  21.             IF s > 300 THEN s = 300
  22.             IF e > 60 THEN e = 60
  23.             IF m > 185 THEN m = 185
  24.             GOSUB face:
  25.         END IF
  26.         IF mouseWheel < 0 THEN
  27.             s = s - 5
  28.             e = e - 1
  29.             m = m - 3
  30.             IF s < 20 THEN s = 20
  31.             IF e < .5 THEN e = .5
  32.             IF m < 6 THEN m = 6
  33.             GOSUB face:
  34.         END IF
  35.  
  36.         IF mouseLeftButton = -1 THEN
  37.             x = mouseX
  38.             y = mouseY
  39.             GOSUB face:
  40.         END IF
  41.     LOOP
  42.     a$ = INKEY$
  43. LOOP WHILE a$ <> CHR$(27)
  44. face:
  45. PAINT (2, 2), _RGB32(0, 172, 255)
  46. 'head
  47. FOR sz = .25 TO s STEP .25
  48.     CIRCLE (x, y), sz, _RGB32(255, 255, 127)
  49. NEXT sz
  50. 'eyes
  51. FOR sz = .25 TO e STEP .25
  52.     CIRCLE (x - (s / 2), y - (s / 2)), sz, _RGB32(0, 0, 0), , , 1.5
  53. NEXT sz
  54. FOR sz = .25 TO e STEP .25
  55.     CIRCLE (x + (s / 2), y - (s / 2)), sz, _RGB32(0, 0, 0), , , 1.5
  56. NEXT sz
  57. 'mouth
  58. FOR sz = .25 TO 5 STEP .25
  59.     CIRCLE (x, y + sz), m, _RGB32(0, 0, 0), _PI, 2 * _PI
  60. NEXT sz
  61. mouseWheel = 0
  62.  

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Happy Face
« Reply #1 on: May 13, 2020, 10:35:17 am »
Hi Ken, I wonder if you can change the smile with the mouse wheel?

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Happy Face
« Reply #2 on: May 13, 2020, 12:43:13 pm »
Yes but it would require a lot of math and a lot of trial and error. You would have to change the circle aspect and also change the start and end radians for the Circle command to where you want the mouth to start and end at. Attached to this I'll add a radians circle chart so you just plug that in to the Circle command. It both has degrees and radians, the radians are the ones with Pi. You also would have to change the aspect number to make the mouth not part of a perfect circle. The aspect number is the very last number on the Circle command. Here is where you can put everything:
CIRCLE [STEP](column, row), radius%, [drawColor%][, startRadian!, stopRadian!] [, aspect!]
Radians.gif
* Radians.gif (Filesize: 9.07 KB, Dimensions: 542x401, Views: 171)
« Last Edit: May 13, 2020, 12:49:48 pm by SierraKen »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Happy Face
« Reply #3 on: May 13, 2020, 03:57:15 pm »
Code: QB64: [Select]
  1. _TITLE "So how do you like b's" 'B+ 2019-03-06
  2. '2020-05-13 add smile
  3.  
  4. CONST smile = 1 / 3 * _PI
  5.  
  6. COLOR , 3
  7. WHILE _KEYDOWN(27) = 0 'until esc keypress
  8.     CLS
  9.     drawFace
  10.         mw = mw + _MOUSEWHEEL
  11.         IF mw > 100 THEN mw = 100
  12.         IF mw < 5 THEN mw = 5
  13.     WEND
  14.     mx = _MOUSEX: my = _MOUSEY
  15.     angle = _ATAN2(my - 240, mx - 320)
  16.     FOR i = 1 TO 8
  17.         IF i MOD 2 THEN bc = 0 ELSE bc = 14
  18.         FillCircle mx + i * 3, my + i * 3, 5, bc
  19.     NEXT
  20.     FillCircle mx - 15 + 20, my + 10, 8, 7
  21.     FillCircle mx + 8 + 20, my + 5, 8, 7
  22.     x1 = 320 - 75 + 37 / 2 * COS(angle)
  23.     y1 = 240 + 37 / 2 * SIN(angle)
  24.     x2 = 320 + 75 + 37 / 2 * COS(angle)
  25.     FillCircle x1, y1, 37 / 2, 0
  26.     FillCircle x2, y1, 37 / 2, 0
  27.     _DISPLAY 'prevent flicker
  28.     _LIMIT 60 'save CPU fan
  29.  
  30. SUB drawFace
  31.     FillCircle 320, 240, 150, 14 '<<<<<<<<<<<<<<<<< works for qb color numbers as well as rgb
  32.     FillCircle 320 - 75, 240, 37, 9
  33.     FillCircle 320 + 75, 240, 37, 9
  34.     'FillCircle 320, 240 + 80, 20, 12
  35.     arc 320, 240, 110, _PI / 2 - smile * mw / 100, _PI / 2 + smile * mw / 100, 12
  36.  
  37. 'fill circle
  38. SUB FillCircle (CX AS INTEGER, CY AS INTEGER, R AS INTEGER, C AS _UNSIGNED LONG)
  39.     DIM Radius AS INTEGER, RadiusError AS INTEGER
  40.     DIM X AS INTEGER, Y AS INTEGER
  41.  
  42.     Radius = ABS(R)
  43.     RadiusError = -Radius
  44.     X = Radius
  45.     Y = 0
  46.  
  47.     IF Radius = 0 THEN PSET (CX, CY), C: EXIT SUB
  48.  
  49.     ' Draw the middle span here so we don't draw it twice in the main loop,
  50.     ' which would be a problem with blending turned on.
  51.     LINE (CX - X, CY)-(CX + X, CY), C, BF
  52.  
  53.     WHILE X > Y
  54.         RadiusError = RadiusError + Y * 2 + 1
  55.         IF RadiusError >= 0 THEN
  56.             IF X <> Y + 1 THEN
  57.                 LINE (CX - Y, CY - X)-(CX + Y, CY - X), C, BF
  58.                 LINE (CX - Y, CY + X)-(CX + Y, CY + X), C, BF
  59.             END IF
  60.             X = X - 1
  61.             RadiusError = RadiusError - X * 2
  62.         END IF
  63.         Y = Y + 1
  64.         LINE (CX - X, CY - Y)-(CX + X, CY - Y), C, BF
  65.         LINE (CX - X, CY + Y)-(CX + X, CY + Y), C, BF
  66.     WEND
  67.  
  68.  
  69. 'use radians
  70. SUB arc (x, y, r, raStart, raStop, c AS _UNSIGNED LONG)
  71.     DIM al, a
  72.     'x, y origin, r = radius, c = color
  73.  
  74.     'raStart is first angle clockwise from due East = 0 degrees
  75.     ' arc will start drawing there and clockwise until raStop angle reached
  76.  
  77.     IF raStop < raStart THEN
  78.         arc x, y, r, raStart, _PI(2), c
  79.         arc x, y, r, 0, raStop, c
  80.     ELSE
  81.         ' modified to easier way suggested by Steve
  82.         'Why was the line method not good? I forgot.
  83.         al = _PI * r * r * (raStop - raStart) / _PI(2)
  84.         FOR a = raStart TO raStop STEP 1 / al
  85.             CIRCLE (x + r * COS(a), y + r * SIN(a)), 3, c '<<< modify for smile
  86.         NEXT
  87.     END IF
  88.  
  89.  
  90.  

 
How do you like b's.PNG

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Happy Face
« Reply #4 on: May 13, 2020, 04:22:18 pm »
LOL bplus, totally cool! Way beyond me in math! :)

Offline Ashish

  • Forum Resident
  • Posts: 630
  • Never Give Up!
    • View Profile
Re: Happy Face
« Reply #5 on: May 14, 2020, 01:13:25 am »
Nice work SierraKen & Bplus. Why the face is not wearing mask? :D
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 bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Happy Face
« Reply #6 on: May 14, 2020, 12:06:38 pm »
Nice work SierraKen & Bplus. Why the face is not wearing mask? :D

LOL that would save us all the math :)