November 28, 2020, 10:56:10 AM

Author Topic: [bmx] Spherical Text by Jesse [ 1+ years ago ]  (Read 389 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
[bmx] Spherical Text by Jesse [ 1+ years ago ]
« on: June 29, 2017, 12:28:41 AM »
Title : Spherical Text
Author : Jesse
Posted : 1+ years ago

Description : I had been trying to figure this out for quite sometime. so I finally figuredit out.
Text is displayed scrolling around a sphere.
I hope it's usefull to someone


Code :
Code: BlitzMax
  1. SuperStrict
  2. Global twidth%,Theight%
  3. Type Tnode
  4.         Field x#
  5.         Field y#
  6.         Field z#
  7. End Type
  8.  
  9. Graphics 1024,768,32
  10. Global format:tnode[][] = getformat()
  11. Global textbox%[,]=gettextbox()
  12. Local st$ = "Hello world This is a code I had been having problems with and finally I figured it out."
  13. st :+ " I wanted To design this For a game I am working on. But now I don't feel like adding this"
  14. st :+ " code To it. I hope you all enjoy it."
  15. Local n% = TextWidth(st)
  16. Local ang% = 0
  17. Repeat
  18.         For Local q% = 0 To st.length-1
  19.                 put((st[q]),ang-8*q,GraphicsWidth()/2,GraphicsHeight()/2)
  20.         Next
  21.         Flip()
  22.         Cls
  23.         ang = (ang+1) Mod (180+n)
  24. Until KeyDown(key_escape)
  25.  
  26.  
  27.  
  28. Function put(c%,ang%,offsetx%,offsety#)
  29.         c = (c-32)*8
  30.         ang = 180 -ang
  31.         If ang >188 Return
  32.         For Local x% =  0 To 7
  33.                 For Local y% = 0 To 15
  34.                         If (x+ang) < 180 And (x+ang)>0
  35.                                 If textbox[x+c,y] = 0
  36.                                         SetColor 0,255,0
  37.                                         DrawRect format[x+ang][15-y].x+offsetx,format[x+ang][15-y].y+offsety,1,8
  38.                                 Else
  39.                                         SetColor 255,0,0                               
  40.                                         DrawOval format[x+ang][15-y].x+offsetx,format[x+ang][15-y].y+offsety,1,8
  41.                                 EndIf
  42.                         EndIf
  43.                 Next
  44.         Next
  45. End Function
  46.  
  47. Function getformat:tnode[][]() 
  48.         Local nodeList:TList=CreateList()
  49.         Local d# = 600
  50.         Local mz# = -100
  51.         Local AngleAxisz# = 0 'spin along y axis; angle of z
  52.         Local AngleAxisx# = 20 'spin along z axiz; angle of x
  53.         Local AngleAxisy# = 0 'spin along x axis; angle of y
  54.         Local gtext:tnode[][]
  55.         gtext = gtext[..180]
  56.         For Local c% = 0 To 179
  57.                 gtext[c]=gtext[c][..16]
  58.         Next
  59.         Local sinAngleAxisx# = Sin(AngleAxisx)
  60.         Local cosAngleAxisx# = Cos(AngleAxisx)
  61.         Local sinAngleAxisy# = Sin(AngleAxisy)
  62.         Local cosAngleAxisy# = Cos(AngleAxisy)
  63.         Local node:tnode
  64.         For Local i# = -8 To 7  
  65.                 node= New tnode
  66.                 nodelist.addlast(node)
  67.                 node.x = (Cos(i*2)*25)
  68.                 node.y = (Sin(i*2)*25)
  69.                 node.z = 0
  70.         Next
  71.  
  72.         For angleaxisz = -179 To 0 Step 1
  73.                 Local sinAngleAxisz# = Sin(AngleAxisz)
  74.                 Local cosAngleAxisz# = Cos(AngleAxisz)
  75.                 Local n% = 0
  76.                 For node  = EachIn nodeList
  77.                         Local X# = -node.x;
  78.                         Local Xa# = cosAngleAxisz * X - sinAngleAxisz * node.z;
  79.                         Local Za# = sinAngleAxisz * X + cosAngleAxisz * node.z
  80.                         Local Ya# = cosAngleAxisx * node.y - sinAngleAxisx * Xa;
  81.                         X = cosAngleAxisx * Xa + sinAngleAxisx * node.y;
  82.                         Local Z# = cosAngleAxisy * Za - sinAngleAxisy * Ya
  83.                         Local Y# = sinAngleAxisy * Za + cosAngleAxisy * Ya;
  84.                         Z = Z + mZ
  85.                         Local sx# = D * X / Z
  86.                         Local sy# = D * Y / Z
  87.                         gtext[179+angleaxisz][n] = New tnode
  88.                         gtext[179+angleaxisz][n].x = sx
  89.                         gtext[179+angleaxisz][n].y = sy
  90.                         n = n + 1
  91.                 Next
  92.         Next
  93.         Return gtext
  94. End Function
  95. Function gettextbox%[,]()
  96.                 Local text$
  97.                 For Local c% = 32 To 127
  98.                         text :+ Chr(c)
  99.                 Next
  100.                 twidth% = TextWidth(text$)
  101.                 theight% = TextHeight(text$)
  102.                 Local array%[twidth,Theight]
  103.                 Local image:timage=CreateImage(Twidth,theight,1,DYNAMICIMAGE)
  104.                 Cls
  105.                 DrawText text,0,0
  106.                 GrabImage image,0,0
  107.                 Local map:TPixmap = LockImage(image)
  108.                 Cls
  109.                 Local c%=0
  110.                 For Local y# = 0 To PixmapHeight(map)-1
  111.                         For Local x#=0 To PixmapWidth(map)-1
  112.                                 Local color% = $fff & ReadPixel(map,x,y)
  113.                                 If  color array[x,y]=1 Else array[x,y] = 0
  114.                         Next
  115.                 Next
  116.                 Return array
  117. End Function


Comments :


Ryan Burnside(Posted 1+ years ago)

 Wow that was REALLY impressive. I wish I had 1337 math skillz like you.


Jesse(Posted 1+ years ago)

 if I have some, Help me find them. My math skills are verry limited. it reches one semester trig and below. thanks.  I am glad you like it.


SculptureOfSoul(Posted 1+ years ago)

 Wow, this is cool. Nice work.


Jesse(Posted 1+ years ago)

 thanks SOS!


jankupila(Posted 1+ years ago)

 Sorry, wrong topic.


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal