Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with Morpholib?
#1
This Youtuber:
Morphocular
says, he has made his math animations with this library-package:
https://github.com/morpho-matters/morpholib

So i decided to play around with it my self.

I installed python, the package and the pycharm environment and tested some sample codes from the repository.

But the window, that opened from running theese things, flickered in green horizontal stripes and the lines look a bit out of shape
   
How to fix this?
I played around with the turtle library before, but do not mention it in my code any more

Than i tried to create a polygon my self with this code:

import morpholib as morpho
morpho.importAll()

from morpholib.tools.basics import *
from morpholib.video import *
from morpholib.grid import Polygon

import math, cmath, random

def kite():
    class Kite(morpho.Skit):
        def makeFrame(self):
            kitepolygon = morpho.grid.Polygon(vertices = [(0, 1), (2, 0), (0, -3), (-2, 0)])

            kitepolygon.width = 4
            kitepolygon.color = (1,1,0)
            kitepolygon.alphaEdge = 0
            kitepolygon.fill = (1,1,0)
            kitepolygon.alphaFill = 0
            kitepolygon.alpha = 0

            kitepolygon.commitTransforms()

            return morpho.Frame([kitepolygon])

    kite1 = Kite()
    kite1 = morpho.Actor(kite1)
    kite1.newendkey(6*30).t = 6

    animation = morpho.Animation(kite1)
    animation.play()

kite()
The coordinates should create a kite with the siagonals intersecting in the coordinate origin.
like this
Made with Geogebra


If i run the code, as it is, i get this error:

Error:
File "C:\Users\"User-Name"\AppData\Roaming\Python\Python311\site-packages\morpholib\grid.py", line 2740, in <lambda> newVertices = self.fimage(lambda s: (mat*(rot*s))+self.origin).vertices ~~~^~ TypeError: can't multiply sequence by non-int of type 'complex'
If i comment out the line "kitepolygon.commitTransforms()", i get an empty window.

Does any one know how to use this morpho package, how to enter the vertex-coordinates for the polygon the right way and centrate the coodinate-origin on the window?
Larz60+ write Nov-13-2022, 01:35 AM:
Please post all code, output and errors (it it's entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Fixed your code this time, please use BBCode tags on future posts.
Reply
#2
Now i got the kiteshape to appear with this code:
import morpholib as morpho
morpho.importAll()
import sample

from morpholib.tools.basics import *
from morpholib.video import *
from morpholib.grid import Polygon

import math, cmath, random

kite = morpho.grid.Polygon([1*1j, 2, -3*1j, -2])

kite.width = 4
kite.color = (1,1,0)
kite.alphaEdge = 1
kite.fill = (1,1,0)
kite.alphaFill = 1
kite.alpha = 1

animation = morpho.Animation(kite)
animation.play()
i found in a tutorial, that i hat to give the vertices in the form [1*1j, 2, -3*1j, -2].
But what means the multiplication with a value of j, that it makes points come of from 0 along the y axis?
Reply
#3
1*1j is a complex number
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020