sierpinski | makes a sierpinski triangle of a user-specified height | Canvas library
kandi X-RAY | sierpinski Summary
kandi X-RAY | sierpinski Summary
draw a sierpinski triangle of a user-specified height.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Calculate the next generation .
- Print out a list .
sierpinski Key Features
sierpinski Examples and Code Snippets
Community Discussions
Trending Discussions on sierpinski
QUESTION
I am working on a C to Brainfuck transpiler, based on the translation described in Brainfuck's Wikipedia page. Each program that I have tested works perfectly, until the end. In the beginning, I allocate an array of 30000 bytes, char* ptr = malloc(30000 * sizeof(char));
, and in the end I free it via free(ptr);
. My transpiler is below:
ANSWER
Answered 2021-Jan-05 at 22:28Do this:
QUESTION
I have a project where I draw a triangle using points, it is called Sierpinski Gasket. To achieve that I am using a class Vx which holds x and y values. The problem is it throws different values if any method is virtual and I wonder why. How virtual functions affect the way the points are generated in the following OpenGL code?
My vector class has the following declaration:
...ANSWER
Answered 2020-Dec-05 at 05:44Class with virtual methods has implicit field - pointer to VMT
(virtual method table). You can check it by printing sizeof(Vx)
with and without virtual methods. Internal representation of classes and structs is not specified by the C++ standards and varies between compilers, so you should not pass classes with virtual methods to functions like glBufferData
.
QUESTION
I'm writing a program in Java to make a Recursive Sierpinski Triangle, to the middle and left side of the triangle it draws recursively like a master-stroke.
However, anything to do with the right side of the triangle simply will not draw.
Here is some code, I'll explain how it works so you have an easier time reading it.
The first thing it does is establish a height for the triangle in the height function.
Height is called in filledTriangle which uses length as an argument (which is 1) and is then passed to a variable hei.
I then use a simple set of coordinates.
x0, x1, x2. y0 , y1, y2.
After that I set up my midpoints, because all a midpoint in a Sierpinski Triangle is are the sum of 2 points divided by 2.
After that, I pass my midpoints X and Y into an array, and voila , a triforce is made!
So naturally, I attempt to create a recursive triangle for the left. The left works masterfully.
Then I plug the arguments into the right and it simply doesn't work.
...ANSWER
Answered 2020-Nov-05 at 04:10There seems to be a couple of bugs in your code:
n--
does not return n-1, but rather n. You should replace it withn-1
.- There are few issues with
filledTriangle
. The (x,y) pairings you create are: (x-x, y), (x, y), and (x/2, height). The (x,y) pairing is a correct point, but the other two are not. Instead you should use (x-length/2,y+height) and (x-length, y) for the top and left points on the triangle. - When you call
sierpinski
recursively, you should pass itx
instead ofx+x/2
. This is because, in this program, you are using the bottom right triangle vertex as the primary vertex. When drawing the right side of the sierpinski triangle, this vertex stays the same.
QUESTION
I am calling this recursive function below:
...ANSWER
Answered 2020-Oct-27 at 17:26...and then calls itself three times with the value n-1... means you just need to duplicate calls to sierpinski((n-1))
one after the other 3 times as below:
QUESTION
How do I find the midpoint of a triangle that was originally drawn? I need to create a sierpinski triangle in which there are multiple triangles within a triangle. So far, I have the code for the first triangle shown below:
...ANSWER
Answered 2020-Oct-21 at 02:37The "midpoint triangle" inside another triangle is defined by a triangle who's co-ordinates are the mid-points of the sides of the surrounding triangle:
So for each line/side of your triangle, calculate the midpoint:
QUESTION
I made a code that generates a string of text base 3, similar to the way that numbers are written in base 3, but the base are complex numbers
For example:
...ANSWER
Answered 2020-Sep-19 at 15:13One can use Python's builtin number parsing to speed up CoordinatesOfString
, which is the bottleneck. The key is that each number can be split into a separate number for each digit, which can be individually translated and merged via addition.
For example, the number 110A0A1
can be decomposed to the sum of
- the 0-digits
0000000
or0
, - the 1-digits
1100001
or1100001
, - the A-digits
000A0A0
orA * 0001010
.
We can use str.replace
to transform the initial literal to the 1-digit and A-digit literals. Using int(..., 2)
allows to parse these as binary literals.
QUESTION
I've been working on a tutorial paper where we are meant to create a Sierpinksi Triangle. which supposed to look like this : enter image description here
And I don't know what is wrong with my code cause its not like what the output that i wanted. Can someone please help me fix this?
I couldn't make my function work.
...ANSWER
Answered 2020-Aug-15 at 01:52I also have to do this for the course i'm doing at Massey Uni. The function I used was:
QUESTION
I am trying to change the color of the vertices of each triangle that I have created using the following code:
This is the Point structure; this structure stores the position data and color data of each vertex:
...ANSWER
Answered 2020-Jul-27 at 21:15When you want to change the color of your vertices over time, you probably want to modify it frame by frame as in the example at the following link:
I have set up a simple way of making those structures change their values during the rendering loop; you can get [more] creative with that once you got the idea. What is important is that you update the data in your structures and you load the new data in the vertex buffer object at each frame, so that the vertex shader and the fragment shader can read the new values.
Note that you can make the colors change during each frame in different ways; another idea could be using random numbers to set the colors' components.
As a side note, you should be able to pass vertices.data()
to glBufferData
as a pointer to your vertex data, and avoid declaring an array of Point
s for it.
QUESTION
I created a JavaFX program to draw a Sierpinski Carpet recursively, but I want to see the recursive functions in action that is, to slow down the program to see it drawing in real-time. For that I tried something like this:
...ANSWER
Answered 2020-Jun-13 at 08:53Any modification on the GUI only yields visual results after it returns. In the meantime JavaFX cannot handle any events and freezes, until your operation is done.
You can use a Timeline
to execute the operation one step at a time though: Use a stack the data for one drawing execution; this allows you to do one drawing operation at a time in addition to modifying the stack for every frame of the Timeline
.
QUESTION
I have to generate the Sierpinski Triangle using a 2d point class and tkinter canvas.The midpt function is essentially going to take input from a randomly chosen vertex and the last plotted midpoint. You can choose any vertices to plot the first midpoint. The points also need to be instances of the 2d point class. I desperately need help because I can't seem to figure this out. Here is what the output is supposed to look like.
This is what I have done so far, but it is not using the 2d point class to generate the triangle.
...ANSWER
Answered 2020-May-26 at 01:54The problem was that you were duplicating the Point-based code in the midpt()
method in your plotPoints()
method, but for tuples instead of Points. Since the triangle is handed to us as a list of tuples, we convert that to a list of Points, and modify our plot()
method to accept a Point, and run the whole plotPoints()
method in terms of Points:
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install sierpinski
You can use sierpinski like any standard Python library. You will need to make sure that you have a development environment consisting of a Python distribution including header files, a compiler, pip, and git installed. Make sure that your pip, setuptools, and wheel are up to date. When using pip it is generally recommended to install packages in a virtual environment to avoid changes to the system.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page