【VISUAL VB NET】ProgressBar Marque Posted: 27 Apr 2021 09:38 AM PDT Imports System Imports System.Collections.GenericImports System.ComponentModelImports System.DataImports System.DrawingImports System.LinqImports System.TextImports System.Threading.TasksImports System.Windows.Forms' make sure that using System.Diagnostics; is included Imports System.Diagnostics' make sure that using System.Security.Principal; is included Imports System.Security.Principal Public Class Form1 Public Sub New() MyBase.New() InitializeComponent() End Sub Private StartPos As Integer = 0 Private TextToShow As String = "Catch me if you can :)" Private Position As Integer = 20 Private Sub timer1_Tick(sender As Object, e As EventArgs) Handles timer1.Tick Me.Refresh() Dim gra As Graphics = Me.CreateGraphics() gra.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality gra.DrawString(TextToShow, New Font("Arial", Position), New SolidBrush(Color.Black), StartPos, 35) StartPos += 10 If StartPos >= Me.Width Then StartPos = TextToShow.Length * Position * -1 End If End Sub Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load End SubEnd Class |
【GAMEMAKER】Random Level Generator Posted: 27 Apr 2021 09:30 AM PDT Information about object: obj_player Sprite: spr_idle_down Solid: false Visible: true Depth: 0 Persistent: false Parent: Children: Mask:
No Physics Object Create Event: execute code:
///set up enum player_state { idle, up, down, left, right }
dir=player_state.down; is_moving=false; image_speed=0.5;
Step Event: execute code:
///keypress code if (keyboard_check(vk_left)) { dir=player_state.left; is_moving=true; } else if (keyboard_check(vk_right)) { dir=player_state.right; is_moving=true; } else if (keyboard_check(vk_up)) { dir=player_state.up; is_moving=true; } else if (keyboard_check(vk_down)) { dir=player_state.down; is_moving=true; } else { is_moving=false; }
execute code:
///movement if is_moving { switch (dir) { case player_state.up: if !position_meeting(x,y-4,obj_solid_base) y -= 4; break;
case player_state.down: if !position_meeting(x,y+4,obj_solid_base) y += 4; break;
case player_state.left: if !position_meeting(x-4,y,obj_solid_base) x -= 4; break; case player_state.right: if !position_meeting(x+4,y,obj_solid_base) x += 4; break; } } depth=-y;
execute code:
///animation if is_moving { switch (dir) { case player_state.up: sprite_index=spr_walk_up; break;
case player_state.down: sprite_index=spr_walk_down; break;
case player_state.left: sprite_index=spr_walk_left; break; case player_state.right: sprite_index=spr_walk_right; break; } } else { switch (dir) { case player_state.up: sprite_index=spr_idle_up; break;
case player_state.down: sprite_index=spr_idle_down; break;
case player_state.left: sprite_index=spr_idle_left; break; case player_state.right: sprite_index=spr_idle_right; break; } }
Information about object: obj_cactus
Sprite: spr_cactus Solid: false Visible: true Depth: 0 Persistent: false Parent: obj_elements_parent Children: Mask:
No Physics Object Information about object: obj_flag Sprite: spr_flag Solid: false Visible: true Depth: 0 Persistent: false Parent: obj_elements_parent Children: Mask:
No Physics Object Information about object: obj_mushroomSprite: spr_mushroom Solid: false Visible: true Depth: 0 Persistent: false Parent: obj_elements_parent Children: Mask:
No Physics Object Information about object: obj_elements_parentSprite: Solid: false Visible: true Depth: 0 Persistent: false Parent:
Children obj_cactus obj_flag obj_mushroom
Mask:
No Physics Object Create Event: execute code:
instance_create(x,y,obj_solid_base); depth=-y;
Information about object: obj_solid_base
Sprite: spr_solid_base Solid: false Visible: false Depth: 0 Persistent: false Parent:
Children obj_wall
Mask:
No Physics Object Information about object: obj_wallSprite: spr_wall Solid: false Visible: true Depth: 0 Persistent: false Parent: obj_solid_base Children: Mask:
No Physics Object Information about object: obj_waterSprite: spr_water Solid: false Visible: true Depth: 0 Persistent: false Parent: Children: Mask:
No Physics Object
Information about object: obj_generateSprite: spr_generate Solid: false Visible: true Depth: 0 Persistent: false Parent: Children: Mask:
No Physics Object Create Event: execute code:
randomize(); path=path_add(); alarm[0]=room_speed;
Alarm Event for alarm 0: execute code:
//place wall borders size=room_width/32-1; for (var loop = 1; loop < size; loop += 1) { instance_create(loop*32,32,obj_wall); instance_create(loop*32,0,obj_wall); instance_create(loop*32,968,obj_wall); instance_create(loop*32,1000,obj_wall); instance_create(32,32*loop+16,obj_wall); instance_create(0,32*loop+16,obj_wall); instance_create(968,32*loop+16,obj_wall); instance_create(1000,32*loop+16,obj_wall); } instance_create(16,16,obj_wall); instance_create(16,984,obj_wall); instance_create(984,16,obj_wall); instance_create(984,1000,obj_wall); alarm[1]=room_speed;
Alarm Event for alarm 1: execute code:
repeat(5)//do this 5 times { //get two random points atleast 100 from room edge var xx1=irandom_range(100,room_width-100); var yy1=irandom_range(100,room_height-100); var xx2=irandom_range(100,room_width-100); var yy2=irandom_range(100,room_height-100); //add points to a path path_add_point(path,xx1,yy1,3); path_add_point(path,xx2,yy2,3); //get length of path var size=floor(path_get_length(path)); show_debug_message(size); //divide by 64 var division=floor(size/64); show_debug_message(division); //get total blocks to draw total=floor(size/division); show_debug_message(total); for (var i = 1; i < total; i += 1) { var point=(1/total)*i;//get a value based on i var placex=path_get_x(path,point);//get x at point on path var placey=path_get_y(path,point);//get y at point on path instance_create(placex,placey,obj_road);//create a road object } path_clear_points(path); }
alarm[2]=room_speed;
Alarm Event for alarm 2: execute code:
//draw some lakes repeat(12) { do { xx = random(room_width) div 32*32; yy = random(room_height) div 32 *32; } until (!position_meeting(xx, yy, all)) instance_create(xx,yy,obj_water); instance_create(xx+32,yy,obj_water); instance_create(xx+32,yy+32,obj_water); instance_create(xx+64,yy,obj_water); instance_create(xx+64,yy+32,obj_water); instance_create(xx+64,yy+64,obj_water); } //draw some square lakes repeat(12) { do { xx = random(room_width) div 32*32; yy = random(room_height) div 32 *32; } until (!position_meeting(xx, yy, all)) instance_create(xx,yy,obj_water); instance_create(xx+32,yy,obj_water); instance_create(xx,yy+32,obj_water); instance_create(xx+32,yy+32,obj_water); } alarm[3]=room_speed;
Alarm Event for alarm 3: execute code:
//add some cactus / mushroom repeat(20) { do { xx = random(room_width-64) div 32 * 32 +32; yy = random(room_height-64) div 32* 32 + 32; } until (!position_meeting(xx, yy, all)) instance_create(xx,yy,choose(obj_mushroom,obj_cactus)); }
path_delete(path); instance_destroy();
Information about object: obj_road
Sprite: spr_road Solid: false Visible: true Depth: 0 Persistent: false Parent: Children: Mask:
No Physics Object |
【PYTHON OPENCV】blobFromImage and imagesFromBlob Posted: 27 Apr 2021 09:22 AM PDT """ Understanding cv2.dnn.blobFromImage() and also cv2.dnn.imagesFromBlob() in OpenCV """ # Import required packages:import cv2import numpy as npfrom matplotlib import pyplot as plt def show_img_with_matplotlib(color_img, title, pos): """Shows an image using matplotlib capabilities""" img_RGB = color_img[:, :, ::-1] ax = plt.subplot(1, 4, pos) plt.imshow(img_RGB) plt.title(title) plt.axis('off') def get_image_from_blob(blob_img, scalefactor, dim, mean, swap_rb, mean_added): """Returns image from blob assuming that the blob is from only one image""" images_from_blob = cv2.dnn.imagesFromBlob(blob_img) image_from_blob = np.reshape(images_from_blob[0], dim) / scalefactor image_from_blob_mean = np.uint8(image_from_blob) image_from_blob = image_from_blob_mean + np.uint8(mean) if mean_added is True: if swap_rb: image_from_blob = image_from_blob[:, :, ::-1] return image_from_blob else: if swap_rb: image_from_blob_mean = image_from_blob_mean[:, :, ::-1] return image_from_blob_mean # Load image:image = cv2.imread("face_test.png") # Call cv2.dnn.blobFromImage():blob_image = cv2.dnn.blobFromImage(image, 1.0, (300, 300), [104., 117., 123.], False, False) # The shape of the blob_image will be (1, 3, 300, 300):print(blob_image.shape) # Get different images from the blob:img_from_blob = get_image_from_blob(blob_image, 1.0, (300, 300, 3), [104., 117., 123.], False, True)img_from_blob_swap = get_image_from_blob(blob_image, 1.0, (300, 300, 3), [104., 117., 123.], True, True)img_from_blob_mean = get_image_from_blob(blob_image, 1.0, (300, 300, 3), [104., 117., 123.], False, False)img_from_blob_mean_swap = get_image_from_blob(blob_image, 1.0, (300, 300, 3), [104., 117., 123.], True, False) # Create the dimensions of the figure and set title:fig = plt.figure(figsize=(16, 4))plt.suptitle("cv2.dnn.blobFromImage() visualization", fontsize=14, fontweight='bold')fig.patch.set_facecolor('silver') # Show the created images:show_img_with_matplotlib(img_from_blob, "img from blob " + str(img_from_blob.shape), 1)show_img_with_matplotlib(img_from_blob_swap, "img from blob swap " + str(img_from_blob.shape), 2)show_img_with_matplotlib(img_from_blob_mean, "img from blob mean " + str(img_from_blob.shape), 3)show_img_with_matplotlib(img_from_blob_mean_swap, "img from blob mean swap " + str(img_from_blob.shape), 4) # Show the Figure:plt.show() |
No comments:
Post a Comment