Jump to content

Recommended Posts

Posted (edited)
import wx
import random
from pyrx import Ap, Db, Ed, Gs

class TestDialog(wx.Dialog):
    def __init__(self, parent, size, pos):
        wx.Dialog.__init__(self)
        self.Create(parent, wx.ID_ANY, "", pos, size, style=wx.BORDER_NONE)
        self.width = size.GetWidth()
        self.height = size.GetHeight()
        self.static_bitmap = None
        self.image = None
        self.raw_data = None
        self.offsets = [0] * self.width 
        self.bg_r = 0
        self.bg_g = 0
        self.bg_b = 0
        self.timer = wx.Timer(self)
        self.Bind(wx.EVT_TIMER, self.on_melt_tick, self.timer)

    def setImage(self, img: wx.Image):
        self.image = img
        self.raw_data = bytearray(self.image.GetData())
        
        if len(self.raw_data) >= 3:
            self.bg_r = self.raw_data[0]
            self.bg_g = self.raw_data[1]
            self.bg_b = self.raw_data[2]

        bmp = wx.Bitmap(self.image)
        if not self.static_bitmap:
            self.static_bitmap = wx.StaticBitmap(self, wx.ID_ANY, bmp, pos=(0, 0))
        else:
            self.static_bitmap.SetBitmap(bmp)
        self.static_bitmap.Bind(wx.EVT_LEFT_DOWN, self.on_click)
        self.timer.Start(33)

    def on_melt_tick(self, event):
        stride = self.width * 3
        melted_anything = False
        
        for x in range(self.width):
            if self.offsets[x] < self.height:
                increment = random.randint(2, 8) 
                self.offsets[x] = min(self.height, self.offsets[x] + increment)
                melted_anything = True
            
            offset = self.offsets[x]
            if offset == 0:
                continue
                
            x_offset = x * 3
            
            for y in range(self.height - 1, offset - 1, -1):
                target_idx = (y * stride) + x_offset
                source_idx = ((y - offset) * stride) + x_offset
                self.raw_data[target_idx] = self.raw_data[source_idx]
                self.raw_data[target_idx + 1] = self.raw_data[source_idx + 1]
                self.raw_data[target_idx + 2] = self.raw_data[source_idx + 2]
                
            for y in range(offset):
                bg_idx = (y * stride) + x_offset
                self.raw_data[bg_idx] = self.bg_r
                self.raw_data[bg_idx + 1] = self.bg_g
                self.raw_data[bg_idx + 2] = self.bg_b

        if not melted_anything:
            self.timer.Stop()
            return

        self.image.SetData(bytes(self.raw_data))
        self.static_bitmap.SetBitmap(wx.Bitmap(self.image))

    def on_click(self, event):
        self.timer.Stop()
        self.EndModal(wx.ID_OK)

@Ap.Command()
def doit():
    doc = Ap.curDoc()
    db = doc.database()
    wxDoc: wx.Window = doc.getWxWindow()
    sz = wxDoc.GetSize()
    pos = wxDoc.GetScreenPosition()
    img: wx.Image = Gs.Core.getBlockImage(db.modelSpaceId(), sz.GetWidth(), sz.GetHeight(), 1.0)
    dlg = TestDialog(wxDoc, size=sz, pos=pos)
    dlg.setImage(img)
    dlg.ShowModal()
    dlg.Destroy()

 

 

dwg.png.93d41887d5da151a25bbab83335a7f24.png

 

dwg2.png.60a8854555e2b5c0d24e90fc2721cd96.png

Edited by Danielm103

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...