-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from polldo/python-animation
Python animation
- Loading branch information
Showing
13 changed files
with
325 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import dolp | ||
|
||
explosion1 = bytearray(b'\x10\x10\x00\x00\x00\x00\x90\x40\x40\x20\x40\x40\x84\x00\x10\x00\x00\x00\x00\x00\x04\x00\x00\x05\x01\x02\x01\x21\x00\x04\x00\x00\x00\x00') | ||
explosion2 = bytearray(b'\x10\x10\x00\x00\x00\x00\x88\x60\x24\x10\x20\x60\x80\x00\x12\x00\x00\x00\x00\x40\x02\x00\x00\x03\x02\x24\x02\x03\x00\x00\x00\x44\x00\x00') | ||
explosion3 = bytearray(b'\x10\x10\x00\x00\x60\x44\x84\x40\xa6\x14\x10\x20\x42\x82\x00\x08\x40\x00\x00\x08\x00\x08\x01\x22\x04\x4b\x48\x05\x02\x01\x00\x60\x06\x00') | ||
explosion4 = bytearray(b'\x10\x10\x00\x00\x00\x18\xa8\xc8\xf0\xf0\xf0\xe0\xe8\xb8\x08\x00\x00\x00\x00\x00\x00\x30\x39\x17\x17\x1f\x0f\x17\x13\x21\x78\x20\x00\x00') | ||
explosion = dolp.Animation([explosion1, explosion2, explosion3, explosion4], [150, 200, 200, 300]) | ||
|
||
dolp.begin() | ||
o = dolp.new_entity() | ||
o.set_animation(explosion) | ||
o.configure(30,30,8,8) | ||
|
||
while True: | ||
dolp.loop() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#include "pentity.h" | ||
extern "C" | ||
{ | ||
#include <dolpmodule.h> | ||
#include "py/obj.h" | ||
#include "py/runtime.h" | ||
} | ||
|
||
mp_obj_t animation_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) | ||
{ | ||
mp_arg_check_num(n_args, n_kw, 2, 3, false); | ||
dolp_animation_obj_t *p = m_new_obj(dolp_animation_obj_t); | ||
|
||
if (!mp_obj_is_type(args[0], &mp_type_list)) | ||
{ | ||
mp_raise_TypeError("first parameter should be a list of bytearray"); | ||
} | ||
if (!mp_obj_is_type(args[1], &mp_type_list)) | ||
{ | ||
mp_raise_TypeError("second parameter should be a list of int"); | ||
} | ||
if (n_args > 2 && !mp_obj_is_type(args[2], &mp_type_list)) | ||
{ | ||
mp_raise_TypeError("third parameter should be a list of bytearray"); | ||
} | ||
|
||
mp_obj_list_t *images = (mp_obj_list_t *)MP_OBJ_TO_PTR(args[0]); | ||
mp_obj_list_t *times = (mp_obj_list_t *)MP_OBJ_TO_PTR(args[1]); | ||
if (images->len != times->len) | ||
{ | ||
mp_raise_TypeError("length of bytearray list should equal the length of int list"); | ||
} | ||
mp_obj_list_t *masks = NULL; | ||
if (n_args > 2) | ||
{ | ||
masks = (mp_obj_list_t *)MP_OBJ_TO_PTR(args[2]); | ||
if (masks->len != images->len) | ||
{ | ||
mp_raise_TypeError("length of first bytearray list should equal the length of second bytearray list"); | ||
} | ||
} | ||
|
||
if (images->len < 1) | ||
{ | ||
mp_raise_TypeError("give me at least a frame!"); | ||
} | ||
|
||
for (size_t i = 0; i < images->len; i++) | ||
{ | ||
mp_buffer_info_t imgbuf; | ||
if (!mp_get_buffer(images->items[i], &imgbuf, 1)) | ||
{ | ||
mp_raise_TypeError("first parameter should be a list of bytearray"); | ||
} | ||
} | ||
|
||
for (size_t i = 0; i < times->len; i++) | ||
{ | ||
if (!mp_obj_is_int(times->items[i])) | ||
{ | ||
mp_raise_TypeError("second parameter should be a list of int"); | ||
} | ||
} | ||
|
||
if (masks) | ||
{ | ||
for (size_t i = 0; i < masks->len; i++) | ||
{ | ||
mp_buffer_info_t imgbuf; | ||
if (!mp_get_buffer(masks->items[i], &imgbuf, 1)) | ||
{ | ||
mp_raise_TypeError("third parameter should be a list of bytearray"); | ||
} | ||
} | ||
} | ||
|
||
p->base.type = &dolp_animation_type; | ||
p->animation = Animation(images, times, masks); | ||
return MP_OBJ_FROM_PTR(p); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"image" | ||
|
||
_ "golang.org/x/image/bmp" | ||
|
||
_ "image/jpeg" | ||
_ "image/png" | ||
|
||
"os" | ||
|
||
"github.com/polldo/dolp/tools/monochrome" | ||
) | ||
|
||
func main() { | ||
var filepath string | ||
flag.StringVar(&filepath, "i", "", "path of image to convert") | ||
flag.Parse() | ||
if filepath == "" { | ||
fmt.Println("please provide a filepath") | ||
os.Exit(1) | ||
} | ||
|
||
img, err := openImage(filepath) | ||
if err != nil { | ||
fmt.Printf("cannot open file %s: %s\n", filepath, err) | ||
os.Exit(1) | ||
} | ||
|
||
b := monochrome.Convert(img) | ||
fmt.Printf("Image for c++: \n%s\n", b.ToCpp()) | ||
fmt.Println() | ||
fmt.Printf("Image for python: \n%s\n", b.ToPy()) | ||
} | ||
|
||
func openImage(filepath string) (image.Image, error) { | ||
f, err := os.Open(filepath) | ||
if err != nil { | ||
return nil, fmt.Errorf("opening file %s: %w", filepath, err) | ||
} | ||
defer f.Close() | ||
img, _, err := image.Decode(f) | ||
return img, err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/polldo/dolp/tools/monochrome | ||
|
||
go 1.17 | ||
|
||
require golang.org/x/image v0.0.0-20220321031419-a8550c1d254a |
Oops, something went wrong.