Skip to content

Commit

Permalink
Merge pull request #19 from Canvim/new_shapes
Browse files Browse the repository at this point in the history
New shapes
  • Loading branch information
cqann authored Sep 2, 2020
2 parents c37b8d6 + 9b269ea commit 0e5d6a4
Show file tree
Hide file tree
Showing 18 changed files with 348 additions and 43 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/pypen_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,7 @@ name: PyPen CI

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
test:
Expand Down
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ TL;DR:
3. type ```pypen example``` and a window should popup with something looking like this: <br><br><img src="https://i.imgur.com/AwMJM3K.png" width="200px"><br><br>
4. edit the example.py file by checking out PyPen's documentation and [examples](./examples/)

## Inspiration from our Examples:

| Example 002 | Example 003 |
|:-----------:|:-----------:|
|![Example 002 Gif](./examples/gifs/002.gif)|![Example 003 Gif](./examples/gifs/003.gif)|

| Example 006 | Example 007 |
|:-----------:|:-----------:|
|![Example 006 Gif](./examples/gifs/006.gif)|![Example 007 Gif](./examples/gifs/007.gif)|

| Example 010 | Example 011 |
|:-----------:|:-----------:|
|![Example 010 Gif](./examples/gifs/010.gif)|![Example 011 Gif](./examples/gifs/011.gif)|

## _(For Maintainers)_ How does PyPen work?
We have an entire page dedicated to explaining the inner workings of PyPen. If you are a developer interested in helping PyPen's development, you should check it out: [How does PyPen _Really_ Work?](https://pypen.readthedocs.io/en/latest/behind_the_scenes.html#behind-the-scenes)

3 changes: 2 additions & 1 deletion examples/example_007.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def __init__(self, x, y):
self.secondary_color = "#565656"

def update(self):
reset_style()
save()
translate(self.x, self.y)
rotate(TIME)
Expand Down Expand Up @@ -40,7 +41,7 @@ def rectangle(self):
def circle(self):
circle(0, 0, self.width/2, self.color)
if self.variation > 0.6:
arc(0, 0, self.width/2, 0, PI, self.secondary_color)
arc(0, 0, self.width/2, 0, PI, None, self.secondary_color, 2)


def start():
Expand Down
10 changes: 5 additions & 5 deletions examples/example_008.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@ def update():
fill_screen("orange")

save()
translate(60,60)
translate(60, 60)
rotate(T*2.5)
ellipse(0, 0, 50, 30, "red", "blue", 3)
restore()

save()
translate(200,200)
translate(200, 200)
rotate(T*1.5+0.5)
ellipse(40*sin(T), 0, 30, 50, stroke_width=10)
restore()

save()
translate(400,300)
translate(400, 300)
rotate(T)
ellipse(0, 100*cos(T*2), 30, 100, "green")
restore()
restore()
42 changes: 42 additions & 0 deletions examples/example_009.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from pypen import *


def start():
settings.fps = 60


def update():
fill_screen("#343434")

begin_shape()
vertex(40, 40)
vertex(40, 140)
vertex(FRAME, 140)
end_shape("red")

begin_shape()
vertex(40+FRAME, 240+FRAME)
vertex(40, 340)
vertex(FRAME, 340)
vertex(340, 280)

end_shape("yellow", "blue", 5)

reset_style()

angle = 0
points = 10 + sin(TIME*2)*5
radius = 100

save()
translate(WIDTH/2, HEIGHT/2)

begin_shape()

while angle <= TAU:
angle += TAU/points
vertex(sin(angle)*radius, cos(angle)*radius)

end_shape("orange")
restore()
reset_style()
19 changes: 19 additions & 0 deletions examples/example_010.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from pypen import *


def start():
settings.fps = 60

def update():
save()
translate(WIDTH/2, HEIGHT/2)

x1 = 200 * cos(TIME - 10 * sin(TIME)) * cos(TIME)
y1 = 200 * sin(TIME - FRAME/10) * sin(TIME)

