drawing

drawing objects on pygame

隐身守侯 提交于 2021-01-29 14:30:45
问题 I am restarting some code for a covid simulation as I cant use the collide function in my current one. I have been able to draw the basic background, and draw one cell. However, when i try create the cell in a different place on my screen it does not appear for some reason. My code is as seen below: import random import pygame # import numpy import time pygame.init() GREEN1 = (0, 255, 0) # Healthy cells RED = (255, 0, 0) # Infected cells GREEN2 = (0, 100, 0) # Healthy cells not susecptible

How to test whether pixel is white in byte array?

丶灬走出姿态 提交于 2021-01-29 05:11:56
问题 I'm trying to trim a Bitmap based on white pixels. I'd like to do it efficiently, so I'm avoiding using .GetPixel I'm implementing the marked-correct answer from this question. In the answer, they detect whether pixels in a byte array are transparent. I would like to detect whether the pixels are white instead, with a threshold (so if it is less white than a threshold then foundPixel=true; . I've extracted the relevant code here: static Bitmap TrimBitmap(Bitmap source) { BitmapData data =

C# - How to get the area of a System.Drawing.Region?

房东的猫 提交于 2021-01-29 03:51:12
问题 I'm computing the area of a rectagle after exclude the area of some circles. this is my current solution: var region = new Region( new Rectangle(0, 0, 10, 10) ); var circle = new System.Drawing.Drawing2D.GraphicsPath(); circle.AddEllipse(50, 50, 25, 25); // Exclude the circle from the region. region.Exclude(circle); However I need something like region.getArea() to get the area after excluding the circle. Do you know how to compute a System.Drawing.Region area? -Or- Do you know another way to

JS: Alter Color for specific image in HTML Canvas

江枫思渺然 提交于 2021-01-28 07:31:55
问题 Let say I got the sprite to the left and I want to apply a red filter over the image before drawing it in a canvas so it looks like the sprite to the right. http://puu.sh/6dQ0E.png Is there a way to do that? It could be done in two steps, but I don't know if it's possible to draw the geometric figure that has the exact same shape than the image. (Ex: Drawing a rectangle over it won't match.) Note: I want the filter to only be applied to this image, not the whole canvas. 回答1: You can combine 2

How to hide invisible elements of the 3d drawing?

女生的网名这么多〃 提交于 2021-01-24 09:52:02
问题 I'm trying to draw a 3d image that displays a ripple: function myFunc(x, y) { let zRipple = Math.pow(2, -0.005 * (Math.abs(x) + Math.abs(y))) * Math.cos(((x * x + y * y) * 2 * pi) / 180 / width) * height; return zRipple; } width and height here are constants that define a drawing area and are equal to 200 in my tests. My approach is based on what I recall from an article that I read 30 years ago and trying to recall now. The idea is to: split the whole drawing board into the 10-pixel grid for

How to hide invisible elements of the 3d drawing?

浪子不回头ぞ 提交于 2021-01-24 09:51:13
问题 I'm trying to draw a 3d image that displays a ripple: function myFunc(x, y) { let zRipple = Math.pow(2, -0.005 * (Math.abs(x) + Math.abs(y))) * Math.cos(((x * x + y * y) * 2 * pi) / 180 / width) * height; return zRipple; } width and height here are constants that define a drawing area and are equal to 200 in my tests. My approach is based on what I recall from an article that I read 30 years ago and trying to recall now. The idea is to: split the whole drawing board into the 10-pixel grid for

Canvas rotate and drawbitmap

爷,独闯天下 提交于 2021-01-07 01:36:08
问题 I have path rect and bitmap, want to add bitmap inside path, While draw on start it appears as expected, but while rotate and draw bitmap goes outside bounds. Here is my code. canvas!!.rotate(rotateAngle.toFloat(), rectF2.centerX(), rectF2.centerY()) canvas!!.drawPath(path, mPaint) bitmap?.let { canvas!!.drawBitmap(it, rectF2.left, rectF2.top, mPaint) } canvas!!.restore() RotateAngle is 0 RotateAngle is 50 回答1: Here is the working solution with matrix. bitmap?.let { val rotate = Matrix()

Canvas rotate and drawbitmap

隐身守侯 提交于 2021-01-07 01:34:57
问题 I have path rect and bitmap, want to add bitmap inside path, While draw on start it appears as expected, but while rotate and draw bitmap goes outside bounds. Here is my code. canvas!!.rotate(rotateAngle.toFloat(), rectF2.centerX(), rectF2.centerY()) canvas!!.drawPath(path, mPaint) bitmap?.let { canvas!!.drawBitmap(it, rectF2.left, rectF2.top, mPaint) } canvas!!.restore() RotateAngle is 0 RotateAngle is 50 回答1: Here is the working solution with matrix. bitmap?.let { val rotate = Matrix()

Canvas rotate and drawbitmap

两盒软妹~` 提交于 2021-01-07 01:34:25
问题 I have path rect and bitmap, want to add bitmap inside path, While draw on start it appears as expected, but while rotate and draw bitmap goes outside bounds. Here is my code. canvas!!.rotate(rotateAngle.toFloat(), rectF2.centerX(), rectF2.centerY()) canvas!!.drawPath(path, mPaint) bitmap?.let { canvas!!.drawBitmap(it, rectF2.left, rectF2.top, mPaint) } canvas!!.restore() RotateAngle is 0 RotateAngle is 50 回答1: Here is the working solution with matrix. bitmap?.let { val rotate = Matrix()

How can I randomly make holes in snake? [duplicate]

一个人想着一个人 提交于 2021-01-05 07:39:14
问题 This question already has answers here : how to handle time for different components in pygame (1 answer) How to run multiple while loops at a time in Python [duplicate] (1 answer) Pygame clock and event loops (1 answer) Closed 17 days ago . I have snake that is turning and drawing trajectory behind him but I don't know how to make holes like random pauses while he's drawing. I tried it and it's not random but problem is that it's very fast pause. It's like teleporting move. Here is my code: