📜 ⬆️ ⬇️

Magic through the eyes of a programmer

Magic through the eyes of a programmer. Introduction


I think many people wondered at least once, they say, it would be nice if the magic in one form or another was available at least to me. Let us omit any speculative moments, we are interested in something else: what would Magic be like if the programmer invented it?

We start to dream


Actually, why all this? As they say, magic exists if you believe in it. In order not to start a holivar, I will say my imho: I will believe if I can understand or prove. I believe in the Small Theorem Farm, since it (once) works and (two) I can prove it, that is, reduced to some postulates or agreements.
Therefore let:
  1. There is magic.
  2. Magic has logic, language, syntax.
  3. There is a Standard Library containing what we don’t have to do ourselves. It just works.
  4. And most importantly: we can use it all.

What do we get? We can not say "I want to find the keys!". Why? Yes, because, Magic, dear% username%, does not know what kind of keys you want to find and what it means for you to "find". Let's figure out what to do.

The magic begins


So,
  1. import magic.core # import magic.physics # import magic.effects #
  2. import magic.core # import magic.physics # import magic.effects #
  3. import magic.core # import magic.physics # import magic.effects #

Let it be the keys and let them in this room. Let them lie on the surface and not covered by anything. And finally, let “find” means for us to see the luminous keys at eye level. Just for starters.

Keys


The keys for us are 2–3 keys on the ring + key chain. On the other hand, it is almost a solid object. We must somehow associate a specific object with the word "keys".
')
  1. alias = str (core.recognizeThought (presentThought)) # for clarity, let it be a string
  2. effects.fire (core.getFocusedObject (), MColor ( '# 4C95DC' )) # highlight the object in focus with a blue flame.
  3. # For example, we look at him or think specifically about him
  4. if core.recognizeThought (presentThought): # yes yes, we can think True
  5. core.Shotrcuts.append ({ 'id' : alias, 'object' : core.getFocusedObject ()}) # stick an object association into the Great Label array
  6. else :
  7. core.getFocusedObject (). resetState () # remove the effect


Something like this. We do the procedure and go through the house. We assume that the standard functions are sufficiently thought out to do exactly what we want. Yes, not very logical, but we're just having fun;)
So, favorite slippers, keys and mobile phone are already known to our Magic.

Levitation


Now we need to raise the keys to eye level. For this, we import another module.
  1. from magic.metrics import MyHeights
  2. EyeLevel = MyHeights.FLOOR + MyHeights.HEIGHT - 0.15 # Eye level = the floor where I stand + my height is 15 centimeters
  3. object = core.Shortcuts [ 'keys' ]
  4. effects.fire ( object , MColor ( '# ff9800' ))
  5. physics.moveTo ( object , z = EyeLevel, x = object .getX (), y = object .getY (), smooth = True , freeze = True ) # Smoothly raise the keys to eye level and fix it there


Voila We make a simple procedure and enjoy.
On the one hand, everything is extremely simple, however, what to do if the keys are in a pocket or in another room? And if you need to create something, and not to operate with existing objects? A huge field for fantasy!
And next time we will brew tea!

PS This is a warm-up for the mind, but a pleasure. Any ideas - Share!
UPD1: java version of dpaste.org/d1O1 Thanks danilissimus

Source: https://habr.com/ru/post/84947/


All Articles