Making a mascot of Puppy Linux using PureBasic built-in vector commands without using external images in program

For discussions about programming, and for programming questions and advice


Moderator: Forum moderators

Post Reply
User avatar
Grey
Posts: 1984
Joined: Wed Jul 22, 2020 12:33 am
Location: Russia
Has thanked: 75 times
Been thanked: 355 times

Making a mascot of Puppy Linux using PureBasic built-in vector commands without using external images in program

Post by Grey »

It's snowing outside today. We need to do something relaxing.
Objective: create a Puppy Linux mascot using PureBasic built-in vector commands without using external images such as .jpg or .png in the program.
Here is the resulting executable file, compiled in PureBasic environment and Fossapup:

Puppy-mascot.tar
(160 KiB) Downloaded 34 times

Just unpack and run.

puppy_purebasic.png
puppy_purebasic.png (41.81 KiB) Viewed 342 times

And here is the resulting source code:

Code: Select all

  If OpenWindow(0, 0, 0, 256, 284, "Puppy Linux vector mascot :-)", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
     CanvasGadget(0, 0, 28, 256, 256)
    
    If StartVectorDrawing(CanvasVectorOutput(0))
     
      ButtonGadget(1, 0, 0, 100, 20, "Woof!")
      GadgetToolTip(1,"Left button")
      ButtonGadget(2, 156, 0, 100, 20, "Woof!")
      GadgetToolTip(2,"Right button")
      
      VectorSourceColor(RGBA(33, 143, 199, 255))
      FillVectorOutput()
      
      AddPathBox(0, 0, 256, 256)
      VectorSourceColor(RGBA(255, 0, 0, 255))
      StrokePath(20)
      
      AddPathSegments("M 109.5 251.445 C 97.8714 249.303 89.9064 246.586 77.5 240.528 C 53.4412 228.779 38.1942 215.05 26.1348 194.275 C 20.6741 184.868 14.02 168.178 10.4762 155 L 7.65255 144.5 L 7.57627 94.5 C 7.51502 54.3484 7.77671 43.5469 8.90483 39.6612 C 12.091 28.6868 26.265 18.5373 44.9122 13.8777 C 51.9372 12.1222 54.9053 11.8897 62.9122 12.4673 C 78.9749 13.626 79.9147 13.5169 90.5051 9.26235 C 102.745 4.34504 107.845 3.22323 121.703 2.39921 C 129.542 1.93313 135.685 2.22177 144.123 3.4527 C 153.357 4.79964 156.941 4.92738 161.557 4.07409 C 168.939 2.70945 207.413 2.68581 216 4.04063 C 219.575 4.60467 225.3 5.98381 228.722 7.10538 C 240.861 11.0835 249.737 22.5249 250.726 35.4686 C 251.269 42.5707 247.949 60.3007 244.874 66.7167 L 242.854 70.9334 L 246.949 82.5962 C 252.512 98.4372 254.301 109.305 254.26 127 C 254.158 171.065 238.452 202.053 202.5 229.126 C 188.835 239.417 177.341 244.987 160 249.722 C 151.914 251.93 148.043 252.361 134 252.617 C 122.571 252.825 115.041 252.465 109.5 251.445 L 109.5 251.445 z")
      AddPathSegments("M 153.707 234.97 C 171.823 230.749 187.331 222.451 202.572 208.824 C 217.332 195.625 224.831 185.249 231.425 168.894 C 241.096 144.91 241.072 109.214 231.367 84.959 C 229.793 81.0262 229.747 81 224.342 81 C 221.349 81 217.573 80.3134 215.95 79.4743 C 213.226 78.0654 211.607 79.0211 214.104 80.5644 C 216.233 81.8799 218.956 89.5455 218.978 94.2821 C 219.04 107.748 207.948 117.573 195.772 114.837 C 177.979 110.84 174.684 85.0661 190.826 76.1543 C 195.922 73.341 203.292 73.0862 208.188 75.5541 L 211.5 77.2237 L 207.347 72.8619 C 202.167 67.422 195.67 57.3519 193.362 51.1838 C 192.15 47.9463 189.662 44.6971 185.304 40.6614 C 181.837 37.4502 179 34.3192 179 33.7036 C 179 32.0766 186.158 25 187.803 25 C 190.187 25 203.697 37.8277 204.942 41.2722 C 209.379 53.5559 219.626 67.6038 223.592 66.84 C 227.496 66.0881 231.617 58.6941 233.482 49.0944 C 237.179 30.0578 232.787 22.9268 215.49 19.8863 C 206.433 18.2942 171.698 18.3313 162.252 19.9431 C 156.039 21.0034 153.541 20.9335 144.752 19.4541")
      AddPathSegments("C 130.903 17.1225 113.148 17.8721 103.455 21.1975 C 99.7158 22.4801 96.4856 24.0431 96.2764 24.6708 C 96.0672 25.2984 97.2151 27.3168 98.8274 29.156 C 104.423 35.5397 113.032 49.3694 114.512 54.3526 C 116.589 61.3476 116.408 72.506 114.135 77.5086 C 111.917 82.3906 106.446 87.3678 101.504 88.9988 L 97.8356 90.2094 L 103.436 95.2008 C 114.844 105.369 119.471 115.85 118.806 130.017 C 118.308 140.627 114.507 149.469 107.059 157.344 C 86.3609 179.229 49.2095 173.616 35.9964 146.606 C 23.8985 121.876 38.8692 91.7251 66.1513 85.8741 C 74.005 84.1898 70.0399 82.8535 56.6181 82.6611 C 45.6169 82.5035 45.2936 82.5628 41.5153 85.4327 L 37.6543 88.3655 L 33.3271 83.586 C 30.9472 80.9573 29 77.9729 29 76.9541 C 29 74.8422 33.9616 70.7401 39.0538 68.6419 C 48.0979 64.9153 68.2497 65.8823 79.1294 70.565 C 86.4478 73.7149 96.2354 74.8795 98.6372 72.8862 C 99.8574 71.8735 100.118 70.0165 99.8336 64.3753 C 99.4861 57.4952 99.2056 56.7725 93.7992 48.8299 C 90.6807 44.2484 86.4127 38.867 84.3146 36.8711")
      AddPathSegments("C 78.9772 31.7936 68.1933 27.6709 60.3612 27.7136 C 45.435 27.7951 27.7743 35.5093 24.4836 43.385 C 22.5334 48.0524 22.6651 136.714 24.6366 146.415 C 26.7181 156.657 31.3265 169.694 36.578 180.196 C 47.8305 202.699 60.7285 215.018 85.7181 227.128 C 106.969 237.427 131.176 240.219 153.707 234.97 L 153.707 234.97 z M 125.5 200.018 C 120.657 198.102 111.329 191.241 109.7 188.396 C 109.168 187.466 110.156 185.498 112.662 182.5 C 114.731 180.025 116.778 178 117.21 178 C 117.643 178 120.689 180.09 123.979 182.645 C 128.801 186.39 130.93 187.383 134.968 187.771 C 141.078 188.358 145.051 186.845 148.894 182.468 C 151.687 179.287 155.507 169.993 154.832 168.022 C 154.649 167.489 147.994 163.74 140.043 159.69 C 124.94 151.997 121.295 148.942 122.326 144.837 C 123.604 139.747 125.217 138.992 153.028 130.458 C 168.137 125.822 181.502 122.022 182.727 122.014 C 185.097 121.999 187.477 124.894 188.469 129")
      AddPathSegments("C 189.178 131.934 183.552 144.205 176.499 155.108 C 174.025 158.933 172 162.688 172 163.453 C 172 165.626 179.965 171.903 183.585 172.582 C 189.484 173.689 198.265 170.593 202.688 165.847 C 203.891 164.556 205.442 161.25 206.134 158.5 C 206.826 155.75 207.688 153.138 208.05 152.696 C 208.8 151.779 218.076 152.811 220.049 154.03 C 221.118 154.691 221.124 155.896 220.083 160.669 C 216.588 176.699 204.164 186.223 186.5 186.414 C 179.691 186.487 177.666 186.091 172.9 183.75 C 169.821 182.238 167.048 181 166.74 181 C 166.431 181 165.201 183.02 164.005 185.489 C 161.596 190.466 154.941 196.825 149.225 199.612 C 143.665 202.323 131.838 202.526 125.5 200.018 L 125.5 200.018 z M 90.7997 140.595 C 100.728 135.43 102.568 122.82 94.5304 115.03 C 91.52 112.112 90.2048 111.577 85.2611 111.259 C 80.7417 110.969 78.7976 111.331 76.2409 112.936 C 66.4703 119.069 66.4703 134.048 76.2409 140.005 C 80.0793 142.346 86.9037 142.622 90.7997 140.595 L 90.7997 140.595 z")
      
      VectorSourceColor(RGBA(0, 0, 0, 255))
      FillPath()
      GadgetToolTip(0,"Puppy Linux vector mascot")
      
      StopVectorDrawing()
    EndIf
    
    Repeat
      Event = WaitWindowEvent()
      If Event = #PB_Event_Gadget
        
        Select EventGadget()
        Case 1
        MessageRequester("Info", "Puppy RULEZ!", #PB_MessageRequester_YesNoCancel)
        Case 2
        MessageRequester("Info", "Puppy RULEZ again!")
      EndSelect
    EndIf            
    
  Until Event = #PB_Event_CloseWindow
EndIf
End

This uses the vector capabilities of PureBasic and its corresponding commands. But you can tell, come on, Grey, where all these fucking numbers in AddPathSegments come from?
Oooh, segments are the most interesting part. PureBasic supports its own lightweight syntax, but still accepts format defined by the SVG Tiny standard.
But it turned out that data from SVG files of "modern large" Inkscape is misunderstood by PureBasic. And then I remembered InkscapeLite, the old version(0.36) of which is in most Puppy distros.
And yes! The data ripped out of his SVG files are good. Therefore, the scheme of actions is as follows:
1. First, in "modern large" Inkscape, vectorize(or draw) a picture from a raster .jpeg or .png and save it in SVG.
2. Then open the resulting SVG in good old InkscapeLite and re-save it with the "Plain SVG" file type. It is important! Now SVG differs from the previous one in that it is NOT displayed in the Viewnior.
Now the version of the format is lower than the previous one.
3. Open the SVG from the second point in Geany. We are looking for lines that start with d=" and then a bunch of numbers. This is our data.
4. We add data to the AddPathSegments command in our program. I divided it into five lines, but you can into one - the main thing is no more than 8192 characters in line.

Now in programs we can draw our favorite mascot without external pictures, only with the basic Basic tools :)

Fossapup OS, Ryzen 5 3600 CPU, 64 GB RAM, GeForce GTX 1050 Ti 4 GB, Sound Blaster Audigy Rx with amplifier + Yamaha speakers for loud sound, USB Sound Blaster X-Fi Surround 5.1 Pro V3 + headphones for quiet sound.

Post Reply

Return to “Programming”