x2 = 200 * cos(TIME + FRAME ** 0.5) * cos(TIME-0.5)
y2 = 200 * sin(TIME + FRAME/10 - 10*cos(TIME/10)) * sin(TIME - 0.5)

line(x1, y1, x2, y2, (150, 30, 230, 10), 0.2)

restore()
22 changes: 22 additions & 0 deletions examples/example_011.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from pypen import *


def pseudo_random(seed: float):
return abs(sin(seed % 478562)*cos(seed % 3579))

def update():
clear_screen()

i = 0
offset_y = TIME*170

for x, y in grid(spacing=30):
seed = i+x*y

actual_y = (y + offset_y) % HEIGHT - 30
percentage = (1-(actual_y/HEIGHT)**5)
color = (80, 130, 50, pseudo_random(seed)*255*percentage)

circle(x, actual_y, pseudo_random(seed)*14*percentage, color)

i += 1
Binary file added examples/gifs/002.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/gifs/003.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/gifs/006.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/gifs/007.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/gifs/010.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/gifs/011.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion pypen/drawing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
from pypen.drawing.pypen_window import PyPenWindow

# Primitives used for intellisense and documentation
from pypen.drawing.fake_primitives import *
from pypen.drawing.fake_pypen import *
79 changes: 50 additions & 29 deletions pypen/drawing/fake_primitives.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@

def rotate(angle):
"""Rotates the context"""
raise NotImplementedError("rotate() is not implemented")


def translate(x, y):
"""Translates the context by x and y"""
raise NotImplementedError("translate() is not implemented")


def scale(factor):
"""Scales the context by the provided factor"""
raise NotImplementedError("scale() is not implemented")


def save():
"""Saves the current context's translation, rotation and scaling"""
raise NotImplementedError("save() is not implemented")


def restore():
"""Restores the context's translation, rotation and scaling to that of the latest save"""
raise NotImplementedError("restore() is not implemented")


def reset_style():
"""Resets PyPen's current setting surrounding style to their default_values, which includes fill_color, stroke_color, stroke_width"""
raise NotImplementedError("reset_style() is not implemented")


def clear_screen():
"""Clears the screen"""
Expand All @@ -20,6 +49,21 @@ def fill():
raise NotImplementedError("fill() not implemented")


def begin_shape():
"""Tells PyPen that a shape is a bout to be created"""
raise NotImplementedError("begin_shape() not implemented")


def vertex(x, y):
"""Adds a vertex to current shape at (x, y)"""
raise NotImplementedError("vertex() not implemented")


def end_shape(fill_color="", stroke_color="", stroke_width=-1):
"""Ends shape and styles it"""
raise NotImplementedError("end_shape() not implemented")


def rectangle(x, y, width, height, fill_color="", stroke_color="", stroke_width=-1):
"""Draws a rectangle on the given coordinate with the given width, height and color"""
raise NotImplementedError("rectangle() not implemented")
Expand All @@ -39,33 +83,10 @@ def arc(x, y, radius, start_angle, stop_angle, fill_color="", stroke_color="", s
"""Draws an arc on the given coordinate with the given radius, angles and color"""
raise NotImplementedError("arc() not implemented")

def triangle(x1, y1, x2, y2, x3, y3, fill_color="", stroke_color="", stroke_width=-1):
"""Draws a triangle between the supplied coordinates with the given color"""
raise NotImplementedError("triangle() not implemented")

def rotate(angle):
"""Rotates the context"""
raise NotImplementedError("rotate() is not implemented")


def translate(x, y):
"""Translates the context by x and y"""
raise NotImplementedError("translate() is not implemented")


def scale(factor):
"""Scales the context by the provided factor"""
raise NotImplementedError("scale() is not implemented")


def save():
"""Saves the current context's translation, rotation and scaling"""
raise NotImplementedError("save() is not implemented")


def restore():
"""Restores the context's translation, rotation and scaling to that of the latest save"""
raise NotImplementedError("restore() is not implemented")


def reset_style():
"""Resets PyPen's current setting surrounding style to their default_values, which includes fill_color, stroke_color, stroke_width"""
raise NotImplementedError("reset_style() is not implemented")

def line(x1, y1, x2, y2, stroke_color="", stroke_width=-1):
"""Draws a line between the supplied coordinates with the given stroke_color and stroke_width"""
raise NotImplementedError("triangle() not implemented")
126 changes: 126 additions & 0 deletions pypen/drawing/fake_pypen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@

def rotate(angle):
"""Rotates the context.
Args:
angle (float): The amount by which the context should be rotated.
"""
raise NotImplementedError("rotate() is not implemented")


def translate(x, y):
"""Translates the context by x and y.
Args:
x (float): Horizontal coordinate.
y (float): Vertical coordinate.
"""
raise NotImplementedError("translate() is not implemented")


def scale(factor):
"""Scales the context by the provided factor
Args:
factor (float): The amount by which the current context should be scaled.
"""
raise NotImplementedError("scale() is not implemented")


def save():
"""Saves the current context's translation, rotation and scaling"""
raise NotImplementedError("save() is not implemented")


def restore():
"""Restores the context's translation, rotation and scaling to that of the latest save"""
raise NotImplementedError("restore() is not implemented")


def reset_style():
"""Resets PyPen's current setting surrounding style to their default_values, which includes fill_color, stroke_color, stroke_width"""
raise NotImplementedError("reset_style() is not implemented")


def clear_screen():
"""Clears the screen"""
raise NotImplementedError("clear_screen() not implemented")


def clear():
"""Clears the screen"""
raise NotImplementedError("clear() not implemented")


def fill_screen(fill_color):
"""Fills the screen with the specified color
Args:
fill_color (Color): The color by which to fill the screen. Defaults to the theme's default background color.
"""
raise NotImplementedError("fill_screen() not implemented")


def fill():
"""Fills the current path. Different from fill_screen."""
raise NotImplementedError("fill() not implemented")


def rectangle(x, y, width, height, fill_color, stroke_color, stroke_width):
"""Draws a rectangle on the given coordinate with the given width, height and color
Args:
x (float): Horizontal coordinate.
y (float): Vertical coordinate.
width (float): Width of the triangle.
height (float): Height of the triangle.
fill_color (Color, optional): The color by which to fill the rectangle.
stroke_color (Color, optional): The color of the rectangle's outline
stroke_width (float, optional): The width of the outline.
"""
raise NotImplementedError("rectangle() not implemented")


def circle(x, y, radius, fill_color, stroke_color, stroke_width):
"""Draws a circle on the given coordinate with the given radius and color
Args:
x (float): Horizontal coordinate.
y (float): Vertical coordinate.
radius (float): Radius of the circle.
fill_color (Color, optional): The color by which to fill the circle.
stroke_color (Color, optional): The color of the circle's outline
stroke_width (float, optional): The width of the outline.
"""
raise NotImplementedError("circle() not implemented")


def ellipse(x, y, width, height, fill_color="", stroke_color="", stroke_width=-1):
"""Draws an ellipse on the given coordinate with the given width, height and color
Args:
x (float): Horizontal coordinate.
y (float): Vertical coordinate.
width (float): Width of the ellipse.
height (float): Height of the ellipse.
fill_color (Color, optional): The color by which to fill the ellipse.
stroke_color (Color, optional): The color of the ellipse's outline
stroke_width (float, optional): The width of the outline.
"""
raise NotImplementedError("ellipse() not implemented")


def arc(x, y, radius, start_angle, stop_angle, fill_color="", stroke_color="", stroke_width=-1):
"""Draws an arc on the given coordinate with the given radius, angles and color
Args:
x (float): Horizontal coordinate.
y (float): Vertical coordinate.
radius (float): Radius of the arc.
start_angle (float): The angle from which to begin drawing the arc.
stop_angle (float): The angle at which to stop drawing the arc.
fill_color (Color, optional): The color by which to fill the arc.
stroke_color (Color, optional): The color of the arc's outline
stroke_width (float, optional): The width of the outline.
"""
raise NotImplementedError("arc() not implemented")
Loading

0 comments on commit 0e5d6a4

Please sign in to comment.